问题
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.
回答1:
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!
来源:https://stackoverflow.com/questions/45502706/gtm-pushing-events-data-to-gtm-datalayer-not-sending-anything-to-https-www-g