-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaidu_analytics.js
More file actions
66 lines (57 loc) · 2.51 KB
/
Copy pathbaidu_analytics.js
File metadata and controls
66 lines (57 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @file
* Behaviours for the Baidu Analytics module to integrated with its JS API.
*
* @link http://tongji.baidu.com/open/api/more?p=guide_overview
*/
(function ($) {
$(document).ready(function() {
// Expression to check for absolute internal links.
var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
// Attach onclick event to document only and catch clicks on all elements.
$(document.body).click(function(event) {
// Catch the closest surrounding link of a clicked element.
$(event.target).closest("a,area").each(function() {
var hm = Drupal.settings.baidu_analytics;
// Expression to check for special links like gotwo.module /go/* links.
var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
// Expression to check for download links.
var isDownload = new RegExp("\\.(" + hm.trackDownloadExtensions + ")$", "i");
// Is the clicked URL internal?
if (isInternal.test(this.href)) {
// Skip 'click' tracking, if custom tracking events are bound.
if ($(this).is('.colorbox')) {
// Do nothing here. The custom event will handle all tracking.
}
// Is download tracking activated and the file extension configured for download tracking?
else if (hm.trackDownload && isDownload.test(this.href)) {
// Download link clicked.
var extension = isDownload.exec(this.href);
_hmt.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), "Downloads Link: " + this.href.replace(isInternal, '')]);
}
else if (isInternalSpecial.test(this.href)) {
// Keep the internal URL for Baidu Analytics website overlay intact.
_hmt.push(["_trackPageview", this.href.replace(isInternal, '')]);
}
}
else {
if (hm.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
// Mailto link clicked.
_hmt.push(["_trackEvent", "Mails", "Click", "Mails: " + this.href.substring(7)]);
}
else if (hm.trackOutbound && this.href.match(/^\w+:\/\//i)) {
_hmt.push(["_trackEvent", "Outbound links", "Click", "Outbound links: " + this.href]);
}
}
});
});
// Colorbox: This event triggers when the transition has completed and the
// newly loaded content has been revealed.
$(document).bind("cbox_complete", function() {
var href = $.colorbox.element().attr("href");
if (href) {
_hmt.push(["_trackPageview", href.replace(isInternal, '')]);
}
});
});
})(jQuery);