Javascript Google analytics代码为每个页面注册3次点击

Javascript Google analytics代码为每个页面注册3次点击,javascript,google-analytics,Javascript,Google Analytics,我已在我的网站的每个页面上添加了以下GA脚本: <script async src=<?PHP print ('"https://www.googletagmanager.com/gtag/js?id='.$gaid.'"'); ?>></script> <script> var gaid = <?PHP print('"'.$gaid.'"'); ?>; window.dataLayer = window.dataLayer || [

我已在我的网站的每个页面上添加了以下GA脚本:

<script async src=<?PHP print ('"https://www.googletagmanager.com/gtag/js?id='.$gaid.'"'); ?>></script>
<script>
var gaid = <?PHP print('"'.$gaid.'"'); ?>;
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', gaid);
gtag('config', gaid, {'custom_map': {'dimension2': 'Za'} });
gtag('event', 'set_za', {'Za': <?php print("'".za()."'"); ?>} );
gtag('config', gaid, {'custom_map': {'dimension3': 'Zd'} });
gtag('event', 'set_zd', {'Zd': <?php print("'".zd()."'"); ?>} );
</script>

每次调用
gtag('config'…)
时都会发送页面浏览点击。您必须重新排列代码,以便在单个调用中定义所有自定义映射,如:

gtag('js', new Date());
gtag('config', gaid, {'custom_map': {'dimension2': 'Za', 'dimension3': 'Zd'} });
gtag('event', 'set_za', {'Za': <?php print("'".za()."'"); ?>} );
gtag('event', 'set_zd', {'Zd': <?php print("'".zd()."'"); ?>} );
gtag('js',newdate());
gtag('config',gaid,{'custom_map':{'dimension2':'Za','dimension3':'Zd'}});
gtag('event','set_za',{'za':