Skip to content

Commit

Permalink
Back-merge main into development
Browse files Browse the repository at this point in the history
  • Loading branch information
expatfile-bot committed Nov 14, 2023
2 parents 68c3ccb + 101b403 commit 581b631
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
node-version: [18]
node-version: [20]

steps:
- name: Checkout
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![GitHub branch checks state][build-url] [![codecov][cov-img]][cov-url] [![Known Vulnerabilities][snyk-img]][snyk-url]

# Zaraz
# Zaraz TS

A type-safe wrapper around the Cloudflare Zaraz Web API.

Expand All @@ -14,22 +14,22 @@ A type-safe wrapper around the Cloudflare Zaraz Web API.
Import zaraz and call the desired method. That's it!

```ts
import { zaraz } from 'zaraz';
import { zaraz } from 'zaraz-ts';

// Track custom events on your website, that might happen in real time.
await zaraz.track("button clicked", { userId: "ABC-123", value: 200 })
```

```ts
import { zaraz } from 'zaraz';
import { zaraz } from 'zaraz-ts';

// Make a variable available in all your events without manually setting it
// every time you are using zaraz.track().
zaraz.set('user_id', '123456');
```

```ts
import { zaraz } from 'zaraz';
import { zaraz } from 'zaraz-ts';

// Track common events of the e-commerce user journey, such as when a user adds
// a product to cart, starts the checkout funnel or completes an order.
Expand Down Expand Up @@ -65,6 +65,8 @@ await zaraz.ecommerce('Order Completed', {
});
```

Checkout the official Cloudflare docs for more details: https://developers.cloudflare.com/zaraz/web-api/.

### Maintenance 👷

This package is maintained and actively used by [Expatfile.tax][expatfile-site].
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zaraz",
"name": "zaraz-ts",
"version": "0.0.0-development",
"description": "Zaraz - A type-safe wrapper around the Cloudflare Zaraz Web API.",
"description": "Zaraz TS - A type-safe wrapper around the Cloudflare Zaraz Web API.",
"main": "build/index.js",
"scripts": {
"lint": "eslint ./src",
Expand All @@ -15,20 +15,22 @@
"semantic-release": "semantic-release"
},
"keywords": [
"zaraz-ts",
"zaraz",
"type-safe",
"cloudflare",
"typescript"
],
"author": "Expatfile.tax LLC",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/expatfile/zaraz.git"
"url": "https://github.com/expatfile/zaraz-ts.git"
},
"bugs": {
"url": "https://github.com/expatfile/zaraz/issues"
"url": "https://github.com/expatfile/zaraz-ts/issues"
},
"homepage": "https://github.com/expatfile/zaraz#readme",
"homepage": "https://github.com/expatfile/zaraz-ts#readme",
"dependencies": {},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.4",
Expand Down
36 changes: 36 additions & 0 deletions src/ecommerce.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ecommerce } from './ecommerce';

const trackMock = jest.fn();
const setMock = jest.fn();
const ecommerceMock = jest.fn();

declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
zaraz: any;
}
}

let windowObj: Window & typeof globalThis;

beforeAll(() => {
windowObj = window;
});

afterAll(() => {
window = windowObj;
});

describe('ecommerce()', () => {
it('should call zaraz ecommerce when called', () => {
window.zaraz = {
track: trackMock,
set: setMock,
ecommerce: ecommerceMock,
};

ecommerce('Cart Viewed');

expect(ecommerceMock).toHaveBeenCalledWith('Cart Viewed', undefined);
});
});
36 changes: 36 additions & 0 deletions src/set.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { set } from './set';

const trackMock = jest.fn();
const setMock = jest.fn();
const ecommerceMock = jest.fn();

declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
zaraz: any;
}
}

let windowObj: Window & typeof globalThis;

beforeAll(() => {
windowObj = window;
});

afterAll(() => {
window = windowObj;
});

describe('set()', () => {
it('should call zaraz set when called', () => {
window.zaraz = {
track: trackMock,
set: setMock,
ecommerce: ecommerceMock,
};

set('user_id', '123456');

expect(setMock).toHaveBeenCalledWith('user_id', '123456', undefined);
});
});
39 changes: 39 additions & 0 deletions src/track.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { track } from './track';

const trackMock = jest.fn();
const setMock = jest.fn();
const ecommerceMock = jest.fn();

declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
zaraz: any;
}
}

let windowObj: Window & typeof globalThis;

beforeAll(() => {
windowObj = window;
});

afterAll(() => {
window = windowObj;
});

describe('track()', () => {
it('should call zaraz track when called', () => {
window.zaraz = {
track: trackMock,
set: setMock,
ecommerce: ecommerceMock,
};

track('button clicked', { userId: 'ABC-123', value: 200 });

expect(trackMock).toHaveBeenCalledWith('button clicked', {
userId: 'ABC-123',
value: 200,
});
});
});

0 comments on commit 581b631

Please sign in to comment.