Original article: http://hi.baidu.com/laoliuseo/blog/item/2d1309c07b3c633fe5dd3bcb.html
Google Analytics advanced application SeriesArticleAuthor: sluke, which exclusively authorizes chinaz.com to repost, mainly explains the application of Google Analytics statistics. This is the second article in a series.
Here, event tracking refers to event tracking, which is more extensive than mouse event tracking. First, let's take a look at what can be counted:
1. Flash content, such as flash sites, Flash animations, and even Flash games.
2. Embedded Ajax
3. webpage Ornaments
4. File Download
5. Data or file loading time
The _ trackevent () method is used here. Its usage is as follows:
_ Trackevent (category, action, optional_label, optional_value)
Category (required)
This is the classification of the statistical item.
Action (required)
This is the specific behavior under the category
Label (optional)
It can be understood as a description of action. Optional.
Value (optional)
This is an integer field, which is usually used to count the number of downloads or the loading time.
If time tracking is deployed, there is another field in the Google Analytics report called implicit count (implicit count). This is used to count interactions. For example, if you click a button 10 times, calculate it once, similar to PV. This value needs to be understood based on different deployments.
Use a music station to describe _ trackevent () usage:
Pagetracker. _ trackevent ("Music", "play", "Sunshine City ");
Pagetracker. _ trackevent ("Music", "pause", "Sunshine City ");
Pagetracker. _ trackevent ("Music", "stop", "Sunshine City ");
Music is category, play is action, sunshine is label (here is the song name), put on the link is like this:
<A href = "#" onclick = "pagetracker. _ trackevent (" Music "," play "," Sunshine City ");"> play </a>
<A href = "#" onclick = "pagetracker. _ trackevent (" Music "," pause "," Sunshine City ");"> suspend </a>
<A href = "#" onclick = "pagetracker. _ trackevent (" Music "," stop "," Sunshine City ");"> stop </a>
If the button is attached to the player, you can view the behavior when you listen to the song "Sunshine City.
If you are counting the information downloaded from an MP3 file, write it as follows:
<A href = "#" onclick = "pagetracker. _ trackevent ('downloads', 'mp3', 'Sunshine city', downloadtime);"> download </a>
Value is added here. Every time the MP3 file is downloaded, the time is counted into the value in seconds. In the report, the value is represented by downloadtime, with implicit count added, the average download time can be calculated. Similarly, it can be used to record the playback of Flash animation. Note that the fourth parameter is an integer.
Extended Application
Here we will introduce two JS libraries:
Timetracker ()
Http://code.google.com/apis/analytics/samples/time-tracker.js
Mouseovertracker ()
Http://code.google.com/apis/analytics/samples/mouseover-tracker.js
They need to be loaded to the statistics page.
Timetracker () has two main features:
1. Record duration
2. Generate a bar chart
If notCode, Using timetracker () will create a category called "timetracker", record the start time and end time, calculate the time difference and send it to google analytics to form a report, and display the average time and other data with a bar chart. It is widely used, such as monitoring the average page loading time, video loading time, flash interface loading time, or embedded JS Script Loading time.
The function is as follows:
Timetracker (opt_buckets_array)
Returns a new time tracker.
_ Recordstarttime (opt_time)
Record Start Time
_ Recordendtime (opt_time)
Record End Time
_ Sethistogrambuckets (buckets_array)
Define the bar chart scale. The default value is [100,200,300,400,500,100 0, 1500,200 0, 2500,500 0].
_ Gettimediff ()
Calculation time difference
_ Track (tracker, opt_event_object_name, opt_event_label)
To use _ track (), you must ensure that the start time and end time have been recorded before.
Tracker is a tracking item that has been instantiated by Google Analytics on the statistics page, such as pagetracker.
Opt_event_object_name is the name that defines the appearance of timetracker () statistics in the report. The default value is "timetracker"
Opt_event_label describes the timetracker (), which is easier to find in the report.
Examples provided by Google:
<HTML>
<Head>
<Title> latency tracking demo </title>
</Head>
<Body>
<SCRIPT type = "text/JavaScript" src = "http://www.google-analytics.com/ga.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "http://www.example.com/scripts/time-tracker.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR timetracker = new timetracker ();
VaR pagetracker = _ gat. _ gettracker ("UA-1735986-1 ");
</SCRIPT>
<Input type = "button" value = "Start timer" onclick = "javascript: timetracker. _ recordstarttime ();"/>
<Input type = "button" value = "Stop timer" onclick = "javascript: timetracker. _ recordendtime ();"/>
<Input type = "button" value = "track! "Onclick =" javascript: timetracker. _ track (pagetracker, undefined, 'Manual test'); "/>
</Body>
</Html>
Example of defining a bar chart:
// Somewhere at the top of the page
VaR timetracker = new timetracker ();
Timetracker. _ recordstarttime ();
// Page load and Setup
// Now when the page is done loading...
Timetracker. _ recordendtime ();
// Specify your own histogram "action" Values
Timetracker. _ sethistogrambuckets ([10, 20, 50,100,500,100 0]);
// Assuming pagetracker is called from _ gat. _ gettracker (account)
Timetracker. _ track (pagetracker );
Mouseovertracker ()
In a PV, the user may trigger the onmouseover () event multiple times. In this way, the collected data has a lot of moisture. Using this library, you can only count the first onmouseover () event () ignore subsequent events.
The function is as follows:
Mouseovertracker (tracker)
Returns a new tracker. tracker is an optional parameter and must be a trail item that has been instantiated on the page, such as pagetracker.
_ Trackmouseover ()
When this method is called for the first time, an onmouseover () event is recorded, and subsequent operations are not recorded.
Example:
// We want to track mouse overs on a video unit that has the element ID "myvideounit ".
// Assuming pagetracker is called from _ gat. _ gettracker (account)
VaR mouseovertracker = new mouseovertracker (pagetracker );
Document. getelementbyid ("myvideounit"). onmouseover = mouseovertracker. _ trackmouseover;