Skip to content

Commit

Permalink
v3 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Jun 28, 2024
1 parent 10da730 commit cbbd30d
Show file tree
Hide file tree
Showing 29 changed files with 390 additions and 217 deletions.
2 changes: 0 additions & 2 deletions packages/clients/walkerjs/src/__tests__/destination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ describe('Destination', () => {
});

test('batch', () => {
jest.useFakeTimers();
const mockBatch = jest.fn();

elb('walker run');
Expand All @@ -666,7 +665,6 @@ describe('Destination', () => {
pushBatch: mockBatch,
config: {
mapping: {
// @TODO
product: {
click: { batch: 50 },
visible: { batch: 2000 },
Expand Down
26 changes: 23 additions & 3 deletions packages/clients/walkerjs/src/__tests__/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('Hooks', () => {
let walkerjs: WebClient.Instance;

beforeEach(() => {
jest.useFakeTimers();
global.performance.getEntriesByType = jest
.fn()
.mockReturnValue([{ type: 'navigate' }]);
Expand All @@ -19,9 +18,11 @@ describe('Hooks', () => {
return true;
});
const mockPush = jest.fn();
const mockPushBatch = jest.fn();
const destination: WebDestination.DestinationInit = {
init: mockInit,
push: mockPush,
pushBatch: mockPushBatch,
};

const preDestinationInit = jest
Expand All @@ -38,26 +39,38 @@ describe('Hooks', () => {
.mockImplementation(function (params, ...args) {
return params.fn(...args);
});
const preDestinationPushBatch = jest.fn();
const postDestinationPushBatch = jest
.fn()
.mockImplementation(function (params, ...args) {
return params.fn(...args);
});

walkerjs = Walkerjs({
pageview: false,
session: false,
});

elb('walker destination', destination);
elb('walker destination', destination, {
mapping: { bundle: { me: { batch: 100 } } },
});
elb('walker run');

elb('walker hook', 'preDestinationInit', preDestinationInit);
elb('walker hook', 'postDestinationInit', postDestinationInit);
elb('walker hook', 'preDestinationPush', preDestinationPush);
elb('walker hook', 'postDestinationPush', postDestinationPush);
elb('walker hook', 'preDestinationPushBatch', preDestinationPushBatch);
elb('walker hook', 'postDestinationPushBatch', postDestinationPushBatch);

expect(walkerjs.hooks).toEqual(
expect.objectContaining({
preDestinationInit: expect.any(Function),
postDestinationInit: expect.any(Function),
preDestinationPush: expect.any(Function),
postDestinationPush: expect.any(Function),
preDestinationPushBatch: expect.any(Function),
postDestinationPushBatch: expect.any(Function),
}),
);

Expand All @@ -72,10 +85,17 @@ describe('Hooks', () => {
result: undefined,
},
expect.objectContaining({ event: 'e a' }), // event
{ init: true }, // destination config
{ init: true, mapping: { bundle: { me: { batch: 100 } } } }, // destination config
undefined, // custom event mapping
expect.objectContaining({ allowed: true }), // walkerjs instance
);

elb('bundle me', { on: 'ce' });
elb('bundle me', { tw: 'ice' });
expect(preDestinationPushBatch).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(100);

expect(preDestinationPushBatch).toHaveBeenCalledTimes(1);
});

test('Push', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/clients/walkerjs/src/lib/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ export function pushToDestination(
mappingEvent.batchFn =
mappingEvent.batchFn ||
debounce((destination, instance) => {
useHooks(destination.pushBatch!, 'DestinationPush', instance.hooks)(
batched,
destination.config,
instance,
);
useHooks(
destination.pushBatch!,
'DestinationPushBatch',
instance.hooks,
)(batched, destination.config, instance);

// Reset the batched events queue
batched.events = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/walkerjs/src/types/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Push<Custom, EventCustom> = (
) => void;

export type PushBatch<Custom, EventCustom> = (
events: WalkerOSDestination.Batch<EventCustom>,
batch: WalkerOSDestination.Batch<EventCustom>,
config: Config<Custom, EventCustom>,
instance?: WalkerOS.Instance,
) => void;
Expand Down
2 changes: 2 additions & 0 deletions packages/config/jest/web.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const mockDataLayer = jest.fn(); //.mockImplementation(console.log);

global.beforeEach(() => {
jest.useFakeTimers();

// Mocks
jest.clearAllMocks();
jest.resetModules();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/utils/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './getHash';
export * from './getHashNode';
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/utils/src/web/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './browser';
export * from './elb';
export * from './getAttribute';
export * from './getHash';
export * from './getHashWeb';
export * from './userAgent';
export * from './isVisible';
export * from './session/';
Expand Down
1 change: 0 additions & 1 deletion website/blog/2022-04-30-walker-gtm-ga4/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ dataLayer.push({
price: '29',
quantity: 1,
},
walkerjs: true,
});
```

Expand Down
10 changes: 8 additions & 2 deletions website/docs/clients/node/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ as a value stored in a cookie for a more extended period, and the session can be
used for temporary identification.

```js
elb('walker user', { id: 'us3r', device: 'c00k13', session: 's3ss10n' });
elb('walker user', {
id: 'us3r',
device: 'c00k13',
session: 's3ss10n',
hash: getHash(str),
});
```

The new user IDs have been added to each event. Make sure only to use hashed or
Expand All @@ -98,7 +103,8 @@ anonymous ids.
"user": {
"id": "us3r",
"device": "c00k13",
"hash": "s3ss10n"
"session": "s3ss10n"
"hash": "h4sh3d"
}
// other properties omitted
}
Expand Down
47 changes: 44 additions & 3 deletions website/docs/clients/walkerjs/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ function elb() {
}
```

Usage options

```js
elb("entity action", data, ...);
elb({event: "entity action", data: { foo: "bar"}});
```

## Configuration

To&nbsp;<Link to="/docs/clients/walkerjs/installation/#configuration">configure
Expand Down Expand Up @@ -70,6 +77,13 @@ globals. A `page view` event is triggered by default, the tagging is checked for
elb('walker run');
```

A run accepts a partial `State` parameter to predefine the state of the
walker.js:

```js
elb('walker run', { group: 'gr0up1d' });
```

## Initialization

(Re-)initializes event listeners on one or multiple target elements. Can be used
Expand Down Expand Up @@ -192,7 +206,7 @@ anonymous ids.
"user": {
"id": "us3r",
"device": "c00k13",
"hash": "s3ss10n"
"session": "s3ss10n"
}
// other properties omitted
}
Expand All @@ -214,6 +228,18 @@ officer.

:::

## custom

```js
elb('walker custom', { key: 'value' });
```

## globals

```js
elb('walker globals', { key: 'value' });
```

## Hooks

Hooks can be used to customize the default behavior of the walker.js. Three
Expand All @@ -235,10 +261,15 @@ The overall function execution order is as follows:
1. prePush
2. preDestinationInit
3. postDestinationInit
4. preDestinationPush
5. postDestinationPush
4. preDestinationPush or preDestinationPushBatch
5. postDestinationPush or postDestinationPushBatch
6. postPush

Others are:

- preSessionStart
- postSessionStart

#### Function signatures

In general, `params` will be prefixed as a parameter, containing `fn` which is
Expand Down Expand Up @@ -273,6 +304,16 @@ function postDestinationPush(params) {
// Custom code with a void return
return;
}

// DestinationPushBatch
function preDestinationPushBatch(params, event, config, mapping, runState) {
console.log('default return result', params.result);
return params.fn(event, config, mapping, runState);
}
function postDestinationPushBatch(params) {
// Custom code with a void return
return;
}
```

#### Adding a hook
Expand Down
59 changes: 0 additions & 59 deletions website/docs/clients/walkerjs/debugging.mdx

This file was deleted.

55 changes: 27 additions & 28 deletions website/docs/clients/walkerjs/installation/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,41 @@ There are multiple ways to install and use the web client walker.js:

There a few configuration options when creating a walker.js instance:

| Option | Type | Description |
| --------- | --------------------------- | ------------------------------------------------------- |
| consent | object | Initial consent states, learn more under consent. |
| dataLayer | boolean | Adds a dataLayer destination if enabled. |
| default | boolean | Add a dataLayer destination and run automatically. |
| elb | string | Name of assign the elb function to the window |
| elbLayer | object | Public elbwalker API for async communication. |
| globals | object | Static attributes added to each event. |
| instance | string | Name of the walkerjs instance to assign to the window |
| pageview | boolean | Trigger a page view event by default. |
| prefix | string | Attributes prefix used by the walker. |
| run | boolean | Automatically start running. |
| session | false or<br />SessionConfig | Configuration for session detection. |
| tagging | number | Current version of the tracking setup. |
| user | object | Setting the user ids including id, device, and session. |
| Option | Type | Description |
| --------------- | --------------------------- | ------------------------------------------------------- |
| consent | object | Initial consent states, learn more under consent. |
| dataLayer | boolean | Adds a dataLayer destination if enabled. |
| dataLayerConfig | object | Config for the dataLayer destination, e.g. for consent. |
| default | boolean | Add a dataLayer destination and run automatically. |
| elb | string | Name of assign the elb function to the window |
| elbLayer | object | Public elbwalker API for async communication. |
| globals | object | Static attributes added to each event. |
| instance | string | Name of the walkerjs instance to assign to the window |
| pageview | boolean | Trigger a page view event by default. |
| prefix | string | Attributes prefix used by the walker. |
| run | boolean | Automatically start running. |
| session | false or<br />SessionConfig | Configuration for session detection. |
| tagging | number | Current version of the tracking setup. |
| user | object | Setting the user ids including id, device, and session. |

```ts
const walkerjs = Walkerjs({
consent: {
functional: true,
dataLayer: true, // Add the dataLayer destination
dataLayerConfig: {
consent: 'functional', // Require functional consent
},
dataLayer: true,
elb: 'elb',
elbLayer: window.elbLayer,
elb: 'elb', // Assign the elb function to the window
globals: {
tagged: false,
tagged: false, // A static global attribute
},
instance: 'walkerjs',
pageview: true,
run: true,
pageview: true, // Trigger a page view event with each run
run: true, // Automatically start running
session: {
storage: true,
consent: 'marketing',
length: 60,
storage: true, // Use the storage for session detection
consent: 'marketing', // Require marketing consent to access storage
length: 60, // Session length in minutes
},
tagging: 1,
tagging: 1, // Current version of the tagging
});
```

Expand Down
Loading

0 comments on commit cbbd30d

Please sign in to comment.