PageSourceSearch

https://www.gradus.com/sites/all/modules/google_analytics/googleanalytics.js?Q

js gradus.com collected 2026-10-04 12:51:18 UTC 6,136 bytes, 190 lines download raw bytes

1
2Drupal.googleanalytics = {};
3
4$(document).ready(function() {
5
6  // Attach mousedown, keyup, touchstart events to document only and catch
7  // clicks on all elements.
8  $(document.body).bind("mousedown keyup touchstart", function(event) {
9
10    // Catch only the first parent link of a clicked element.
11    $(event.target).parents("a:first,area:first").andSelf().filter("a,area").each(function() {
12
13      // Is the clicked URL internal?
14      if (Drupal.googleanalytics.isInternal(this.href)) {
15        // Skip 'click' tracking, if custom tracking events are bound.
16        if ($(this).is('.colorbox')) {
17          // Do nothing here. The custom event will handle all tracking.
18          //console.info("Click on .colorbox item has been detected.");
19        }
20        // Is download tracking activated and the file extension configured for download tracking?
21        else if (Drupal.settings.googleanalytics.trackDownload && Drupal.googleanalytics.isDownload(this.href)) {
22          // Download link clicked.
23          ga("send", {
24            "hitType": "event",
25            "eventCategory": "Downloads",
26            "eventAction": Drupal.googleanalytics.getDownloadExtension(this.href).toUpperCase(),
27            "eventLabel": Drupal.googleanalytics.getPageUrl(this.href),
28            "transport": "beacon"
29          });
30        }
31        else if (Drupal.googleanalytics.isInternalSpecial(this.href)) {
32          // Keep the internal URL for Google Analytics website overlay intact.
33          ga("send", {
34            "hitType": "pageview",
35            "page": Drupal.googleanalytics.getPageUrl(this.href),
36            "transport": "beacon"
37          });
38        }
39      }
40      else {
41        if (Drupal.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
42          // Mailto link clicked.
43          ga("send", {
44            "hitType": "event",
45            "eventCategory": "Mails",
46            "eventAction": "Click",
47            "eventLabel": this.href.substring(7),
48            "transport": "beacon"
49          });
50        }
51        else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
52          if (Drupal.settings.googleanalytics.trackDomainMode !== 2 || (Drupal.settings.googleanalytics.trackDomainMode === 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) {
53            // External link clicked / No top-level cross domain clicked.
54            ga("send", {
55              "hitType": "event",
56              "eventCategory": "Outbound links",
57              "eventAction": "Click",
58              "eventLabel": this.href,
59              "transport": "beacon"
60            });
61          }
62        }
63      }
64    });
65  });
66
67  // Track hash changes as unique pageviews, if this option has been enabled.
68  if (Drupal.settings.googleanalytics.trackUrlFragments) {
69    window.onhashchange = function() {
70      ga("send", {
71        "hitType": "pageview",
72        "page": location.pathname + location.search + location.hash
73      });
74    };
75  }
76
77  // Colorbox: This event triggers when the transition has completed and the
78  // newly loaded content has been revealed.
79  $(document).bind("cbox_complete", function () {
80    var href = $.colorbox.element().attr("href");
81    if (href) {
82      ga("send", {
83        "hitType": "pageview",
84        "page": Drupal.googleanalytics.getPageUrl(href)
85      });
86    }
87  });
88
89});
90
91/**
92 * Check whether the hostname is part of the cross domains or not.
93 *
94 * @param string hostname
95 *   The hostname of the clicked URL.
96 * @param array crossDomains
97 *   All cross domain hostnames as JS array.
98 *
99 * @return boolean
100 */
101Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) {
102  /**
103   * jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is
104   * `null` or `undefined`, http://bugs.jquery.com/ticket/10076,
105   * https://github.com/jquery/jquery/commit/a839af034db2bd934e4d4fa6758a3fed8de74174
106   *
107   * @todo: Remove/Refactor in D8
108   */
109  if (!crossDomains) {
110    return false;
111  }
112  else {
113    return $.inArray(hostname, crossDomains) > -1 ? true : false;
114  }
115};
116
117/**
118 * Check whether this is a download URL or not.
119 *
120 * @param string url
121 *   The web url to check.
122 *
123 * @return boolean
124 */
125Drupal.googleanalytics.isDownload = function (url) {
126  var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
127  return isDownload.test(url);
128};
129
130/**
131 * Check whether this is an absolute internal URL or not.
132 *
133 * @param string url
134 *   The web url to check.
135 *
136 * @return boolean
137 */
138Drupal.googleanalytics.isInternal = function (url) {
139  var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
140  return isInternal.test(url);
141};
142
143/**
144 * Check whether this is a special URL or not.
145 *
146 * URL types:
147 *  - gotwo.module /go/* links.
148 *
149 * @param string url
150 *   The web url to check.
151 *
152 * @return boolean
153 */
154Drupal.googleanalytics.isInternalSpecial = function (url) {
155  var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
156  return isInternalSpecial.test(url);
157};
158
159/**
160 * Extract the relative internal URL from an absolute internal URL.
161 *
162 * Examples:
163 * - http://mydomain.com/node/1 -> /node/1
164 * - http://example.com/foo/bar -> http://example.com/foo/bar
165 *
166 * @param string url
167 *   The web url to check.
168 *
169 * @return string
170 *   Internal website URL
171 */
172Drupal.googleanalytics.getPageUrl = function (url) {
173  var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i");
174  return url.replace(extractInternalUrl, '');
175};
176
177/**
178 * Extract the download file extension from the URL.
179 *
180 * @param string url
181 *   The web url to check.
182 *
183 * @return string
184 *   The file extension of the passed url. e.g. "zip", "txt"
185 */
186Drupal.googleanalytics.getDownloadExtension = function (url) {
187  var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
188  var extension = extractDownloadextension.exec(url);
189  return (extension === null) ? '' : extension[1];
190};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.