@bilyai/js 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ <!-- markdownlint-disable MD033 -->
2
+ <p align="center">
3
+ <svg width="96" height="54" fill="none" xmlns="http://www.w3.org/2000/svg"><g opacity=".99" fill-rule="evenodd" clip-rule="evenodd" fill="#000"><path d="M10.81 16.206l2.22 1.643L16 9.187l-5.19 7.02zm0 0l-2.221-1.64 7.41-5.379-5.189 7.02z"/><path d="M21.187 16.206l-2.22 1.643-2.969-8.662 5.19 7.02zm0 0l2.222-1.64L16 9.187l5.189 7.02zm1.697-13.039l-6.886 6.02 9.081-.997 6.918-5.988h.001l-9.114.965z"/><path d="M9.114 3.167L16 9.187 6.919 8.19v-.001L0 2.202l9.115.964z"/></g></svg>
4
+ </p>
5
+ <!-- markdownlint-enable MD033 -->
6
+
7
+ # Official Bily SDK for Browser
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@bilyai/js.svg)](https://www.npmjs.com/package/@bilyai/js)
10
+ [![npm dm](https://img.shields.io/npm/dm/@bilyai/js.svg)](https://www.npmjs.com/package/@bilyai/js)
11
+ [![npm dt](https://img.shields.io/npm/dt/@bilyai/js.svg)](https://www.npmjs.com/package/@bilyai/js)
12
+
13
+ Don't already have an account and store added ? Head over to [Bily](https://app.bily.ai), then return to this page.
14
+
15
+ # ☕ Install package
16
+
17
+ ```shell Npm
18
+ npm install @bilyai/js
19
+ ```
20
+
21
+ ```shell Yarn
22
+ yarn add @bilyai/js
23
+ ```
24
+
25
+ # 🚦 Configurations
26
+
27
+ Configuration should happen as early as possible in your application's lifecycle.
28
+
29
+ ```javascript Init Bily
30
+ import { init } from '@bilyai/js';
31
+
32
+ init('https://b.magnetor.net');
33
+ ```
34
+
35
+ Once implemented, Bily's JavaScript SDK will automatically track all pageviews. You can now begin tracking all other
36
+ events as well.
37
+
38
+ # 🚀 Start tracking events
39
+
40
+ ```javascript Product Viewed
41
+ import { track } from '@bilyai/js';
42
+
43
+ track('Product Viewed', {
44
+ client: {
45
+ firstname: 'John',
46
+ lastname: 'Doe',
47
+ // ... other attributes here
48
+ },
49
+ products: [
50
+ {
51
+ id: '123',
52
+ name: 'Product 1',
53
+ price: 100,
54
+ quantity: 1,
55
+ currency: 'USD',
56
+ sku: '123',
57
+ category: 'Category 1',
58
+ brand: 'Brand 1',
59
+ },
60
+ ],
61
+ // ...other attributes here
62
+ });
63
+ ```
64
+
65
+ ```javascript Add to cart
66
+ import { track } from '@bilyai/js';
67
+
68
+ track('Product Added', {
69
+ client: {
70
+ firstname: 'John',
71
+ lastname: 'Doe',
72
+ // ... other attributes here
73
+ },
74
+ products: [
75
+ {
76
+ id: '123',
77
+ name: 'Product 1',
78
+ price: 100,
79
+ quantity: 1,
80
+ currency: 'USD',
81
+ sku: '123',
82
+ category: 'Category 1',
83
+ brand: 'Brand 1',
84
+ },
85
+ ],
86
+ // ...other attributes here
87
+ });
88
+ ```
89
+
90
+ ```javascript Checkout Started
91
+ import { track } from '@bilyai/js';
92
+
93
+ track('Checkout Started', {
94
+ client: {
95
+ firstname: 'John',
96
+ lastname: 'Doe',
97
+ email: 'john@doe.com',
98
+ // ... other attributes here
99
+ },
100
+ products: [
101
+ {
102
+ id: '123',
103
+ name: 'Product 1',
104
+ price: 100,
105
+ quantity: 1,
106
+ currency: 'USD',
107
+ sku: '123',
108
+ category: 'Category 1',
109
+ brand: 'Brand 1',
110
+ },
111
+ ],
112
+ // ...other attributes here
113
+ });
114
+ ```
115
+
116
+ ```javascript Order Completed
117
+ import { track } from '@bilyai/js';
118
+
119
+ track('Order Completed', {
120
+ client: {
121
+ firstname: 'John',
122
+ lastname: 'Doe',
123
+ email: 'john@doe.com',
124
+ phone: '1234567890',
125
+ gender: 'male',
126
+ dateOfBirth: '1990-01-01',
127
+ address: {
128
+ city: 'New York',
129
+ state: 'NY',
130
+ country: 'US',
131
+ zip: '10002',
132
+ },
133
+ // ... other attributes here
134
+ },
135
+ order: {
136
+ id: '123',
137
+ currency: 'USD',
138
+ total: 100,
139
+ products: [
140
+ {
141
+ id: '123',
142
+ name: 'Product 1',
143
+ price: 100,
144
+ quantity: 1,
145
+ currency: 'USD',
146
+ sku: '123',
147
+ category: 'Category 1',
148
+ brand: 'Brand 1',
149
+ },
150
+ ],
151
+ },
152
+ // ...other attributes here
153
+ });
154
+ ```
155
+
156
+ If you get stuck, [shoot us an email](mailto:support@bily.ai) or use the Intercom widget on the bottom right of any
157
+ page.
158
+
159
+ We're excited you're here! :blue-heart:
160
+
161
+ ![This won't be fun to clean up...](https://owlbert.io/images/popper.gif)
package/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { BilyEvent, BilyPayload } from '@bilyai/types';
2
+ declare global {
3
+ interface Window {
4
+ zaraz: any;
5
+ bily: any;
6
+ bilyConfig: any;
7
+ }
8
+ }
9
+ declare const init: (domainTracking: string, config?: {
10
+ verbose: boolean;
11
+ }) => void;
12
+ declare const track: (event: BilyEvent, payload: BilyPayload) => void;
13
+ export { init, track };
package/lib/index.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.track = exports.init = void 0;
4
+ const core_1 = require("@bilyai/core");
5
+ const types_1 = require("@bilyai/types");
6
+ const initBilyClient = () => {
7
+ window.bily = window.zaraz;
8
+ };
9
+ const init = (domainTracking, config) => {
10
+ if (document.querySelector('script[id="bily-tracking-script"]')) {
11
+ return;
12
+ }
13
+ if (config) {
14
+ window.bilyConfig = config;
15
+ }
16
+ if (config === null || config === void 0 ? void 0 : config.verbose) {
17
+ console.info('bily', 'init', domainTracking, config);
18
+ }
19
+ const trackingUrl = (0, core_1.getTrackingScriptTagUrl)(domainTracking);
20
+ const script = document.createElement('script');
21
+ script.id = 'bily-tracking-script';
22
+ script.src = trackingUrl;
23
+ document.body.appendChild(script);
24
+ script.onload = () => {
25
+ initBilyClient();
26
+ const bilyId = (0, core_1.generateExternalId)();
27
+ window.bily.set(types_1.BILY_EXTERNAL_ID_KEY, bilyId);
28
+ localStorage.setItem(types_1.BILY_EXTERNAL_ID_KEY, bilyId);
29
+ };
30
+ };
31
+ exports.init = init;
32
+ const track = (event, payload) => {
33
+ var _a, _b;
34
+ if (window === null || window === void 0 ? void 0 : window.bily) {
35
+ const bilyId = localStorage.getItem(types_1.BILY_EXTERNAL_ID_KEY) || window.bily.get(types_1.BILY_EXTERNAL_ID_KEY) || (0, core_1.generateExternalId)();
36
+ window.bily.set(types_1.BILY_EXTERNAL_ID_KEY, bilyId);
37
+ localStorage.setItem(types_1.BILY_EXTERNAL_ID_KEY, bilyId);
38
+ const data = (0, core_1.mapPayload)(payload, bilyId);
39
+ data.source = 'web';
40
+ const eventName = (0, core_1.getEventName)(event);
41
+ const ecommerce = (0, core_1.isEcommerceEvent)(event);
42
+ if (ecommerce) {
43
+ window.bily.ecommerce(eventName, data);
44
+ }
45
+ else {
46
+ window.bily.track(eventName, data);
47
+ }
48
+ if ((_a = window === null || window === void 0 ? void 0 : window.bilyConfig) === null || _a === void 0 ? void 0 : _a.verbose) {
49
+ console.info('bily', 'event tracked', event, data);
50
+ }
51
+ }
52
+ else {
53
+ if (document.querySelector('script[id="bily-tracking-script"]')) {
54
+ setTimeout(() => {
55
+ track(event, payload);
56
+ }, 1000);
57
+ }
58
+ else {
59
+ if ((_b = window === null || window === void 0 ? void 0 : window.bilyConfig) === null || _b === void 0 ? void 0 : _b.verbose) {
60
+ console.warn('bily', 'module not loaded');
61
+ }
62
+ }
63
+ }
64
+ };
65
+ exports.track = track;
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAuH;AACvH,yCAA6E;AAU7E,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;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AAC,CAAC;AAEa,sBAAK"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@bilyai/js",
3
+ "private": false,
4
+ "version": "1.0.21",
5
+ "description": "> TODO: description",
6
+ "author": "Babacar NIANG <babacar.basse.niang@gmail.com>",
7
+ "homepage": "https://github.com/usepixl/bily-javascript#readme",
8
+ "license": "ISC",
9
+ "main": "lib/index.js",
10
+ "typings": "lib/index.d.ts",
11
+ "directories": {
12
+ "lib": "lib",
13
+ "test": "__tests__"
14
+ },
15
+ "files": [
16
+ "lib"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/usepixl/bily-javascript.git"
21
+ },
22
+ "scripts": {
23
+ "tsc": "tsc",
24
+ "test": "node ./__tests__/browser.test.js"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/usepixl/bily-javascript/issues"
28
+ },
29
+ "gitHead": "061b539a20665e723b1de074ff2c9063910ccb83",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "@bilyai/core": "^1.0.21",
35
+ "@bilyai/types": "^1.0.21"
36
+ }
37
+ }