Chrome扩展程序中的Google Analytics(分析)不起作用 [英] Google Analytics in Chrome Extension not working
问题描述
我已经在Google Analytics(分析)上创建了一个帐户,并创建了一个媒体资源和网络数据流.在我的Chrome扩展程序的popup.js中,我具有以下代码:
//标准Google Universal Analytics代码(function(i,s,o,g,r,a,m){i ['GoogleAnalyticsObject'] = r; i [r] = i [r] || function(){(i [r] .q = i [r] .q || []).push(arguments)},i [r] .l = 1 * new Date(); a = s.createElement(o),m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a,m)})(窗口,文档,'脚本','https://www.google-analytics.com/analytics.js'、'ga');ga('create','G-XXXXXXXXXX','auto');ga('set','checkProtocolTask',null);ga('send','pageview','/popup.html');函数trackButtonClick(e){ga('send','event','Button','Click',e.target.id);};var button = document.querySelectorAll('button');for(var i = 0; i< buttons.length; i ++){button [i] .addEventListener('click',trackButtonClick);}
我可以在开发工具中观察者请求
I have created an account on Google analytics, created a property, and a data stream for web. In my popup.js for the Chrome extension I have the following code:
// Standard Google Universal Analytics code
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'G-XXXXXXXXXX', 'auto');
ga('set', 'checkProtocolTask', null);
ga('send', 'pageview', '/popup.html');
function trackButtonClick(e) {
ga('send', 'event', 'Button', 'Click', e.target.id);
};
var buttons = document.querySelectorAll('button');
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', trackButtonClick);
}
I can observer in dev tools the request to https://www.google-analytics.com/collect. But in the google analytics console, I'm not showing any data. It's been several days since I have first used the tracking code. What am I doing wrong? Is it something with the new Google Analytics 4?
You are using a Google Analytics 4 Property ID (G-XXXXXXXX) with analytics.js
library (ga) for Universal Analytics. To use your snippet I suggest you create a Universal Analytics Property (as shown in following image) and use the relative identifier UA-XXXXXXX-X:
这篇关于Chrome扩展程序中的Google Analytics(分析)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!