How i can insert google tag manager to popup in chrome extension?

半世苍凉 提交于 2021-01-29 06:11:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!