Skip to content

Commit

Permalink
fix queued requests in JS tracker and add possibility to disable it (m…
Browse files Browse the repository at this point in the history
…atomo-org#14146)

* fix queued requests in JS tracker and add possibility to disable it

* Regenerate core tracker JS.

* Fix jslint error.

* trying to fix and debug failing js test

* fix js test

* trying to fix test

* debugging failing test

* fix JS tests

* fix jslint
  • Loading branch information
tsteur authored and diosmosis committed Mar 4, 2019
1 parent 637871b commit 9241966
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 150 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -13,7 +13,8 @@ The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)*
### New Features
* It is now possible to use monolog's FingersCrossedHandler which buffers all logs and logs all of them in case of warning or error.

### Deprecations
### New APIs
* A new tracker method `disableQueueRequest` has been added to disable queued requests which may be useful when logs are imported.
* The event `LanguageManager.getAvailableLanguages` has been deprecated. Use `LanguagesManager.getAvailableLanguages` instead.

## Matomo 3.8.0
Expand Down
31 changes: 22 additions & 9 deletions js/piwik.js
Expand Up @@ -998,7 +998,7 @@ if (typeof JSON_PIWIK !== 'object' && typeof window.JSON === 'object' && window.
addListener, enableLinkTracking, enableJSErrorTracking, setLinkTrackingTimer, getLinkTrackingTimer,
enableHeartBeatTimer, disableHeartBeatTimer, killFrame, redirectFile, setCountPreRendered,
trackGoal, trackLink, trackPageView, getNumTrackedPageViews, trackRequest, queueRequest, trackSiteSearch, trackEvent,
requests, timeout, sendRequests, queueRequest,
requests, timeout, enabled, sendRequests, queueRequest, disableQueueRequest,getRequestQueue, unsetPageIsUnloading,
setEcommerceView, getEcommerceItems, addEcommerceItem, removeEcommerceItem, clearEcommerceCart, trackEcommerceOrder, trackEcommerceCartUpdate,
deleteCookie, deleteCookies, offsetTop, offsetLeft, offsetHeight, offsetWidth, nodeType, defaultView,
innerHTML, scrollLeft, scrollTop, currentStyle, getComputedStyle, querySelectorAll, splice,
Expand Down Expand Up @@ -5656,29 +5656,32 @@ if (typeof window.Piwik !== 'object') {
return hookObj;
}

/*</DEBUG>*/

var requestQueue = {
enabled: true,
requests: [],
timeout: null,
sendRequests: function () {
var requestsToTrack = this.requests;
this.requests = [];
if (requestsToTrack.length === 1) {
sendRequest(requestsToTrack[0]);
sendRequest(requestsToTrack[0], configTrackerPause);
} else {
sendBulkRequest(requestsToTrack);
sendBulkRequest(requestsToTrack, configTrackerPause);
}
},
push: function (requestUrl) {
if (!requestUrl) {
return;
}
if (isPageUnloading) {
if (isPageUnloading || !this.enabled) {
// we don't queue as we need to ensure the request will be sent when the page is unloading...
trackerInstance.trackRequest(requestUrl);
sendRequest(requestUrl, configTrackerPause);
return;
}

this.requests.push(requestUrl);
requestQueue.requests.push(requestUrl);

if (this.timeout) {
clearTimeout(this.timeout);
Expand Down Expand Up @@ -5706,9 +5709,6 @@ if (typeof window.Piwik !== 'object') {
}
}
};

/*</DEBUG>*/

/************************************************************
* Constructor
************************************************************/
Expand Down Expand Up @@ -5801,6 +5801,12 @@ if (typeof window.Piwik !== 'object') {
this.getConsentRequestsQueue = function () {
return consentRequestsQueue;
};
this.getRequestQueue = function () {
return requestQueue;
};
this.unsetPageIsUnloading = function () {
isPageUnloading = false;
};
this.hasConsent = function () {
return configHasConsent;
};
Expand Down Expand Up @@ -7347,6 +7353,13 @@ if (typeof window.Piwik !== 'object') {
});
};

/**
* Disables sending requests queued
*/
this.disableQueueRequest = function () {
requestQueue.enabled = false;
};

/**
* Won't send the tracking request directly but wait for a short time to possibly send this tracking request
* along with other tracking requests in one go. This can reduce the number of requests send to your server.
Expand Down

0 comments on commit 9241966

Please sign in to comment.