Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorSijawusz Pur Rahnama <sija@sija.pl>2014-07-17 00:34:54 +0400
committerSijawusz Pur Rahnama <sija@sija.pl>2014-08-24 20:50:31 +0400
commit9689138a34f6a2accb8c884131ca15dda183f063 (patch)
tree03d7a1888651d8e63dae8d9b3df84d9dda36c82e /js
parentfed85ff6a0de28983ccc9eb5c58b2a623c8480fe (diff)
Add support for passing callback argument
Implemented in the API #trackLink method, as it’s the one in which using callback makes most sense
Diffstat (limited to 'js')
-rw-r--r--js/piwik.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/js/piwik.js b/js/piwik.js
index 2dbb418aa7..30b998aa55 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -1347,11 +1347,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;
}
@@ -1359,7 +1360,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
@@ -1375,7 +1376,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()
}
};
@@ -1384,21 +1387,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;
@@ -1696,6 +1699,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
@@ -2016,10 +2020,10 @@ if (typeof Piwik !== 'object') {
/*
* Log the link or click with the server
*/
- function logLink(url, linkType, customData) {
+ function logLink(url, linkType, customData, callback) {
var request = getRequest(linkType + '=' + encodeWrapper(purify(url)), customData, 'link');
- sendRequest(request, configTrackerPause);
+ sendRequest(request, (callback ? 0 : configTrackerPause), callback);
}
/*
@@ -3014,9 +3018,9 @@ if (typeof Piwik !== 'object') {
* @param string linkType
* @param mixed customData
*/
- trackLink: function (sourceUrl, linkType, customData) {
+ trackLink: function (sourceUrl, linkType, customData, callback) {
trackCallback(function () {
- logLink(sourceUrl, linkType, customData);
+ logLink(sourceUrl, linkType, customData, callback);
});
},
@@ -3065,6 +3069,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.