Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send queued requests slightly less often and have method to change interval #15048

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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