Leverage on customTask API to achieve to your desired tracking goals

Leverage customTask to achieve to your desired tracking goals

Are you facing hurdles in accessing hit payloads that are sent to Google Analytics ? Are you having any curiosity to understand the mechanism of Google Analytics hit payload creation/modification?

Regardless to whether you have Google Analytics Standard or get Google Analytics 360, we are going to discuss about the customTask API and how we can use it efficiently. Google has provided varieties of tasks which are executed based on queue algorithm. Before hit is being sent to Google Analytics, customTask is the first among all the other tasks and functions.

Previously, we were not able to modify any hit payload parameters before the hit is sent to Google analytics. Anything that passes on as an extra value with the very first hit was not possible earlier. For example ClientID with first page pageview tag. But customTask makes all these things possible for us.

In this blog, We will discuss use cases to leverage customTask API. Let us see how you can modify the hit. For example, I want to change event category value before sending it to GA.

Follow the below steps to do so.

Step 1: Create variable of type Custom JavaScript named tvc_customtask_js in Google Tag Manager and write the following code.

This is the code which changes event category value before hitpayload is sent to Google Analytics

 

Step 2 : Now you need to use that variable in your Universal Analytics tag. Select Track Type as Event. Inside Fields to Set section select customTask from dropdown and assign the tvc_customtask_js variable inside Value.

Login Event Track

 

Step 3: Create a trigger type of Custom Event.custom type API click track

 

Above is the standard use case that you can follow for changing other parameters as well. Once it is done, test it and make it live.

defining event category

We have other advanced use cases as well which will give you better understanding of customTask API.

USECASE 1: Update the session level cookie to align your session cookies with Google Analytics session

To align session level browser cookie with GA session,, modify the cookie that maintains your session timing and align it with your Google Analytics session timings.It can be best solution for one page site.

customtask API usecase

USECASE 2: Send users’ variant information with first pageview hit to Google Analytics

Now a days to improve user experience and user engagement websites are performing A/B test. Now suppose you have 2 different experiences as A/B test variants, variant 1 can be original and variant 2 can be experimented version of original. Here, variant value would be stored into cookie. Get the variant’s value which user falls into variant 2 or original. And pass it to any hit using customTask API.

USECASE 3: Collecting the Client ID in a custom dimension

Capturing the clientID is very helpful to measure users’ behaviour in GA with very first hit. After fetching it successfully pass it to custom dimension.

USECASE 4: Leverage subsequent tasks

As customTask is the first task that is executed from all the other subsequent tasks, we may change/modify any parameters to other subsequent tasks. Those changes can be added to any custom javascript variable or write function in custom HTML tag in Google Tag Manager.

USECASE 5: Modify hit payload parameters before sending it to Google Analytics:

Send hit to multiple properties at same time. Is it possible? Of Course by creating multiple tags or by using lookup table variable. But what if all my hits are sent without creating any extra tag, It is possible using customTask.

USECASE 6: Aborting a hit

To abort the specific hit before it sent to GA. Such as we can set exception in trigger for that particular, tag will not be fired so we can set it in customTask.

To gather more information about above four use cases please refer Google’s standard doc.

Disclaimer: Google has introduced new feature gtag.js which is currently not supporting any tasks API. In future it might be support.

The following two tabs change content below.
Rajvi Shah

Rajvi Shah

Rajvi is a Technical Analyst at Tatvic and provides technical support regarding analytical data that concerns the clients. She’s passionate about learning and developing new stuff in new technologies.
, ,
Previous Post
Migrate your website to new host for enhanced Google Analytics Tracking
Next Post
Implement dataLayer and Google Tag Manager: Best Practices and Advantages

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu