non security modules update
This commit is contained in:
@@ -1,64 +1,61 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.googleanalytics = {};
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
// Expression to check for absolute internal links.
|
||||
var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
|
||||
// Attach mousedown, keyup, touchstart events to document only and catch
|
||||
// clicks on all elements.
|
||||
$(document.body).bind("mousedown keyup touchstart", function(event) {
|
||||
|
||||
// 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 ga = Drupal.settings.googleanalytics;
|
||||
// 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("\\.(" + ga.trackDownloadExtensions + ")$", "i");
|
||||
|
||||
// Is the clicked URL internal?
|
||||
if (isInternal.test(this.href)) {
|
||||
if (Drupal.googleanalytics.isInternal(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.
|
||||
//console.info("Click on .colorbox item has been detected.");
|
||||
}
|
||||
// Is download tracking activated and the file extension configured for download tracking?
|
||||
else if (ga.trackDownload && isDownload.test(this.href)) {
|
||||
else if (Drupal.settings.googleanalytics.trackDownload && Drupal.googleanalytics.isDownload(this.href)) {
|
||||
// Download link clicked.
|
||||
var extension = isDownload.exec(this.href);
|
||||
_gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
|
||||
ga("send", "event", "Downloads", Drupal.googleanalytics.getDownloadExtension(this.href).toUpperCase(), Drupal.googleanalytics.getPageUrl(this.href));
|
||||
}
|
||||
else if (isInternalSpecial.test(this.href)) {
|
||||
else if (Drupal.googleanalytics.isInternalSpecial(this.href)) {
|
||||
// Keep the internal URL for Google Analytics website overlay intact.
|
||||
_gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
|
||||
ga("send", "pageview", { "page": Drupal.googleanalytics.getPageUrl(this.href) });
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ga.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
|
||||
if (Drupal.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
|
||||
// Mailto link clicked.
|
||||
_gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
|
||||
ga("send", "event", "Mails", "Click", this.href.substring(7));
|
||||
}
|
||||
else if (ga.trackOutbound && this.href.match(/^\w+:\/\//i)) {
|
||||
if (ga.trackDomainMode == 2 && isCrossDomain($(this).attr('hostname'), ga.trackCrossDomains)) {
|
||||
// Top-level cross domain clicked. document.location is handled by _link internally.
|
||||
event.preventDefault();
|
||||
_gaq.push(["_link", this.href]);
|
||||
}
|
||||
else {
|
||||
// External link clicked.
|
||||
_gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
|
||||
else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
|
||||
if (Drupal.settings.googleanalytics.trackDomainMode != 2 || (Drupal.settings.googleanalytics.trackDomainMode == 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) {
|
||||
// External link clicked / No top-level cross domain clicked.
|
||||
ga("send", "event", "Outbound links", "Click", this.href);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Track hash changes as unique pageviews, if this option has been enabled.
|
||||
if (Drupal.settings.googleanalytics.trackUrlFragments) {
|
||||
window.onhashchange = function() {
|
||||
ga('send', 'pageview', location.pathname + location.search + location.hash);
|
||||
}
|
||||
}
|
||||
|
||||
// Colorbox: This event triggers when the transition has completed and the
|
||||
// newly loaded content has been revealed.
|
||||
$(document).bind("cbox_complete", function() {
|
||||
$(document).bind("cbox_complete", function () {
|
||||
var href = $.colorbox.element().attr("href");
|
||||
if (href) {
|
||||
_gaq.push(["_trackPageview", href.replace(isInternal, '')]);
|
||||
ga("send", "pageview", { "page": Drupal.googleanalytics.getPageUrl(href) });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,7 +71,7 @@ $(document).ready(function() {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isCrossDomain(hostname, crossDomains) {
|
||||
Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) {
|
||||
/**
|
||||
* jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is
|
||||
* `null` or `undefined`, http://bugs.jquery.com/ticket/10076,
|
||||
@@ -88,6 +85,81 @@ function isCrossDomain(hostname, crossDomains) {
|
||||
else {
|
||||
return $.inArray(hostname, crossDomains) > -1 ? true : false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this is a download URL or not.
|
||||
*
|
||||
* @param string url
|
||||
* The web url to check.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
Drupal.googleanalytics.isDownload = function (url) {
|
||||
var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
|
||||
return isDownload.test(url);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this is an absolute internal URL or not.
|
||||
*
|
||||
* @param string url
|
||||
* The web url to check.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
Drupal.googleanalytics.isInternal = function (url) {
|
||||
var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
|
||||
return isInternal.test(url);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this is a special URL or not.
|
||||
*
|
||||
* URL types:
|
||||
* - gotwo.module /go/* links.
|
||||
*
|
||||
* @param string url
|
||||
* The web url to check.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
Drupal.googleanalytics.isInternalSpecial = function (url) {
|
||||
var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
|
||||
return isInternalSpecial.test(url);
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract the relative internal URL from an absolute internal URL.
|
||||
*
|
||||
* Examples:
|
||||
* - http://mydomain.com/node/1 -> /node/1
|
||||
* - http://example.com/foo/bar -> http://example.com/foo/bar
|
||||
*
|
||||
* @param string url
|
||||
* The web url to check.
|
||||
*
|
||||
* @return string
|
||||
* Internal website URL
|
||||
*/
|
||||
Drupal.googleanalytics.getPageUrl = function (url) {
|
||||
var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i");
|
||||
return url.replace(extractInternalUrl, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract the download file extension from the URL.
|
||||
*
|
||||
* @param string url
|
||||
* The web url to check.
|
||||
*
|
||||
* @return string
|
||||
* The file extension of the passed url. e.g. "zip", "txt"
|
||||
*/
|
||||
Drupal.googleanalytics.getDownloadExtension = function (url) {
|
||||
var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
|
||||
var extension = extractDownloadextension.exec(url);
|
||||
return (extension === null) ? '' : extension[1];
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
Reference in New Issue
Block a user