diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-10-14 02:09:47 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-10-14 02:09:47 +0400 |
commit | 9f8e17f48ac73eec1fb2e521f103301edcb85baa (patch) | |
tree | 582b8891d485d107587a09510dcb7444644e5212 /js | |
parent | 5a1665cc02d4e5e4ec2f4804cf9f6e1e4e5f65e9 (diff) |
refs #6415 #4996 better protection for 0 actions if content tracking is used.
Delay first content tracking request a bit to make kinda sure a possible
previous pageview request is already executed. If there is a new visitor
and there are 2 tracking requests at nearly same time (eg trackPageView
and trackContentImpression) 2 visits will be created as both visitors
are basically at the same time. This is only a workaround and it this
problem might still occur. Also delay a link earlier in case an
interaction is happening to make sure the browser waits for the
interaction to be tracked.
Diffstat (limited to 'js')
-rw-r--r-- | js/piwik.js | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/js/piwik.js b/js/piwik.js index 74f63f45c0..ac49858073 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -2267,6 +2267,11 @@ if (typeof Piwik !== 'object') { trackedContentImpressions = [], isTrackOnlyVisibleContentEnabled = false, + // Guard to prevent empty visits see #6415. If there is a new visitor and there are 2 tracking requests + // at nearly same time (eg trackPageView and trackContentImpression) 2 visits will be created as both + // visitors are basically at the same time. + contentImpressionTrackingDelayInMs = 650, + // Guard against installing the link tracker more than once per Tracker instance linkTrackingInstalled = false, linkTrackingEnabled = false, @@ -2479,21 +2484,24 @@ if (typeof Piwik !== 'object') { } } - /* - * Send requests using bulk - */ - function sendBulkRequest(requests, delay) { - + function canSendBulkRequest(requests) + { if (configDoNotTrack) { - return; + return false; } - if (!requests || !requests.length) { + return (requests && requests.length); + } + + /* + * Send requests using bulk + */ + function sendBulkRequest(requests, delay) + { + if (!canSendBulkRequest(requests)) { return; } - // here we have to prevent 414 request uri too long error in case someone tracks like 1000 - var now = new Date(); var bulk = '{"requests":["?' + requests.join('","?') + '"]}'; @@ -3376,6 +3384,9 @@ if (typeof Piwik !== 'object') { return; } + var now = new Date(); + expireDateTime = now.getTime() + configTrackerPause; + var contentBlock = content.findParentContentNode(targetNode); var interactedElement; @@ -3387,6 +3398,7 @@ if (typeof Piwik !== 'object') { } if (!isNodeAuthorizedToTriggerInteraction(contentBlock, interactedElement)) { + expireDateTime = now.getTime(); return; } @@ -3412,10 +3424,10 @@ if (typeof Piwik !== 'object') { return 'href'; } - var block = content.buildContentBlock(contentBlock); if (!block) { + expireDateTime = now.getTime(); return; } @@ -4755,9 +4767,13 @@ if (typeof Piwik !== 'object') { trackCallbackOnReady(function () { // we have to wait till DOM ready var contentNodes = content.findContentNodes(); + var requests = getContentImpressionsRequestsFromNodes(contentNodes); - var requests = getContentImpressionsRequestsFromNodes(contentNodes); - sendBulkRequest(requests, configTrackerPause); + setTimeout(function () { + sendBulkRequest(requests, configTrackerPause); + }, contentImpressionTrackingDelayInMs); + + contentImpressionTrackingDelayInMs = 0; }); }); }, @@ -4815,9 +4831,12 @@ if (typeof Piwik !== 'object') { trackCallbackOnLoad(function () { // we have to wait till CSS parsed and applied var contentNodes = content.findContentNodes(); + var requests = getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes); - var requests = getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes); - sendBulkRequest(requests, configTrackerPause); + setTimeout(function () { + sendBulkRequest(requests, configTrackerPause); + }, contentImpressionTrackingDelayInMs); + contentImpressionTrackingDelayInMs = 0; }); }); }, |