#GTMTips: Use customTask to access Tracker values ​​in Google Tag Manager – News Couple

#GTMTips: Use customTask to access Tracker values ​​in Google Tag Manager

One of the things I’ve recommended from the start is to always send the Client ID to Google Analytics with users’ results. This is very useful for adding a level of detail to your trace. Initially, I recommended using an event tag to do this. Then I tweaked my style a bit so you could submit with your initial pageview (and thus not inflate your hits).

However, Universal Analytics recently released a new important API, customTask, which gives you access to the middle of the model object’s tag, allowing you to modify the payload that is sent to Google Analytics. In this article, I’ll show you how to do that using the classic example of submitting a customer ID to Google Analytics.


Simmer . newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava right in your inbox!

Tip 59: Hit the middle of the sample object tag in Google Tag Manager

Setup is really simple. You need custom dimension Setup in Universal Analytics, after which you simply need to add a file field to set in your page view tag (or whatever you want to use to send data to GA). Remember to read my article about sending this type of metadata to Google Analytics, if you’re not sure why you’d want to do this in the first place.

The tag setting will look like this:

The field name must be set to customTask, and as its value you need to use a file custom javascript variable. The variable looks like this:

  // Modify customDimensionIndex to match the index number you want to send the data to
  var customDimensionIndex = 5;
  return function(model) 
    model.set('dimension' + customDimensionIndex, model.get('clientId'));

What happens is that once the Google Tag Manager starts executing the tag code, it first encounters customTask field. Resolves the variable to a ending, which is basically a function that automatically receives a model object as a parameter. The form object can be manipulated using get And set Techniques.

next we Puts The dimension assigned at index 5 (as determined by the value of customDimensionIndex) to the customer ID, which we retrieve using Get object model method.

This little trick means we can tell the GA tag to fetch the client ID from the tracker object and send it in a custom dimension without any additional hacks or workarounds we had to use previously. fact that customTask It has no other function in Universal Analytics which means we don’t have to take into account the fact that we are replacing an important method with this tag.

You can use this for any fields in the form/tracker object if you wish.

Source link

Related Articles

Back to top button