Use Google Tag Manager for Yandex.Metrica: hitCallback for reachGoal method

Here’s a quick tip on how to use Google Tag Manager for Yandex Metrica (Яндекс.Метрика). In this post I’ll show you how to easily register goals (reachGoal method) and/or make use of dataLayer array in order to send e-commerce data to Metrica.

This tip corresponds with my previous post containing a solution for sending events to Facebook with GTM avoiding HTML tags usage. Check it out!

What is Yandex.Metrica

I’m sure all my Russian readers are familiar with this great analytics tool powered by Yandex. Robust API, absolutely no data sampling, ad hoc reporting – all this just starts the list of benefits you get while using Yandex.Metrica.

For those interested in fresh unique web-analytics insights for your site/app, here’s a list of all features this tool boasts.

use google tag manager for yandex metrica: interface

Install Yandex.Metrica using Google Tag Manager

You can easily install Metrica on your site using custom HTML tag. Simply create a new HTML tag and paste the JS code snippet you’ve received after completing the registration process. You can always find the code under Settings -> Counter Code

use google tag manager for yandex metrica: counter-code-min1

Attach the very same trigger you’re using for your GA main pageview tag to it, so Yandex.Metrica fires alongside with Google Analytics.

Use hitCallback field for reachGoal method

Oftentimes people use a separate custom HTML tag for sending data to 3rd party counters (like Facebook or Yandex.Metrica). I’m not saying this is wrong. Obviously, that’s a totally valid way to do it, but I believe there’s a smarter way.

If you have a GA tag firing on certain event on your site, you can use the hitCallback field to send data to 3rd party counters.

Here’s how it works. Suppose, you have a GA tag that fires once a user clicks on a check-out button. This is how you add event tracking for Yandex.Metrica

use google tag manager for yandex metrica: hitCallback-min

See? All you need is a custom JS function returning a certain code for sending data to Metrica. Here’s the content of the variable.

Don’t forget to paste your values for Metrica ID and goalId. You can also use goalParams and goalCallback arguments, but there are optional.

Though this solution is 100% applicable, there’s a nasty painful necessity about it. You’ll need to create a new variable for each event. And that is certainly not the way we’re used to approach web-analytics tasks, right?

Use a standard GTM Event variable for Metrica goal ID

So, here’s what you can do:

The trick is that here we’re using a standard GTM variable Event as Metrica goal identifier. So, if your GA tag fires on a custom dataLayer event, the name of this very event is going to be used for Metrica goal identifier. Thus, all you need to do is to make sure your Metrica goal identifiers exactly match event names you’re using in the triggers. In other words, use the same names for Metrica goal IDs (идентификаторы цели) as you use for custom event triggers that fire GA tags.\


I hope this post will come in handy not only for my Russian readers who use Google Tag Manager for Yandex Metrica, but all of you eager to get rid of a bunch of HTML tags containg 1-5 lines.

Let me know in the comment section below if you have any questions.

Tag Manager , ,