Skip to content

Commit

Permalink
Send queued requests less often (matomo-org#15048)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur authored and diosmosis committed Nov 4, 2019
1 parent 4fc86a4 commit 7ba181b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
19 changes: 15 additions & 4 deletions js/piwik.js
Original file line number Diff line number Diff line change
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, ping, queueRequest, trackSiteSearch, trackEvent,
requests, timeout, enabled, sendRequests, queueRequest, disableQueueRequest,getRequestQueue, unsetPageIsUnloading,
requests, timeout, enabled, sendRequests, queueRequest, disableQueueRequest,setRequestQueueInterval,interval,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 @@ -5655,6 +5655,7 @@ if (typeof window.Piwik !== 'object') {
enabled: true,
requests: [],
timeout: null,
interval: 2500,
sendRequests: function () {
var requestsToTrack = this.requests;
this.requests = [];
Expand All @@ -5680,11 +5681,11 @@ if (typeof window.Piwik !== 'object') {
clearTimeout(this.timeout);
this.timeout = null;
}
// we always extend by another 1.75 seconds after receiving a tracking request
// we always extend by another 2.5 seconds after receiving a tracking request
this.timeout = setTimeout(function () {
requestQueue.timeout = null;
requestQueue.sendRequests();
}, 1750);
}, requestQueue.interval);

var trackerQueueId = 'RequestQueue' + uniqueTrackerId;
if (!Object.prototype.hasOwnProperty.call(plugins, trackerQueueId)) {
Expand Down Expand Up @@ -7365,6 +7366,17 @@ if (typeof window.Piwik !== 'object') {
requestQueue.enabled = false;
};

/**
* Defines after how many ms a queued requests will be executed after the request was queued initially.
* The higher the value the more tracking requests can be send together at once.
*/
this.setRequestQueueInterval = function (interval) {
if (interval < 1000) {
throw new Error('Request queue interval needs to be at least 1000ms');
}
requestQueue.interval = interval;
};

/**
* 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 Expand Up @@ -7901,7 +7913,6 @@ if (typeof window.Piwik !== 'object') {
if (window && window.piwikAsyncInit) {
window.piwikAsyncInit();
}

if (!window.Piwik.getAsyncTrackers().length) {
// we only create an initial tracker when no other async tracker has been created yet in piwikAsyncInit()
if (hasPaqConfiguration()) {
Expand Down
Loading

0 comments on commit 7ba181b

Please sign in to comment.