diff options
author | Justin Velluppillai <justin@innocraft.com> | 2022-03-24 13:53:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 13:53:44 +0300 |
commit | b2a17cb2e59043b2978286e97cdec584e3e2393f (patch) | |
tree | 584d5724f0c471405a62c1c569425b87d151f113 /js/piwik.js | |
parent | 738333d186a5587413a388ecca7d8aafff1d570f (diff) |
Don't create cookies when disabled (#18935)
* Rebuilding
* Empty commit
* rebuilt piwik.js
* Need to track a pageview before checking cookie
* more fixes for tests where not setting visitorId cookie until tracking request first sent
* a few more test fixes
* allow a little longer for beforeUnloadHandler now it does more by default...
* bump it a little higher
* track a page view so the referer tests work
* undo last
* testing
* give more info
* removed test code
* undo test changes, set a variable to store initial visitor id while the cookie isn't set
* one more test removal
* Track a pageview to create cookie before testing matching visitorIds
* rebuilt piwik.js
* trackpageview so some more visitorid tests pass
* one more tracking request now
* allow more time for beforeUnloadHandler
* Instead of storing a temporary variable we just create the cookie when getVisitorId is called, if it is not existing
* rebuilt piwik.js
* Removed unnecessary changes
* rebuilt piwik.js
* minor fixes
* different approach
* rebuilt piwik.js
* set visitor id cookie in getVisitorInfo also
* rebuilt piwik.js
* remove unnecessary configCookiesDisabled check
* rebuilt piwik.js
Co-authored-by: justinvelluppillai <justinvelluppillai@users.noreply.github.com>
Diffstat (limited to 'js/piwik.js')
-rw-r--r-- | js/piwik.js | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/js/piwik.js b/js/piwik.js index 41dd1af52e..7b1ba0e56b 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -4896,7 +4896,6 @@ if (typeof window.Matomo !== 'object') { * initialize tracker */ updateDomainHash(); - setVisitorIdCookie(); /*<DEBUG>*/ /* @@ -5000,26 +4999,30 @@ if (typeof window.Matomo !== 'object') { }; /** - * Get visitor ID (from first party cookie) - * - * @return string Visitor ID in hexits (or empty string, if not yet known) - */ - this.getVisitorId = function () { - return getValuesFromVisitorIdCookie().uuid; - }; - - /** * Get the visitor information (from first party cookie) * * @return array */ this.getVisitorInfo = function () { + if (!getCookie(getCookieName('id'))) { + setVisitorIdCookie(); + } + // Note: in a new method, we could return also return getValuesFromVisitorIdCookie() // which returns named parameters rather than returning integer indexed array return loadVisitorIdCookie(); }; /** + * Get visitor ID (from first party cookie) + * + * @return string Visitor ID in hexits (or empty string, if not yet known) + */ + this.getVisitorId = function () { + return this.getVisitorInfo()[1]; + }; + + /** * Get the Attribution information, which is an array that contains * the Referrer used to reach the site as well as the campaign name and keyword * It is useful only when used in conjunction with Tracker API function setAttributionInfo() @@ -7071,6 +7074,15 @@ if (typeof window.Matomo !== 'object') { }); Matomo.trigger('TrackerSetup', [this]); + + Matomo.addPlugin('TrackerVisitorIdCookie' + uniqueTrackerId, { + // if no tracking request was sent we refresh the visitor id cookie on page unload + unload: function () { + if (!hasSentTrackingRequestYet) { + setVisitorIdCookie(); + } + } + }); } function TrackerProxy() { |