/[drupal]/contributions/modules/google_analytics/googleanalytics.js
ViewVC logotype

Contents of /contributions/modules/google_analytics/googleanalytics.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sat Oct 17 13:42:43 2009 UTC (5 weeks, 5 days ago) by hass
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +4 -1 lines
File MIME type: text/javascript
Wrap JS code in (function ($) { ... })(jQuery);
1 // $Id: googleanalytics.js,v 1.8 2009/08/22 13:09:45 hass Exp $
2 (function ($) {
3
4 $(document).ready(function() {
5
6 // Attach onclick event to document only and catch clicks on all elements.
7 $(document.body).click(function(event) {
8 // Catch only the first parent link of a clicked element.
9 $(event.target).parents("a:first,area:first").andSelf().filter("a,area").each(function() {
10
11 var ga = Drupal.settings.googleanalytics;
12 // Expression to check for absolute internal links.
13 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
14 // Expression to check for special links like gotwo.module /go/* links.
15 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
16 // Expression to check for download links.
17 var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
18
19 try {
20 // Is the clicked URL internal?
21 if (isInternal.test(this.href)) {
22 // Is download tracking activated and the file extension configured for download tracking?
23 if (ga.trackDownload && isDownload.test(this.href)) {
24 // Download link clicked.
25 var extension = isDownload.exec(this.href);
26 pageTracker._trackEvent("Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, ''));
27 }
28 else if (isInternalSpecial.test(this.href)) {
29 // Keep the internal URL for Google Analytics website overlay intact.
30 pageTracker._trackPageview(this.href.replace(isInternal, ''));
31 }
32 }
33 else {
34 if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
35 // Mailto link clicked.
36 pageTracker._trackEvent("Mails", "Click", this.href.substring(7));
37 }
38 else if (ga.trackOutgoing) {
39 // External link clicked.
40 pageTracker._trackEvent("Outgoing links", "Click", this.href);
41 }
42 }
43 } catch(err) {}
44
45 });
46 });
47 });
48
49 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2