简体   繁体   中英

How to track a custom event on google Analytics

How to track a custom event on Google Analytics. I have used this code alone:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-42651041-1']);
_gaq.push(['_trackEvent','Popup','Click','Step1']); //on button click

Is there any extra code need to be added? for tracking, on every event?

You don't need any other code, just event tracking code is enough. Once you installed google analytics , please the event tracking code in your button “OnClick” event.

For more information , https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

Sample code from my site (I am tracking traffic to my social media sites in button OnClick event)

<a href="http://www.linkedin.com/in/isharashehan" target="_blank" title="LinkedIn" onclick="_gaq.push(['_trackEvent', 'LinksToSocialMedia', 'SM_Button_Click','LinkedIn']);"> # </a>

You need to first get a tracking snippet from Google Analytics. Only after you put that code into your header must you insert your event tracking code . Note that on that page it states that:

Once event tracking has been set up and working on your site for a day , go to the Content section of the reports and view Event Tracking

You're welcome :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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