@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 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, variantId, quantity, }: {
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
@@ -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,CAchB;IACF,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,O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ACrB,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,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
- return this._callbacks.addToCart({ productId, variantId, quantity });
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, variantId, quantity, }) {
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);
@@ -3,6 +3,7 @@ export declare class Tracking {
3
3
  private _posthog;
4
4
  private readonly _token;
5
5
  private readonly _apiHost;
6
+ private readonly _apiKey;
6
7
  constructor(apiKey: string);
7
8
  track(event: TrackingEvents, properties?: Record<string, unknown>): void;
8
9
  }
@@ -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,CAAqD;IAC5E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;gBAE3C,MAAM,EAAE,MAAM;IASnB,KAAK,CACV,KAAK,EAAE,cAAc,EACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,IAAI;CAGR"}
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 = 'phc_EKMR6Jt4OTMEYmoUlz0v58KPwqcFxI7aZCLckpSD8Tv';
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
- this._posthog.capture(event, properties);
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,6 +1,7 @@
1
1
  export declare const config: {
2
2
  baseApiUrl: string;
3
3
  assistantUrl: string;
4
+ posthogApiKey: string;
4
5
  };
5
6
  export type Config = typeof config;
6
7
  //# sourceMappingURL=config.development.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.development.d.ts","sourceRoot":"","sources":["../../src/config/config.development.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
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,4 +1,5 @@
1
1
  export const config = {
2
2
  baseApiUrl: 'https://abkjr5ukvi.execute-api.eu-west-1.amazonaws.com',
3
3
  assistantUrl: 'https://d2bycosa71tnxv.cloudfront.net/assets/index.js',
4
+ posthogApiKey: 'phc_WM5MRkqG7AiqOKeTmNKj0fNIl41ZOQex7wRhEswRlTA',
4
5
  };
@@ -1,6 +1,7 @@
1
1
  export declare const config: {
2
2
  baseApiUrl: string;
3
3
  assistantUrl: string;
4
+ posthogApiKey: string;
4
5
  };
5
6
  export type Config = typeof config;
6
7
  //# sourceMappingURL=config.production.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.production.d.ts","sourceRoot":"","sources":["../../src/config/config.production.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
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"}
@@ -1,4 +1,5 @@
1
1
  export const config = {
2
2
  baseApiUrl: 'https://rtbzcxkmwj.execute-api.eu-west-1.amazonaws.com',
3
3
  assistantUrl: 'https://d2zm7i5bmzo6ze.cloudfront.net/assets/index.js',
4
+ posthogApiKey: 'phc_EKMR6Jt4OTMEYmoUlz0v58KPwqcFxI7aZCLckpSD8Tv'
4
5
  };
@@ -1,6 +1,7 @@
1
1
  export declare const config: {
2
2
  baseApiUrl: string;
3
3
  assistantUrl: string;
4
+ posthogApiKey: string;
4
5
  };
5
6
  export type Config = typeof config;
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
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"}
@@ -1,4 +1,5 @@
1
1
  export const config = {
2
2
  baseApiUrl: 'https://rtbzcxkmwj.execute-api.eu-west-1.amazonaws.com',
3
3
  assistantUrl: 'https://d2zm7i5bmzo6ze.cloudfront.net/assets/index.js',
4
+ posthogApiKey: 'phc_EKMR6Jt4OTMEYmoUlz0v58KPwqcFxI7aZCLckpSD8Tv'
4
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askdialog/dialog-sdk",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "private": false,
5
5
  "description": "Dialog SDK",
6
6
  "main": "dist/index.js",