diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2014-09-02 13:19:21 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2014-09-02 13:19:21 +0400 |
commit | a6474178f9a770d56754636345082a3cc698eeb8 (patch) | |
tree | 894199addf0ce6f6c696c8fdb2735cdbcdb5757b /js | |
parent | e58a92d2512f7054c328f0e4370405d7bc0a17e8 (diff) | |
parent | f5fc3c8e62e0a90a6100346cf203d4dc037de22f (diff) |
Merge branch 'master' into 4996_content_tracking
Conflicts:
js/piwik.js
Diffstat (limited to 'js')
-rw-r--r-- | js/piwik.js | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/js/piwik.js b/js/piwik.js index f0516a3f49..0f1e14149c 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -2020,11 +2020,12 @@ if (typeof Piwik !== 'object') { * Send image request to Piwik server using GET. * The infamous web bug (or beacon) is a transparent, single pixel (1x1) image */ - function getImage(request) { + function getImage(request, callback) { var image = new Image(1, 1); image.onload = function () { iterator = 0; // To avoid JSLint warning of empty block + if (typeof callback === 'function') { callback(); } }; image.src = configTrackerUrl + (configTrackerUrl.indexOf('?') < 0 ? '?' : '&') + request; } @@ -2032,7 +2033,7 @@ if (typeof Piwik !== 'object') { /* * POST request to Piwik server using XMLHttpRequest. */ - function sendXmlHttpRequest(request) { + function sendXmlHttpRequest(request, callback) { try { // we use the progid Microsoft.XMLHTTP because // IE5.5 included MSXML 2.5; the progid MSXML2.XMLHTTP @@ -2048,7 +2049,9 @@ if (typeof Piwik !== 'object') { // fallback on error xhr.onreadystatechange = function () { if (this.readyState === 4 && !(this.status >= 200 && this.status < 300)) { - getImage(request); + getImage(request, callback); + } else { + if (typeof callback === 'function') { callback(); } } }; @@ -2057,21 +2060,21 @@ if (typeof Piwik !== 'object') { xhr.send(request); } catch (e) { // fallback - getImage(request); + getImage(request, callback); } } /* * Send request */ - function sendRequest(request, delay) { + function sendRequest(request, delay, callback) { var now = new Date(); if (!configDoNotTrack) { if (configRequestMethod === 'POST') { - sendXmlHttpRequest(request); + sendXmlHttpRequest(request, callback); } else { - getImage(request); + getImage(request, callback); } expireDateTime = now.getTime() + delay; @@ -2386,6 +2389,7 @@ if (typeof Piwik !== 'object') { lastVisitTs = currentVisitTs; } + // Detect the campaign information from the current URL // Only if campaign wasn't previously set // Or if it was set but we must attribute to the most recent one @@ -2889,14 +2893,14 @@ if (typeof Piwik !== 'object') { /* * Log the link or click with the server */ - function logLink(url, linkType, customData, sourceElement) { + function logLink(url, linkType, customData, callback, sourceElement) { var linkParams = linkType + '=' + encodeWrapper(purify(url)); linkParams = appendContentInteractionToRequestIfPossible(linkParams, sourceElement, url); var request = getRequest(linkParams, customData, 'link'); - - sendRequest(request, configTrackerPause); + + sendRequest(request, (callback ? 0 : configTrackerPause), callback); } /* @@ -3021,7 +3025,7 @@ if (typeof Piwik !== 'object') { // urldecode %xx sourceHref = urldecode(sourceHref); - logLink(sourceHref, linkType, undefined, originalSource); + logLink(sourceHref, linkType, undefined, null, originalSource); } } } @@ -3890,10 +3894,11 @@ if (typeof Piwik !== 'object') { * @param string sourceUrl * @param string linkType * @param mixed customData + * @param function callback */ - trackLink: function (sourceUrl, linkType, customData) { + trackLink: function (sourceUrl, linkType, customData, callback) { trackCallback(function () { - logLink(sourceUrl, linkType, customData); + logLink(sourceUrl, linkType, customData, callback); }); }, @@ -3976,6 +3981,7 @@ if (typeof Piwik !== 'object') { }); }, + /** * Used to record that the current page view is an item (product) page view, or a Ecommerce Category page view. * This must be called before trackPageView() on the product/category page. @@ -4278,4 +4284,3 @@ if (typeof piwik_log !== 'function') { } /*! @license-end */ - |