Core Methods Reference

This document provides a reference for the core Embed API methods as well as an overview of how those methods interact with Embed API components and the underlying Analytics client library.

Core Methods

The Embed API's core methods are the methods found on the gapi.analytics object.

ready

Queues a callback function to be invoked as soon as the Embed API library is fully loaded. Callbacks are invoked in the order they were added.

The ready function is defined by the Embed API snippet, so it can be used immediately. All other functions should be placed inside the ready callback to ensure the library is loaded before they're invoked.

Usage

gapi.analytics.ready(callback)

Parameters

Name Type Description
callback Function The function to be invoked as soon as the Embed API library is fully loaded.

Example

gapi.analytics.ready(function() {
  // Code in here will be invoked once the library fully loads.
});

createComponent

Creates a component with the specified name and prototype methods. The created component will be stored on gapi.analytics.ext with the passed name.

The createCallback function should always be invoked inside a ready callback to ensure the Embed API client library is loaded.

Usage

gapi.analytics.createComponent(name, prototypeMethods)

Parameters

Name Type Description
name string The name of component.
prototypeMethods Object An object whose properties and methods will be stored on the component's prototype.

Example

gapi.analytics.ready(function() {

  gapi.analytics.createComponent('MyComponent', {
    foo: function() {
      alert('foo');
    },
    bar: function() {
      alert('bar');
    }
  });

  var myComponentInstance = new gapi.analytics.ext.MyComponent();
  myComponentInstance.foo(); // Alerts 'foo'.

});