What is customTask in the Google Analytics and Google Tag Manager?

As most of the frequent users of the Google Analytics know that all the hits pass to the Google Analytics server using measurement protocol or MP. The Google Analytics have a sequence to check a hit before sending to the Google Analytics. The below table shows the sequence in which google analytics check the hit.

Task Description
customTask No functionality of its own, but can be used to manipulate the model object before it is processed by the other tasks.
previewTask If the request is generated from the pageview of a “Top Sites” thumbnail in Safari, abort the hit.
checkProtocolTask Aborts the request if the page protocol is not valid (http or https).
validationTask Checks if the fields in the request have valid and expected values. Aborts the request if this is not the case (e.g. trying to send a string as the Event Value).
historyImportTask If there is still legacy tracking running on the site, this task imports information from the old GA library cookies into Universal Analytics. Very useful if the site is migrating to Universal Analytics.
samplerTask If you’ve decided to manually sample the users to stay within Google Analytics’ processing limits, this task aborts the request if the user is sampled out of data collection.
buildHitTask Generates the hitPayload string, which is essentially the list of query parameters and their values passed to the Measurement Protocol request.
sendHitTask Sends the hitPayload in a Measurement Protocol request to the GA servers.
timingTask If you are automatically sampling pages for page speed measurements, this task sends the timing hit to Google Analytics.
displayFeaturesTask If you have enabled display features in GA settings, this task compiles the request to the DoubleClick servers.

As you can see customTask is a first task Google Analytics execute and customTask doesn’t have any of its own function so, we need to manually set it up if needed. A model is an object which holds all the value of hits and processed by the Google Analytic i.e. model object generated by customTask will be used by previewTask and so on.

As customTask runs before any other task, it is one of the most powerful features that Google Analytics offers.

Example of the customTask:  The below code will send tracking id as a custom dimension to the Google Analytics. We can setup customTask using Google Analytics or Google Tag Manager.

Using on-page universal analytics (analytics.js) :

var _customTask = function() {
// Set Client ID to Custom Dimension 1
return function(customTaskModel) {
customTaskModel.set(‘dimension1’, customTaskModel.get(‘clientId’));

ga(‘create’, ‘UA-12345-1’);
ga(‘set’, ‘customTask’, _customTask());
ga(‘send’, ‘pageview’);


Using the GTM: Create a custom javascript variable and use it in a field to set, as shown below in a screenshot.

function() {
return function(model) {
model.set(‘dimension199’, model.get(‘clientId’));




You can read more about customTask here

Please follow and like us:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *