Skip to content

Commit

Permalink
tagging to state
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed May 17, 2024
1 parent 622f40d commit 8d7c259
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/clients/walkerjs/src/__tests__/elblayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ describe('ElbLayer', () => {
prefix: 'data-elb',
run: false,
session: { storage: false },
tagging: expect.any(Number),
};

const defaultInterface: WebClient.Instance = {
Expand All @@ -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: {},
};
Expand Down
19 changes: 12 additions & 7 deletions packages/clients/walkerjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -283,6 +285,7 @@ export function Walkerjs(
on,
queue,
round,
tagging,
timing,
user,
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions packages/clients/walkerjs/src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface CustomConfig extends Partial<Config> {
hooks?: Hooks.Functions;
on?: On.Config;
queue?: WalkerOS.Events;
tagging?: number;
user?: WalkerOS.User;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/walkeros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8d7c259

Please sign in to comment.