Skip to content

Commit

Permalink
timing to state
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed May 16, 2024
1 parent 000289f commit dbeceba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 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 @@ -196,7 +196,6 @@ describe('ElbLayer', () => {
run: false,
round: expect.any(Number),
session: { storage: false },
timing: expect.any(Number),
tagging: expect.any(Number),
};

Expand All @@ -211,6 +210,7 @@ describe('ElbLayer', () => {
hooks: {},
queue: expect.any(Array),
session: expect.objectContaining({ storage: false }),
timing: expect.any(Number),
user: {},
};

Expand Down
22 changes: 16 additions & 6 deletions packages/clients/walkerjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export function Walkerjs(
storage: false, // Do not use storage by default
},
globalsStatic: assign(values.globalsStatic || {}), // Static global properties
timing: 0, // Offset counter to calculate timing property
tagging: 0, // Helpful to differentiate the clients used setup version
};

Expand Down Expand Up @@ -252,6 +251,9 @@ export function Walkerjs(

const queue = values.queue || []; // Temporary event queue for all events of a run

// Offset counter to calculate timing property
const timing = 0;

const user = values.user || {}; // Handles the user ids

return {
Expand All @@ -262,6 +264,7 @@ export function Walkerjs(
group,
hooks,
queue,
timing,
user,
};
}
Expand Down Expand Up @@ -376,8 +379,16 @@ export function Walkerjs(
return;
}

const { config, consent, destinations, globals, group, queue, user } =
instance;
const {
config,
consent,
destinations,
globals,
group,
timing,
queue,
user,
} = instance;

// Check if walker is allowed to run
if (!config.allowed) return;
Expand Down Expand Up @@ -415,7 +426,6 @@ export function Walkerjs(

++config.count;
const timestamp = Date.now();
const timing = Math.round((performance.now() - config.timing) / 10) / 100;
const id = `${timestamp}-${group}-${config.count}`;
const source = {
type: 'web',
Expand All @@ -437,7 +447,7 @@ export function Walkerjs(
entity,
action,
timestamp,
timing,
timing: Math.round((performance.now() - timing) / 10) / 100,
group,
count: config.count,
version: {
Expand Down Expand Up @@ -561,7 +571,7 @@ export function Walkerjs(
callPredefined(instance, false);
} else {
// Reset timing with each new run
instance.config.timing = performance.now();
instance.timing = performance.now();
}

// Session handling
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 @@ -30,6 +30,7 @@ export interface Instance extends State, WalkerOS.Instance {
export interface State extends WalkerOS.State {
config: Config;
destinations: Destinations;
timing: number;
}

export interface Config extends WalkerOS.Config {
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/walkeros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface Config {
custom: Properties;
on: On.Config;
round: number;
timing: number;
tagging: number;
default?: boolean;
verbose?: boolean; // Enable verbose logging
Expand Down

0 comments on commit dbeceba

Please sign in to comment.