Transmitting data on additional events

  1. Data transmission limits
  2. Sending pageview data
  3. Sending data on goals and events

To send additional event data to Yandex Metrica, you can use standard JavaScript methods. We recommend using distinct methods for transmitting different types of data.

Data transmission limits

  • Maximum number of nested levels: 10.
  • Maximum size per JSON: 8 KB.
  • Maximum number of parameters per session: 512.

For more information, see Restrictions.

Sending pageview data

We recommend using these methods to send pageview data:

  • init: When initializing the tag.
  • hit: For transmitting large amounts of data and for AJAX or Flash websites.
init method
Note. Use the init method for small amounts of data and the hit method for large ones.

The init method is typically used for normal tag initialization on the website and is specified by default in the code snippet:

ym(XXXXXX, "init", {});

Sample code snippet with additional parameters:

ym(XXXXXX, "init", {
    clickmap: true,
    trackLinks: true,
    accurateTrackBounce: true,
    webvisor: true,
    ecommerce: "dataLayer",
    params: {
        user_info: {
            user_id: "123456",
            user_type: "customer"
        }
    }
});
Attention. Use caution when introducing additional parameters into the init method. If errors occur during data transmission, the pageview may not be recorded for the user, and any subsequent actions on this page may not be included in the session.

More details about the init method.

hit method

Use this method to send large amounts of data. The hit method is also suitable for AJAX or Flash websites, where the user navigates between pages within the same window, without loading any new pages.

ym(XXXXXX, 'hit', url[, options])

Here's an example of using the method with additional data:

 ym(XXXXXX, 'hit', '#contacts', {
    params: {
        page_info: {
            title: "Page title",
            referrer: "Page referrer"
        },
        user_info: {
            user_id: "123456",
            user_type: "customer"
        }
    }
}); 

More details about the hit method.

Sending data on goals and events

To send data about user events and actions on your site, we recommend these methods:

  • reachGoal: For sending goal data.
  • params: For sending data about additional events you want to analyze.
reachGoal method

Use this method for events that you plan to set as goals in Yandex Direct or for viewing data about goal completion in Yandex Metrica.

ym(XXXXXX, 'reachGoal', target[, params[, callback[, ctx]]]);

Example of using the method with additional parameters:

ym(XXXXXX,'reachGoal','TARGET_NAME', {
    page_info: {
        title: "Page title",
        referrer: "Page referrer"
    },
    user_info: {
        user_id: "123456",
        user_type: "customer"
    },
    action_info: {
        action_type: "select",
        action_placement: "action_placement"
    }
}); 

More details about the reachGoal method.

params method

Use this method for the events you wish to analyze without setting them as goals:

ym(XXXXXX, 'params', parameters);

Example of using the method with parameters:

ym(XXXXXX, 'params', {
    action_info: {
        action_type: "select",
        action_placement: "action_placement"
    }
});

More details about the params method.