我按照以下说明通过Google:https://support.google.com/optimize/answer/6262084加载谷歌优化片段
它基本上可以归结为我的GA代码中的一个新行:
ga('require', 'GTM-S1O2M3E');整个GA片段看起来如下(我为可读性添加了行符):
(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', '//www.google-analytics.com/analytics.js', 'ga');
ga('require', 'GTM-S1O2M3E');
ga('create', 'UA-NNNNNNNN-N', 'auto');
ga('send', 'pageview');当我对我的优化实验进行预览时,Google优化Chrome扩展会在几秒钟后发出这个警告:
The Google Optimize snippet for the container with ID GTM-S1O2M3E is not correctly installed on this page.
To preview experiences or debug the container, make sure the Google Optimize snippet is installed on any pages
you want to test.检查开发工具中的网络选项卡,我找不到任何包含我的OPT_CONTAINER_ID的请求--看起来GA从未加载它!此外,检查全局变量google_optimize返回未定义的(我在这里发现:https://support.google.com/optimize/answer/9059383?hl=en)。
但是,当我在Developer控制台中手动执行行ga('require', 'GTM-S1O2M3E');时,我看到一个新请求和 google_optimize 变量都被实例化了!
那么,为什么GA不像它应该的那样,在开始时加载优化脚本呢?
发布于 2019-12-15 21:14:34
尝试倒转以下代码行
发自:
ga('require', 'GTM-S1O2M3E');
ga('create', 'UA-NNNNNNNN-N', 'auto');
ga('send', 'pageview');至:
ga('create', 'UA-NNNNNNNN-N', 'auto');
ga('require', 'GTM-S1O2M3E');
ga('send', 'pageview');发布于 2019-12-15 06:50:32
如果您有以下三个问题,就会发生这种情况。
GA属性。https://stackoverflow.com/questions/59197025
复制相似问题