I have added this gtm code in my chrome extension page(injected by the content script in and iframe)
// <!-- Google Tag Manager -->
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','owDataLayer','GTM-XXXXXXX');
// <!-- End Google Tag Manager -->
I confimred the gtm.js file loaded successfully.
Request URL:https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX&l=dataLayer
Request Method:GET
Status Code:200 (from disk cache)
I have a button and below code has been attached to the click event of the button
dataLayer.push({
'event': 'tab click',
'user id' : 123,
'description' : "Social"
});
When I click the button dataLayer.push worked with success but nothing is being sent to https://www.google-analytics.com/r/collect?
no activities in the "Network" tab of developer toolbar window.
Can anybody help me resolving this? Thanks in advance!
EDIT: Adding screenshot of the tag setup.
If your website has a Content Security Policy, it might block GTM's preview mode. You can identify this by going to your browser's developer console (On Windows, Chrome, you should go to Browser's Menu > More Tools > Developer Tools > Console. Then refresh the page.
After the dataLayer has been declared, use dataLayer. push({'item': 'value'}) to add additional values to it, and if those values need to be available to Tag Manager when the page loads, then that dataLayer. push() call needs to be above the Tag Manager container code as well.
Incorrect trigger. The first thing you should check in order to find out why your tag did not fire in GTM is firing triggers. If you are in a situation where tag did not fire, do the following. Choose an event in the Preview and Debug console's event stream (left side) and click the tag that behaved unexpectedly.
I have spent a lot of time this weekend on reading gtm and Google chrome extension. Finally I got this blog post by Simo Ahava. He discussing the exact same problem with solution. Thanks to Simo.
Here is partial paste of his blog post. We must add checkProtocolTask : false
to each gtm tag in order to send track them from
Google Chrome Extension.
Add checkProtocolTask : false
to Fields to Set
Scroll down to Fields to Set, and add a new field:
Field Name: checkProtocolTask
Value: false
Normally, Google Analytics requires that the request to GA originate from either HTTP or HTTPS. If the requests originate from anywhere else, the process is cancelled. By setting the task named checkProtocolTask to false, we can prevent this check from happening, since the extension uses the custom chrome-extension:// protocol.
Screenshot:
Posting this so others an find this answers helpful if they face same issues. Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With