Examples of sending session parameters
- XXXXXX is the tag ID.
- TARGET is the ID of the “JavaScript event” goal.
- URL is the first-level session parameter. Any name can be set.
- document.location.href is the second-level session parameter that will be used to transmit the address of the page where the user performed the target action.
<script type="text/javascript">
window.yaParams = { "Author": 123 };
ym(XXXXXX, 'params', window.yaParams||{});
</script>
<script type="text/javascript">
window.yaParams = { "Category": 123 };
ym(XXXXXX, 'params', window.yaParams||{});
</script>
For instance, we need to transmit data and show it in a report in a tree view.
<script type="text/javascript">
window.yaParams = {
"level1":{"level2":["level3_1","level3_2"]}}
...
ym(XXXXXX, 'params', window.yaParams||{});
</script>
Let’s say we need to conduct an experiment to determine how the color of the Buy button affects the conversion rate for a “View basket” goal.
If the user is shown a red button, we use the following parameter:
window.yaParams = {ab_test: "red"};
If the user is shown a green button, we use the following parameter:
window.yaParams = {ab_test: "green"};
This parameter is transmitted in any convenient way. For example, it can be passed when initializing the tag on product pages or using the reachGoal method that is called when the Buy button is clicked.
After this, we will be able to use the ab_test
parameter value in the Yandex Metrica interface for selecting the corresponding data.
Use the following code sample to analyze differences in the behavior of registered and non-registered site users:
<script type="text/javascript">
window.yaParams = {'Логин': '[% вставка логина посетителя из шаблонизатора сайта %]' || 'Гость'};
ym(XXXXXX, 'params', window.yaParams||{});
</script>
where XXXXXX is the tag ID.
For example, if you have a single form on every page of a site, you can track the pages where it's filled in most often. To do this, create a JavaScript event (form submission) goal and configure the transmission of the page address.
ym(XXXXXX, 'reachGoal', 'TARGET', {URL: document.location.href})
If you want to track different actions, such as clicking on two different phone numbers, create two goals (one for each number) and transmit each with its own document.location.href parameter.
ym(XXXXXX, 'reachGoal', 'TARGET', {URL: document.location.href})
...
ym(XXXXXX, 'reachGoal', 'TARGET2', {URL2: document.location.href})