可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
Any ideas?
回答1:
If you are using the OLD GOOGLE ANALYTICS TRACKING BLOCK, then the below should work:
<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:
<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
2. Make sure your IP is not excluded or filtered out of the analytis profile
3. Login to your google analytics account
4. Go to Real-Time section on the left hand sidebar.
5. Click on Events
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.
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. 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. I would suggest you get the event tracking working, before trying to adjust the bounce rates :-)
Thank you,
回答2:
In order to use Event Tracking the page needs the basic tracking code for 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". 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:
- 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]);
回答3:
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.
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>
回答4:
As well as this link to general tracking on events guide, the following is from the official GA docs. The following line is only a few lines down the page, just under the "overview" header:
For example, you might want to measure how many times a button was pressed
Hope this helps!
Amar
回答5:
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');