问题
I have created chrome extension. I add google tag manager script and no script iframe in popup html like this:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Signals</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Google Tag Manager -->
<script>(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','dataLayer','GTM-XXXXXXX');
console.log(dataLayer);
</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<ch-signals maxLines="7" lang="en" symbols="rub,usd,eur"></ch-signals>
<script type="text/javascript" src="ch_signal-f9eaa1a4.js"></script></body>
</html>
All worked fine but GTM not working, i add console.log(dataLayer) in console i see dataLayer array. What is wrong?
回答1:
I found the answer. In the extension everything was correct, in Google Tag Manager (GTM) it was necessary to disable the protocol check. I set checkProtocolTask
to false
and path
to {{PagePath}}
in GTM fields to set, and its working now!
来源:https://stackoverflow.com/questions/55382346/how-i-can-insert-google-tag-manager-to-popup-in-chrome-extension