Leverage on customTask API to achieve to your desired tracking goals

📢 Tatvic is now a global partner of Usercentrics, world’s leading consent management platform

Leverage on customTask API to achieve to your desired tracking goals

Last Updated:


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.

Step 3: Create a trigger type of Custom Event.

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.

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.

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.

Tejas Modi

Tejas Modi

Tejas brings in a rich expertise of more than 10 years in the domain of strategic advisory, business consulting and finance. He also leads the Analytics Solutions team here at Tatvic.

Sign up for
our monthly newsletter

This field is for validation purposes and should be left unchanged.

Other Blog

Scroll to Top

Leverage Tatvic's comprehensive approach to 

Enquire Now

This field is for validation purposes and should be left unchanged.

Leverage Tatvic's comprehensive approach to 

Contact Us

This field is for validation purposes and should be left unchanged.