找到你要的答案

Q:Google analytics incorrect event reporting

Q:谷歌分析不正确的事件报告

I am using the following code in a WordPress sidebar widget, to load random advertisement which is working perfectly. This code also sends impressions to google Analytics. Now the issue is that this code sends impressions to all advertisements. not only the advertisement loaded randomly. I have pasted the code in the below url.

http://pastebin.com/TrxDhLXa

<script>
var value1 = 'top_1st';
var value2 = 'top_2nd';
var value3 = 'top_3rd';
var chosenValue = Math.random() < 0.5 ? value1 : value2 : value3;
var chosenDiv = document.getElementById(chosenValue);
chosenDiv.style.display = "block";
</script>

<div id="inline" class="various2">
      <div style="display: none;" id="top_1st">
         <a href="http://scicom.mv" onClick="ga('send', 'event', 'TopBannerSciCom', 'click','SciComTopTuition',1.00, {'nonInteraction': 1});" ><img width="100%" style="border: 0px" src="http://ads.esfiya.com/wp-content/uploads/2015/08/tuition_top.jpg" alt="" /></a>
<img width=0 height=0 src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="ga('send', 'event', 'TopBannerSciCom', 'impression','SciComTopTuition',2.00, {'nonInteraction': 1});"/>
       </div>
    <div style="display: none;" id="top_2nd">
           <a href="http://scicom.mv" onClick="ga('send', 'event', 'TopBannerSciCom', 'click','SciComTopEng',1.00, {'nonInteraction': 1});" ><img width="100%" style="border: 0px" src="http://ads.esfiya.com/wp-content/uploads/2015/08/eng_top.jpg" alt="" /></a>
<img width=0 height=0 src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="ga('send', 'event', 'TopBannerSciCom', 'impression','SciComTopEng',2.00, {'nonInteraction': 1});"/>
       </div>

<div style="display: none;" id="top_3rd">
           <a href="http://scicom.mv" onClick="ga('send', 'event', 'TopBannerAdHere', 'click','TopAdHere',1.00, {'nonInteraction': 1});" ><img width="100%" style="border: 0px" src="http://ads.esfiya.com/wp-content/uploads/2015/04/ad-here-red700x140.jpg" alt="" /></a>
<img width=0 height=0 src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="ga('send', 'event', 'TopBannerAdHere', 'impression','TopAdHere',2.00, {'nonInteraction': 1});"/>
       </div>
</div>

I am using the following code in a WordPress sidebar widget, to load random advertisement which is working perfectly. This code also sends impressions to google Analytics. Now the issue is that this code sends impressions to all advertisements. not only the advertisement loaded randomly. I have pasted the code in the below url.

http://pastebin.com/trxdhlxa

<script>
var value1 = 'top_1st';
var value2 = 'top_2nd';
var value3 = 'top_3rd';
var chosenValue = Math.random() < 0.5 ? value1 : value2 : value3;
var chosenDiv = document.getElementById(chosenValue);
chosenDiv.style.display = "block";
</script>

<div id="inline" class="various2">
      <div style="display: none;" id="top_1st">
         <a href="http://scicom.mv" onClick="ga('send', 'event', 'TopBannerSciCom', 'click','SciComTopTuition',1.00, {'nonInteraction': 1});" ><img width="100%" style="border: 0px" src="http://ads.esfiya.com/wp-content/uploads/2015/08/tuition_top.jpg" alt="" /></a>
<img width=0 height=0 src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="ga('send', 'event', 'TopBannerSciCom', 'impression','SciComTopTuition',2.00, {'nonInteraction': 1});"/>
       </div>
    <div style="display: none;" id="top_2nd">
           <a href="http://scicom.mv" onClick="ga('send', 'event', 'TopBannerSciCom', 'click','SciComTopEng',1.00, {'nonInteraction': 1});" ><img width="100%" style="border: 0px" src="http://ads.esfiya.com/wp-content/uploads/2015/08/eng_top.jpg" alt="" /></a>
<img width=0 height=0 src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="ga('send', 'event', 'TopBannerSciCom', 'impression','SciComTopEng',2.00, {'nonInteraction': 1});"/>
       </div>

<div style="display: none;" id="top_3rd">
           <a href="http://scicom.mv" onClick="ga('send', 'event', 'TopBannerAdHere', 'click','TopAdHere',1.00, {'nonInteraction': 1});" ><img width="100%" style="border: 0px" src="http://ads.esfiya.com/wp-content/uploads/2015/04/ad-here-red700x140.jpg" alt="" /></a>
<img width=0 height=0 src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="ga('send', 'event', 'TopBannerAdHere', 'impression','TopAdHere',2.00, {'nonInteraction': 1});"/>
       </div>
</div>
answer1: 回答1:

Impressions

All your advertisements are loaded, so all three onload scripts will take effect. They are only not visible because display: none.

You have to attack this impression event only to desired advertisement.

Ternary operator

Math.random() < 0.5 ? value1 : value2 : value3;

Try this instead:

var options = ['top_1st','top_2nd','top_3rd']; 
var chosenValue = options[Math.floor(Math.random()*options.length)];

Non-interaction flag on onclick

Why do you use non-interaction flag on onclick event? it is users interaction, so it would be interactive event.

onClick="ga('send', 'event', 'TopBannerSciCom', 'click','SciComTopEng',1.00);"

Impressions

你所有的广告都是装的,所以三的onload脚本生效。它们仅仅是不可见的,因为显示:没有。

你必须攻击这个印象事件只对期望的广告。

Ternary operator

Math.random() < 0.5 ? value1 : value2 : value3;

试试这个:

var options = ['top_1st','top_2nd','top_3rd']; 
var chosenValue = options[Math.floor(Math.random()*options.length)];

Non-interaction flag on onclick

你为什么使用非交互的国旗在onclick事件吗?它是用户交互,所以会是交互事件。

onClick="ga('send', 'event', 'TopBannerSciCom', 'click','SciComTopEng',1.00);"
javascript  jquery  google-analytics