Send Google Analytics hits to 3rd party services using Google Tag Manager

Yes, I know. It’s been a huge while since my last post. However, it wasn’t that I lost my passion for web-analytics and/or web development. Rather on the contrary, I decided to focus on deepening my Javascript and SQL skills along with mathematics content knowledge to deliver an excellent customer experience to my clients and provide you, my readers, with more valuable web-analytics insights.

So it’s awesome to be back on track!

In this post I will show you how to send Google Analytics hits to 3rd party services using Google Tag Manager (ex. Google Bigquery). The setup is really simple. All you need to start sending your data is a custom js variable and a sendHitTask field in each of your UA tags.

Custom JS variable

Create a custom JS variable with the following content.

As you can see, the function contains extensive description for each code block. I hope this sheds enough light on how the function works. However, if you want to know more on its logic, I believe additional comments provided at the end of the post would not go amiss. Plus, you should definitely check the documentation for GA tasks.

sendHitTask field

Add a “sendHitTask” field to each (!) of your UA tags (like it is shown below) and use the variable we’ve just created for its value.

send google analytics hits to 4rd party serives using google tag manager

Preview and publish

That’s it! If you’ve set up everything correctly, then each of your UA tag should send at least two hits: one to GA and another to the destination you choose.


In the example above I’m sending  hits to Google Bigquery. Now, we came up to the most riveting part of the post. Here are the benefits you get when using this solution.

Enrich your data

As you noticed, the following variable contains your GA payload.

The payload itself may look like this

To enrich my data and make it more valuable from the viewpoint of user behaviour analysis, I add the ClientId to the payload using a custom dimension. Thus, you can have any information send with your payload. For example, if you want to send the ClientId AND the UserId with your data, the line might look like this:

Don’t forget to change the index of the custom dimensions where you actually store these values.

Solve GA data sampling problem

As you may know, your GA reports can be a subject to sampling in certain circumstances. Sending all your GA hits to Google Bigquery is one the possible methods for solving this issue. Once you have your data collected in GBQ, you can easily build non-sampled reports (ex. in Data Studio) in order to gain a complete insight for the purposes of web analysis.

Implement the solution easily

Finally, this solution is very easy to implement. All you have to do is to create a variable with the above code altered to your needs and use it as a value for the sendHitTask field in each UA tag. That’s it! No additional tags, triggers, workarounds etc. For those of you having GA snippet hard-corded on their sites I’ll add a separate instruction to this post later.

Feel free to share your thoughts in the comment section below. Should any additional questions arise while implementing the solution on how to send Google Analytics hits to 3rd party services using Google Tag Manager, do not hesitate to contact me here or on Google Plus.