Disabling Analytics checkProtocolTask in Tag Manager

The analytics.js library features a series of tasks that validate, construct, and send a Measurement Protocol request from the user's browser to Google Analytics. Of these, the "checkProtocolTask" aborts the request if the identified protocol is not http or https.

For certain app frameworks, such as Ionic, the check protocol task can prevent Google Analytics from sending hits when the analytics.js snippet is placed directly in a webview or when analytics.js is loaded through a Google Tag Manager JavaScript snippet placed in a webview. In these frameworks, Google Tag Manager will work, but Google Analytics tags will experience aborted hit requests.

To resolve this issue, a custom JavaScript variable will need to be created in Google Tag Manager that disables the "checkProtocolTask" for all Google Analytics Tasks.

Disable the Check Protocol Task in Google Tag Manager

  1. Open your Google Tag Manager container at tagmanager.google.com
  2. Navigate to the "Variables" page on the navigation bar
  3. Click the "New" button to create a new variable
  4. Select "Custom JavaScript" from the variable type selection sidebar
  5. Enter the following code as the value of the custom JavaScript variable
function () {
  return function () {
    try {
      // Retrieve all trackers
      var trackers = ga.getAll();
      trackers.forEach(function(tracker) {
        // Get the Client ID
        var cid = tracker.get('clientId');
        // Set the Check Protocol Task to null
        tracker.set('checkProtocolTask', null);
    } catch (e) {}
The above code retrieves all Google Analytics tracker objects on the page and disables the "checkProtocolTask" for all present tracker objects.
  1.  Save the variable name as "disableCheckProtocolTask"
  2. Open your "Google Analytics Settings" variable
    1. If you do not have a Google Analytics settings variable, then create a new one. Learn More
  3. Add a new field under "Fields to Set"
  4. Set the field name to "checkProtocolTask", without quotes
  5. Set the field value to "{{disableCheckProtocolTask}}", without quotes
  6. Save the Google Analytics settings variable
  7. Publish your Google Tag Manager container
Was this helpful?
How can we improve it?