From d710c1706a6bed917f612b83def7373f09253774 Mon Sep 17 00:00:00 2001 From: Jack Keene Date: Mon, 9 Oct 2023 17:10:19 +0100 Subject: [PATCH 1/4] Add setNetworkUserId function to index.ts --- libraries/browser-tracker-core/src/tracker/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/browser-tracker-core/src/tracker/index.ts b/libraries/browser-tracker-core/src/tracker/index.ts index a6443a932..9f70bbd84 100755 --- a/libraries/browser-tracker-core/src/tracker/index.ts +++ b/libraries/browser-tracker-core/src/tracker/index.ts @@ -318,7 +318,8 @@ export function Tracker( configSessionContext = trackerConfiguration.contexts?.session ?? false, toOptoutByCookie: string | boolean, onSessionUpdateCallback = trackerConfiguration.onSessionUpdateCallback, - manualSessionUpdateCalled = false; + manualSessionUpdateCalled = false, + networkUserId: string | undefined; if (trackerConfiguration.hasOwnProperty('discoverRootDomain') && trackerConfiguration.discoverRootDomain) { configCookieDomain = findRootDomain(configCookieSameSite, configCookieSecure); @@ -336,6 +337,7 @@ export function Tracker( core.addPayloadPair('lang', browserLanguage); core.addPayloadPair('res', resolution); core.addPayloadPair('cd', colorDepth); + setNetworkUserId(networkUserId); /* * Initialize tracker @@ -1149,6 +1151,11 @@ export function Tracker( activityTrackingConfig.configurations[actionKey] = undefined; } + function setNetworkUserId(networkUserId: string | undefined): void { + if (networkUserId) { + core.addPayloadPair('tnuid', networkUserId); + } + } const apiMethods = { getDomainSessionIndex: function () { return memorizedVisitCount; @@ -1311,6 +1318,8 @@ export function Tracker( }, clearUserData: clearUserDataAndCookies, + + setNetworkUserId, }; return { From 97ae45aa3cbd805014ec10b16e8c351cdba62fc3 Mon Sep 17 00:00:00 2001 From: Jack Keene Date: Mon, 9 Oct 2023 17:10:46 +0100 Subject: [PATCH 2/4] Add setNetworkUserId function to types.ts --- libraries/browser-tracker-core/src/tracker/types.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/browser-tracker-core/src/tracker/types.ts b/libraries/browser-tracker-core/src/tracker/types.ts index 0f5801c9d..dbc313609 100755 --- a/libraries/browser-tracker-core/src/tracker/types.ts +++ b/libraries/browser-tracker-core/src/tracker/types.ts @@ -602,6 +602,12 @@ export interface BrowserTracker { * @param configuration - The plugin to add */ addPlugin: (configuration: BrowserPluginConfiguration) => void; + + /** + * Set the newtork user id + * @param networkUserId - The custom network user id + */ + setNetworkUserId: (networkUserId: string) => void; } /** From 45ef10b45392f793b8bea5ac14534f024250c4b0 Mon Sep 17 00:00:00 2001 From: Jack Keene Date: Mon, 9 Oct 2023 17:11:23 +0100 Subject: [PATCH 3/4] Add setNetworkUserId function to api --- trackers/browser-tracker/src/api.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trackers/browser-tracker/src/api.ts b/trackers/browser-tracker/src/api.ts index e8eba06b6..b5d3c9a99 100644 --- a/trackers/browser-tracker/src/api.ts +++ b/trackers/browser-tracker/src/api.ts @@ -506,3 +506,15 @@ export function addPlugin(configuration: BrowserPluginConfiguration, trackers?: t.addPlugin(configuration); }); } + +/** + * Set the business-defined network user ID for this user. + * + * @param networkUserId - The business-defined network user ID + * @param trackers - The tracker identifiers which will be configured + */ +export function setNetworkUserId(networkUserId: string, trackers?: Array) { + dispatchToTrackers(trackers, (t) => { + t.setNetworkUserId(networkUserId); + }); +} From ab32f068727386cf947c255185fa88cbf8afa70d Mon Sep 17 00:00:00 2001 From: Jack Keene Date: Mon, 9 Oct 2023 17:19:23 +0100 Subject: [PATCH 4/4] Run rush change --- .../feature-set_network_user_id_2023-10-09-16-16.json | 10 ++++++++++ .../feature-set_network_user_id_2023-10-09-16-16.json | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 common/changes/@snowplow/browser-tracker-core/feature-set_network_user_id_2023-10-09-16-16.json create mode 100644 common/changes/@snowplow/browser-tracker/feature-set_network_user_id_2023-10-09-16-16.json diff --git a/common/changes/@snowplow/browser-tracker-core/feature-set_network_user_id_2023-10-09-16-16.json b/common/changes/@snowplow/browser-tracker-core/feature-set_network_user_id_2023-10-09-16-16.json new file mode 100644 index 000000000..4d5407c0f --- /dev/null +++ b/common/changes/@snowplow/browser-tracker-core/feature-set_network_user_id_2023-10-09-16-16.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-tracker-core", + "comment": "Add setNetworkUserId() function", + "type": "none" + } + ], + "packageName": "@snowplow/browser-tracker-core" +} \ No newline at end of file diff --git a/common/changes/@snowplow/browser-tracker/feature-set_network_user_id_2023-10-09-16-16.json b/common/changes/@snowplow/browser-tracker/feature-set_network_user_id_2023-10-09-16-16.json new file mode 100644 index 000000000..a18df5682 --- /dev/null +++ b/common/changes/@snowplow/browser-tracker/feature-set_network_user_id_2023-10-09-16-16.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-tracker", + "comment": "Add setNetworkUserId() function", + "type": "none" + } + ], + "packageName": "@snowplow/browser-tracker" +} \ No newline at end of file