简体   繁体   English

Google Analytics事件跟踪代码

[英]Google Analytics Event Tracking code

I'm using Google Analytics, at the top level I can see who has come onto my site, however I cannot see track my event tracking for my social network buttons, I think I may have developed these wrong. 我正在使用谷歌分析,在顶级我可以看到谁进入我的网站,但是我无法看到跟踪我的社交网络按钮的事件跟踪,我想我可能已经发现了这些错误。

These events are not been tracked on my analytics account that I can see anyway if someone knows where they are kept that would be great. 我的分析帐户中没有跟踪这些事件,如果有人知道他们保留在哪里会很棒,我无论如何都可以看到这些事件。

But the code I've used is below as I'm not sure if I have implemented this correctly: 但我使用的代码如下,因为我不确定我是否正确实现了这个:

<a href="https://twitter.com/share?text=2009:%20Michael%20Jackson%20Dies&hashtags=DIGITL,MichaelJackson" target="_blank" onClick="_gaq.push(['_trackEvent', 'Social Media', 'Twitter', 'Share 2009 Jackson',, false]);"><img src="images/twitter_icon.png" id="2009_michaeljackson_share_twitter" alt="Share on Twitter" title="Share on Twitter"></a>

If someone can advise if this is correct will be great! 如果有人可以建议这是否正确将是伟大的!

Update 更新

As per the answer below, I removed the double comma retested in the Events Overview section and no on click items have appeared... 根据下面的答案,我删除了事件概述部分中重新测试的双逗号,并且没有出现点击项目......

Example of updated code: 更新代码示例:

<li><a href="#" onClick="_gaq.push(['_trackEvent', 'Social Media', 'Facebook', 'Share 2003', false]);"><img src="images/facebook_icon.png" id="2003_share_fb" alt="Share Icon for Twitter" title="Share on Facebook"></a></li>

I've even added them as a goal in Google Analytics but this doesn't seem to work either. 我甚至将它们添加为Google Analytics中的目标,但这似乎也不起作用。

Any ideas? 有任何想法吗?

If you are using the OLD GOOGLE ANALYTICS TRACKING BLOCK , then the below should work: 如果您使用的是旧的Google ANALYTICS TRACKING BLOCK ,则以下内容应该有效:

<li><a href="#" onclick="_gaq.push(['_trackEvent', 'Social Media', 'Facebook', 'Share 2003', false]);"><img src="images/facebook_icon.png" id="2003_share_fb" alt="Share Icon for Twitter" title="Share on Facebook"></a></li>

If you are using the NEW GOOGLE UNIVERSAL EVENT TRACKING code the below will work: 如果您使用新的GOOGLE UNIVERSAL EVENT TRACKING代码,则以下内容将起作用:

<li><a href="#" onclick="ga('send', 'event', 'Social Media', 'Facebook', 'Share 2003');"><img src="images/facebook_icon.png" id="2003_share_fb" alt="Share Icon for Twitter" title="Share on Facebook"></a></li>

To check whether the events are firing correctly VERY QUICKLY. 检查事件是否非常快速地正确触发。 Do the following; 请执行下列操作;

1. Make sure you update the code on your site and make it live 1.确保更新站点上的代码并使其生效

2. Make sure your IP is not excluded or filtered out of the analytis profile 2.确保不排除您的IP或从分析配置文件中过滤掉您的IP

3. Login to your google analytics account 3.登录您的Google Analytics(分析)帐户

4. Go to Real-Time section on the left hand sidebar. 4.转到左侧边栏的“ 实时”部分。

5. Click on Events 5.单击“ 事件”

6. Go to your site and click on the link you added the event code to and then watch if that link shows up in the real-time -> events section. 6.转到您的站点并单击您添加事件代码的链接,然后观察该链接是否显示在实时 - >事件部分中。

Bounce Rate Discussion 跳出率讨论

About the bounce rate everyone is talking about. 关于每个人都在谈论的跳出率。 Usually when you add an event and someone clicks on it, then google analytics will assume that user interacted with your site and therefore provide a very low bounce rate for that page. 通常,当您添加某个活动并且有人点击该活动时,Google解析会假定该用户与您的网站进行了互动,因此该网页的跳出率非常低。 If you don;t want the bounce rate to be affected on the page where the event is placed, then you can add the false at the end of the event. 如果您不希望在放置事件的页面上影响跳出率,则可以在事件结束时添加false。 I would suggest you get the event tracking working, before trying to adjust the bounce rates :-) 在尝试调整跳出率之前,我建议你让事件跟踪工作:-)

