@askdialog/dialog-sdk 1.0.15 → 1.0.17
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 +34 -0
- package/dist/Dialog.d.ts +11 -4
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Dialog.js +17 -5
- package/dist/Tracking.d.ts +1 -0
- package/dist/Tracking.d.ts.map +1 -1
- package/dist/Tracking.js +11 -2
- package/dist/config/config.development.d.ts +1 -0
- package/dist/config/config.development.d.ts.map +1 -1
- package/dist/config/config.development.js +1 -0
- package/dist/config/config.production.d.ts +1 -0
- package/dist/config/config.production.d.ts.map +1 -1
- package/dist/config/config.production.js +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,10 +56,12 @@ const client = new Dialog({
|
|
|
56
56
|
addToCart: async ({
|
|
57
57
|
productId,
|
|
58
58
|
quantity,
|
|
59
|
+
currency,
|
|
59
60
|
variantId,
|
|
60
61
|
}: {
|
|
61
62
|
productId: string;
|
|
62
63
|
quantity: number;
|
|
64
|
+
currency: string;
|
|
63
65
|
variantId?: string;
|
|
64
66
|
}) => Promise<void>, // required
|
|
65
67
|
getProduct: async (
|
|
@@ -182,9 +184,11 @@ const client = new Dialog({
|
|
|
182
184
|
productId,
|
|
183
185
|
quantity,
|
|
184
186
|
variantId,
|
|
187
|
+
currency
|
|
185
188
|
}: {
|
|
186
189
|
productId: string;
|
|
187
190
|
quantity: number;
|
|
191
|
+
currency: string;
|
|
188
192
|
variantId?: string;
|
|
189
193
|
}): Promise<void> => {
|
|
190
194
|
// Call your api to trigger addToCart
|
|
@@ -232,4 +236,34 @@ const client = new Dialog({
|
|
|
232
236
|
});
|
|
233
237
|
```
|
|
234
238
|
|
|
239
|
+
### Tracking
|
|
235
240
|
|
|
241
|
+
Our SDK includes a tracking system to monitor user interactions in your purchase flow.
|
|
242
|
+
|
|
243
|
+
#### Automatic Tracking
|
|
244
|
+
|
|
245
|
+
When a user interacts with our assistant and clicks on an "Add to Cart" CTA, it automatically triggers the previously configured `addToCart` callback (see "Client Instantiation" section). These events are tracked internally by our system.
|
|
246
|
+
|
|
247
|
+
#### Manual Tracking
|
|
248
|
+
|
|
249
|
+
However, we cannot automatically detect cart additions or checkout completions that occur **after** using our assistant. To get accurate data in your Dialog dashboards, you should use the following tracking methods:
|
|
250
|
+
|
|
251
|
+
#### Available Methods
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
|
|
255
|
+
client.registerAddToCartEvent({
|
|
256
|
+
productId: 'ProductIdentifier', // {string} - Required
|
|
257
|
+
quantity: 1, // {number} - Required
|
|
258
|
+
currency: 'EUR' // {string} - Required
|
|
259
|
+
variantId: 'VariantIdentifier' // {string} - Optional
|
|
260
|
+
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
client.registerSubmitCheckoutEvent({
|
|
264
|
+
productId: 'ProductIdentifier', // {string} - Required
|
|
265
|
+
quantity: 1, // {number} - Required
|
|
266
|
+
currency: 'EUR' // {string} - Required
|
|
267
|
+
variantId: 'VariantIdentifier' // {string} - Optional
|
|
268
|
+
});
|
|
269
|
+
```
|
package/dist/Dialog.d.ts
CHANGED
|
@@ -25,17 +25,24 @@ export declare class Dialog {
|
|
|
25
25
|
sendProductMessage(params: ProductQuestionPayload): void;
|
|
26
26
|
sendGenericMessage(params: GenericQuestionPayload): void;
|
|
27
27
|
getProduct(productId: string, variantId?: string): Promise<SimplifiedProduct>;
|
|
28
|
-
addToCart({ productId, quantity, variantId, }: {
|
|
28
|
+
addToCart({ productId, quantity, currency, variantId, }: {
|
|
29
29
|
productId: string;
|
|
30
30
|
quantity: number;
|
|
31
|
+
currency: string;
|
|
31
32
|
variantId?: string;
|
|
32
33
|
}): Promise<void>;
|
|
33
|
-
registerAddToCartEvent({ productId,
|
|
34
|
+
registerAddToCartEvent({ productId, quantity, currency, variantId, }: {
|
|
34
35
|
productId: string;
|
|
35
|
-
variantId: string;
|
|
36
36
|
quantity: number;
|
|
37
|
+
currency: string;
|
|
38
|
+
variantId?: string;
|
|
39
|
+
}): void;
|
|
40
|
+
registerSubmitCheckoutEvent({ productId, quantity, currency, variantId, }: {
|
|
41
|
+
productId: string;
|
|
42
|
+
quantity: number;
|
|
43
|
+
currency: string;
|
|
44
|
+
variantId?: string;
|
|
37
45
|
}): void;
|
|
38
|
-
registerSubmitCheckoutEvent(): void;
|
|
39
46
|
private _loadAssistant;
|
|
40
47
|
}
|
|
41
48
|
//# sourceMappingURL=Dialog.d.ts.map
|
package/dist/Dialog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../src/Dialog.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,kBAAkB,EAEnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAEL,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMpD,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../src/Dialog.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,kBAAkB,EAEnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,o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AM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMV,sBAAsB,CAAC,EAC5B,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,GACV,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI;IAWD,2BAA2B,CAAC,EACjC,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,GACV,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI;IAWR,OAAO,CAAC,cAAc;CA0BvB"}
|
package/dist/Dialog.js
CHANGED
|
@@ -77,18 +77,30 @@ export class Dialog {
|
|
|
77
77
|
getProduct(productId, variantId) {
|
|
78
78
|
return this._callbacks.getProduct(productId, variantId);
|
|
79
79
|
}
|
|
80
|
-
addToCart({ productId, quantity, variantId, }) {
|
|
81
|
-
|
|
80
|
+
async addToCart({ productId, quantity, currency, variantId, }) {
|
|
81
|
+
await this._callbacks.addToCart({ productId, variantId, quantity, currency });
|
|
82
|
+
this.registerAddToCartEvent({ productId, variantId, quantity, currency });
|
|
83
|
+
return;
|
|
82
84
|
}
|
|
83
|
-
registerAddToCartEvent({ productId,
|
|
85
|
+
registerAddToCartEvent({ productId, quantity, currency, variantId, }) {
|
|
84
86
|
this._tracking.track(TrackingEvents.USER_ADDED_TO_CART, {
|
|
87
|
+
user_id: this._userId,
|
|
85
88
|
product_id: productId,
|
|
86
89
|
variant_id: variantId,
|
|
87
90
|
quantity,
|
|
91
|
+
locale: this._locale,
|
|
92
|
+
currency,
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
|
-
registerSubmitCheckoutEvent() {
|
|
91
|
-
this._tracking.track(TrackingEvents.USER_SUBMITTED_CHECKOUT
|
|
95
|
+
registerSubmitCheckoutEvent({ productId, quantity, currency, variantId, }) {
|
|
96
|
+
this._tracking.track(TrackingEvents.USER_SUBMITTED_CHECKOUT, {
|
|
97
|
+
user_id: this._userId,
|
|
98
|
+
product_id: productId,
|
|
99
|
+
variant_id: variantId,
|
|
100
|
+
quantity,
|
|
101
|
+
locale: this._locale,
|
|
102
|
+
currency,
|
|
103
|
+
});
|
|
92
104
|
}
|
|
93
105
|
_loadAssistant() {
|
|
94
106
|
const localeInfo = getDetailedLocaleInfo(this._locale);
|
package/dist/Tracking.d.ts
CHANGED
package/dist/Tracking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tracking.d.ts","sourceRoot":"","sources":["../src/Tracking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"Tracking.d.ts","sourceRoot":"","sources":["../src/Tracking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,MAAM;IAUnB,KAAK,CACV,KAAK,EAAE,cAAc,EACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,IAAI;CASR"}
|
package/dist/Tracking.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import posthog from 'posthog-js';
|
|
2
|
+
import { config } from './config';
|
|
2
3
|
export class Tracking {
|
|
3
4
|
_posthog;
|
|
4
|
-
_token =
|
|
5
|
+
_token = config.posthogApiKey;
|
|
5
6
|
_apiHost = 'https://eu.i.posthog.com';
|
|
7
|
+
_apiKey;
|
|
6
8
|
constructor(apiKey) {
|
|
9
|
+
this._apiKey = apiKey;
|
|
7
10
|
this._posthog = posthog.init(this._token, {
|
|
8
11
|
api_host: this._apiHost,
|
|
9
12
|
});
|
|
@@ -12,6 +15,12 @@ export class Tracking {
|
|
|
12
15
|
});
|
|
13
16
|
}
|
|
14
17
|
track(event, properties) {
|
|
15
|
-
|
|
18
|
+
const defaultProperties = {
|
|
19
|
+
$host: window.location.hostname,
|
|
20
|
+
$pathname: window.location.pathname,
|
|
21
|
+
url: window.location.href,
|
|
22
|
+
apiKey: this._apiKey,
|
|
23
|
+
};
|
|
24
|
+
this._posthog.capture(event, { ...defaultProperties, ...properties });
|
|
16
25
|
}
|
|
17
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.development.d.ts","sourceRoot":"","sources":["../../src/config/config.development.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"config.development.d.ts","sourceRoot":"","sources":["../../src/config/config.development.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;CAIlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.production.d.ts","sourceRoot":"","sources":["../../src/config/config.production.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"config.production.d.ts","sourceRoot":"","sources":["../../src/config/config.production.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;CAIlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;CAIlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
|
package/dist/config/index.js
CHANGED