Skip to content

Commit

Permalink
Expose setVisitorId JS tracker method (#16042)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur authored Jun 9, 2020
1 parent cc1df8e commit 210e566
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This is the Developer Changelog for Matomo platform developers. All changes in o

The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)** lets you see more details about any Matomo release, such as the list of new guides and FAQs, security fixes, and links to all closed issues.

## Matomo 3.13.7

### New API
* A new JavaScript tracker method has been added: `_paq.push(['setVisitorId', visitorId]);`. This can be used to force a specific visitorId. It takes a 16 digit hexadecimal string.

## Matomo 3.13.6

### API Changes
Expand Down
21 changes: 17 additions & 4 deletions js/piwik.js
Original file line number Diff line number Diff line change
Expand Up @@ -5844,9 +5844,6 @@ if (typeof window.Piwik !== 'object') {
this.getContent = function () {
return content;
};
this.setVisitorId = function (visitorId) {
visitorUUID = visitorId;
};

this.buildContentImpressionRequest = buildContentImpressionRequest;
this.buildContentInteractionRequest = buildContentInteractionRequest;
Expand Down Expand Up @@ -6066,6 +6063,22 @@ if (typeof window.Piwik !== 'object') {
}
};

/**
* Sets a Visitor ID to this visitor. Should be a 16 digit hex string.
* The visitorId won't be persisted in a cookie or something similar and needs to be set every time.
*
* @param string User ID
*/
this.setVisitorId = function (visitorId) {
var validation = /[0-9A-Fa-f]{16}/g;

if (isString(visitorId) && validation.test(visitorId)) {
visitorUUID = visitorId;
} else {
logConsoleError('Invalid visitorId set' + visitorId);
}
};

/**
* Gets the User ID if set.
*
Expand Down Expand Up @@ -7730,7 +7743,7 @@ if (typeof window.Piwik !== 'object') {
* Constructor
************************************************************/

var applyFirst = ['addTracker', 'disableCookies', 'setTrackerUrl', 'setAPIUrl', 'enableCrossDomainLinking', 'setCrossDomainLinkingTimeout', 'setSessionCookieTimeout', 'setVisitorCookieTimeout', 'setSecureCookie', 'setCookiePath', 'setCookieDomain', 'setDomains', 'setUserId', 'setSiteId', 'alwaysUseSendBeacon', 'enableLinkTracking', 'requireConsent', 'setConsentGiven'];
var applyFirst = ['addTracker', 'disableCookies', 'setTrackerUrl', 'setAPIUrl', 'enableCrossDomainLinking', 'setCrossDomainLinkingTimeout', 'setSessionCookieTimeout', 'setVisitorCookieTimeout', 'setSecureCookie', 'setCookiePath', 'setCookieDomain', 'setDomains', 'setUserId', 'setVisitorId', 'setSiteId', 'alwaysUseSendBeacon', 'enableLinkTracking', 'requireConsent', 'setConsentGiven'];

function createFirstTracker(piwikUrl, siteId)
{
Expand Down
Loading

0 comments on commit 210e566

Please sign in to comment.