Setting up a server tag for Yandex Metrica
- Prerequisites
- Step 1. Create a server container
- Step 2. Configure a server-side container to transmit data
- Step 3. Create a Yande Metrica server tag template
- Step 4. Create a server tag
- Step 5. Configure triggers to collect Ecom and JavaScript events
- Step 6. Configure the clients
- Step 7. Publish the configuration you built
- Step 8. Set up data sending
If you set up a server tag for Yandex Metrica, you can use Google Tag Manager to send data to Yandex Metrica without installing the tag.js
code for the tag on your site pages.
You can use the server implementation of the event delivery protocol to collect:
- Pageviews for site pages.
- JavaScript event goals sent from sites as custom Google Analytics events.
Prerequisites
To send data to Yandex Metrica via the Google server container, you must have:
- An account in Google Tag Manager.
- An account on Google Cloud Platform or any other cloud platform. You can set up a server from scratch or use an existing server.
- A Yandex Metrica account and a tag that will collect the data. To collect E-commerce data, set up E-commerce.
Step 1. Create a server container
Go to Google Tag Manager and create a server container following the instructions.
Step 2. Configure a server-side container to transmit data
You can set up a Google Cloud Platform server for your server-side container automatically, when creating a server tag in Google Tag Manager, or manually. To configure the container on an existing server, follow the App Engine setup instructions.
You can also set up the server-side container on another cloud platform.
For more information about how to correctly specify a subdomain, see the Google Tag Manager Documentation.
Step 3. Create a Yande Metrica server tag template
Download the template (template.tpl) for the Yandex Metrica server tag.
Import the downloaded file into the project tag templates:
- In the Google Tag Manager project, select the Templates section.
- Under Tag templates, click New.
In the upper-left corner, click template.tpl file.
and select the
Save the downloaded tag template code. You can run tests against the tag code and see the permissions that the tag needs to run:
- Reading values from _ym_uid cookie files.
- Output to the console.
- Setting up the _ym_uid cookie file.
- Reading data of any events.
- Sending HTTP requests to https://mc.yandex.ru/*.
- Reading container data.
Step 4. Create a server tag
The server tag will process and send events to Yandex Metrica.
- Go to the Tags section.
- Click Create and select the Yandex Metrica tag configuration.
- In the Counter ID field, enter the ID of the Yandex Metrica tag that you want to send events to.
- Click on Triggers, then select the All Pages trigger (Page View).
- Save the tag you've created.
Step 5. Configure triggers to collect Ecom and JavaScript events
- Click on Triggers and create a new trigger.
- Select Special as the trigger type and All events as the trigger activation criteria.
- Save the trigger.
- Go to the Tags section.
- Select the Yandex Metrica tag and add the previously created trigger for special events to it.
- Save the tag.
- For the Google Analytics event to be displayed by Yandex Metrica as a goal, create a new goal in Yandex Metrica with the JavaScript event type and a goal ID exactly matching the <event_name> property of the Google Analytics event.
Step 6. Configure the clients
By default, Universal Analytics and GA4 clients are connected in the server container. For more information about the setup, see the Google Tag Manager Documentation.
If you want to upload scripts from your domain, change the default gtag.js paths for specific IDs. Select the checkbox Default gtag.js paths for specific IDs, click Add Data Stream ID, and enter UA-XXX as a tracking ID in the field.
Step 7. Publish the configuration you built
- In the upper-right corner, click Send.
- Specify the name and description of the version.
- Click Publish.
Step 8. Set up data sending
To set up data sending using the tag manager or the global gtag.js tag, follow the instructions.
Add the transport_url and first_party_collection parameters to the tag:
gtag('config', 'G-XXXXXX', {
transport_url: 'https://analytics.yourdomain.com',
first_party_collection: true
});
where:
G-XXXXXX
: Universal Analytics ID or GA4 ID.transport_url
: Your subdomain where your server tag is installed.
If you chose to download scripts from your domain, edit the script domain to the domain of your server container:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://analytics.yourdomain.com/gtag/js?id=<G-XXXXXX>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXX', {
transport_url: 'https://analytics.yourdomain.com',
first_party_collection: true
});
</script>