我正在使用Google Tag Manager容器来管理脚本。 我正在尝试执行服务器端优化/分析实验。出于性能原因,我需要进行服务器端实验。 我已经成功地使用GTM / Optimize容器执行了客户端实验。
这是我的GTM代码:
window.dataLayer = window.dataLayer || [];
....
<!-- 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-XXXXXXXX');</script>
<!-- End Google Tag Manager -->
我尝试了以下不同的方法来触发哪个变体。
// These fn get called only once GA exists via setTimeout. They get called correctly.
// I've setup the experimentTrigger via GTM container and it triggers correctly to Analytics.
function setGAExperiment1(_expIdvId){
// Matches ga('set', 'exp', '$experimentId.$variationId');
// https://developers.google.com/optimize/devguides/experiments
ga('set', 'exp', _expIdvId);
dataLayer.push({'event': 'experimentTrigger', 'exp': _expIdvId }); // to trigger data send of exp
// I receive the experimentTrigger event with 'exp' value on Analytics but not any experiment data into Optimize/Analytics.
}
function setGAExperiment2(_expIdvId){
// Matches ga('set', 'exp', '$experimentId.$variationId');
// https://developers.google.com/optimize/devguides/experiments
ga('set', 'exp', _expIdvId);
ga('send', 'event', 'experiment', 'view'); // to trigger data send of exp
}
我在Google Optimize或Google Analytics的“行为”->“实验”中没有收到任何实验数据,就像我应该收到的那样。我该如何修复这个问题?