Thank you, 谢谢,

In order to use Event Tracking the page needs the basic tracking code for Google Analytics. 要使用事件跟踪,该页面需要Google Analytics的基本跟踪代码。 So I'm assuming this page is tagged with a code similar to this: 所以我假设这个页面标有类似于这样的代码:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

This is the Classic Analytics Tracking Code. 这是经典分析跟踪代码。 There's also a chance that you are using a newer version of Analytics called " Universal Analytics ". 您还可以使用名为“ Universal Analytics ”的更新版Google Analytics That version has a different tracking code and the event also has a different syntax. 该版本具有不同的跟踪代码,并且该事件也具有不同的语法。 In case you are using Universal Analytics tracking code the event below won't work. 如果您使用的是通用分析跟踪代码,则以下活动将无效。

The _trackEvent method takes 5 parameters: _trackEvent方法有5个参数:

  • String Category 字符串类别
  • String Action 字符串动作
  • String Label 字符串标签
  • Number Value (optional) 数值(可选)
  • Boolean Non-Interactive (optional) 布尔非交互式(可选)

All of them are positional arguments so in case you want to provide the non-interactive flag you have to pass a value or undefined. 所有这些都是位置参数,所以如果你想提供非交互式标志,你必须传递一个值或未定义。 Any of the following options are valid and similar. 以下任何选项均有效且类似。

_gaq.push(['_trackEvent', 'Social Media', 'Facebook', 'Share 2003', undefined, false]);

_gaq.push(['_trackEvent', 'Social Media', 'Facebook', 'Share 2003', 0,false]);

I had a quick read of the Analytics documentation. 我快速阅读了分析文档。

You have a double comma when you're pushing and the fourth part is optional. 当你推动时你有一个双逗号,第四部分是可选的。

So you can remove the ',, false' from your _gaq.push. 所以你可以从你的_gaq.push中删除',, false'。

Let me know if that helps 如果有帮助,请告诉我

Updated for his update 更新了他的更新

Try this code in place of yours. 尝试使用此代码代替您的代码。 Let me know if it works. 如果有效,请告诉我。

<li><a href="#" onClick="_gaq.push(['_trackEvent', 'Social Media', 'Facebook', 'Share 2003']);"><img src="images/facebook_icon.png" id="2003_share_fb" alt="Share Icon for Twitter" title="Share on Facebook"></a></li>

As well as this link to general tracking on events guide, the following is from the official GA docs. 除了此事件指南的一般跟踪链接 ,以下内容来自GA官方文档。 The following line is only a few lines down the page, just under the "overview" header: 以下行仅在页面下方几行,就在“overview”标题下:

For example, you might want to measure how many times a button was pressed 例如,您可能想要测量按下按钮的次数

Hope this helps! 希望这可以帮助!

Amar 阿马尔

In my success page I have add this example: 在我的成功页面中,我添加了这个示例:

 ga('require', 'ecommerce'); ga('ecommerce:addTransaction', { 'id': '{/literal}{$idorder}{literal}', // Order ID. 'affiliation': '{/literal}{$lang.i_title}{literal}', // Affiliation or store name. 'revenue': '{/literal}{$total_sum}{literal}', // Grand Total. 'shipping': '{/literal}{$delivery_price}{literal}', // Shipping. 'tax': '0.00', 'currency': 'BGN' // local currency code. }); {/literal}{if !empty($products)}{foreach from=$products key=k item=v}{literal} ga('ecommerce:addItem', { 'id': '{/literal}{$idorder}{literal}', 'name': '{/literal}{$v.name}{literal}', 'sku': '{/literal}{$v.idnumber}{literal}', 'category': '{/literal}{$v.idcategory}{literal}', 'price': '{/literal}{$v.product_price}{literal}', 'quantity': '{/literal}{$v.count}{literal}', 'currency': 'BGN' }); {/literal}{/foreach}{/if}{literal} ga('ecommerce:send'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM