Setting up a server tag for Yandex Metrica

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:

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.

Note. At the configuration stage, specify the subdomain of your site as the domain of the server-side container. This ensures that your tag gets complete data. For example, analytics.yourdomain.com.

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

  1. Download the template (template.tpl) for the Yandex Metrica server tag.

  2. Import the downloaded file into the project tag templates:

    1. In the Google Tag Manager project, select the Templates section.
    2. Under Tag templates, click New.
    3. In the upper-left corner, click  → Import and select the template.tpl file.

  3. 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.

  1. Go to the Tags section.
  2. Click Create and select the Yandex Metrica tag configuration.
  3. In the Counter ID field, enter the ID of the Yandex Metrica tag that you want to send events to.
  4. Click on Triggers, then select the All Pages trigger (Page View).
  5. Save the tag you've created.

Step 5. Configure triggers to collect Ecom and JavaScript events

  1. Click on Triggers and create a new trigger.
  2. Select Special as the trigger type and All events as the trigger activation criteria.
  3. Save the trigger.
  4. Go to the Tags section.
  5. Select the Yandex Metrica tag and add the previously created trigger for special events to it.
  6. Save the tag.
  7. 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

  1. In the upper-right corner, click Send.
  2. Specify the name and description of the version.
  3. 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>

Select a question to find a solution.

Goals in Yandex Metrica work the same way for any source. Perhaps there aren't any users who have completed the goal from this source yet.


This might happen for the following reasons:
  • The goal condition in Yandex Metrica doesn't cover all the possibilities. For example, the goal is set as going to the order confirmation page, but the site also allows instant checkout without visiting this page.
  • The site user has a browser plugin that blocks the Yandex Metrica tag, so this user isn't counted.
  • The user has an antivirus system with strict privacy settings.
  • The user has a slow internet connection, so the Yandex Metrica tag didn't load on the target page.