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
- Open your Google Tag Manager container at tagmanager.google.com
- Navigate to the "Variables" page on the navigation bar
- Click the "New" button to create a new variable
- Select "Custom JavaScript" from the variable type selection sidebar
- Enter the following code as the value of the custom JavaScript variable
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) {}
}
}
- Save the variable name as "disableCheckProtocolTask"
- Open your "Google Analytics Settings" variable
- If you do not have a Google Analytics settings variable, then create a new one. Learn More
- Add a new field under "Fields to Set"
- Set the field name to "checkProtocolTask", without quotes
- Set the field value to "{{disableCheckProtocolTask}}", without quotes
- Save the Google Analytics settings variable
- Publish your Google Tag Manager container