From 8d7c2596469ddf5a7dd98eac27360d60e27e45e4 Mon Sep 17 00:00:00 2001 From: alexander Date: Fri, 17 May 2024 14:53:54 +0200 Subject: [PATCH] tagging to state --- .../walkerjs/src/__tests__/elblayer.test.ts | 2 +- packages/clients/walkerjs/src/index.ts | 19 ++++++++++++------- packages/clients/walkerjs/src/types/client.ts | 1 + packages/types/src/walkeros.ts | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/clients/walkerjs/src/__tests__/elblayer.test.ts b/packages/clients/walkerjs/src/__tests__/elblayer.test.ts index cf243e90..b460eaaa 100644 --- a/packages/clients/walkerjs/src/__tests__/elblayer.test.ts +++ b/packages/clients/walkerjs/src/__tests__/elblayer.test.ts @@ -191,7 +191,6 @@ describe('ElbLayer', () => { prefix: 'data-elb', run: false, session: { storage: false }, - tagging: expect.any(Number), }; const defaultInterface: WebClient.Instance = { @@ -210,6 +209,7 @@ describe('ElbLayer', () => { queue: expect.any(Array), round: expect.any(Number), session: expect.objectContaining({ storage: false }), + tagging: expect.any(Number), timing: expect.any(Number), user: {}, }; diff --git a/packages/clients/walkerjs/src/index.ts b/packages/clients/walkerjs/src/index.ts index f309473d..bb263d5f 100644 --- a/packages/clients/walkerjs/src/index.ts +++ b/packages/clients/walkerjs/src/index.ts @@ -213,7 +213,6 @@ export function Walkerjs( storage: false, // Do not use storage by default }, globalsStatic: assign(values.globalsStatic || {}), // Static global properties - tagging: 0, // Helpful to differentiate the clients used setup version }; // Wait for explicit run command to start @@ -264,6 +263,9 @@ export function Walkerjs( // The first round is a special one due to state changes const round = 0; + // Helpful to differentiate the clients used setup version + const tagging = values.tagging || 0; + // Offset counter to calculate timing property const timing = 0; @@ -283,6 +285,7 @@ export function Walkerjs( on, queue, round, + tagging, timing, user, }; @@ -398,13 +401,18 @@ export function Walkerjs( return; } + // Increase event counter + ++instance.count; + const { allowed, config, consent, + count, destinations, globals, group, + tagging, timing, queue, user, @@ -444,11 +452,8 @@ export function Walkerjs( (data as WalkerOS.Properties).id || window.location.pathname; } - // Increase event counter - ++instance.count; - const timestamp = Date.now(); - const id = `${timestamp}-${group}-${instance.count}`; + const id = `${timestamp}-${group}-${count}`; const source = { type: 'web', id: window.location.href, @@ -471,10 +476,10 @@ export function Walkerjs( timestamp, timing: Math.round((performance.now() - timing) / 10) / 100, group, - count: instance.count, + count, version: { client, - tagging: config.tagging, + tagging, }, source, }; diff --git a/packages/clients/walkerjs/src/types/client.ts b/packages/clients/walkerjs/src/types/client.ts index 0d56dd80..d5716796 100644 --- a/packages/clients/walkerjs/src/types/client.ts +++ b/packages/clients/walkerjs/src/types/client.ts @@ -54,6 +54,7 @@ export interface CustomConfig extends Partial { hooks?: Hooks.Functions; on?: On.Config; queue?: WalkerOS.Events; + tagging?: number; user?: WalkerOS.User; } diff --git a/packages/types/src/walkeros.ts b/packages/types/src/walkeros.ts index b57a1507..61ce7f6a 100644 --- a/packages/types/src/walkeros.ts +++ b/packages/types/src/walkeros.ts @@ -20,11 +20,11 @@ export interface State { on: On.Config; queue: Events; round: number; + tagging: number; user: User; } export interface Config { - tagging: number; default?: boolean; verbose?: boolean; // Enable verbose logging }