@askdialog/dialog-sdk 1.0.15 → 1.0.16

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
@@ -232,4 +232,31 @@ const client = new Dialog({
232
232
  });
233
233
  ```
234
234
 
235
+ ### Tracking
235
236
 
237
+ Our SDK includes a tracking system to monitor user interactions in your purchase flow.
238
+
239
+ #### Automatic Tracking
240
+
241
+ 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.
242
+
243
+ #### Manual Tracking
244
+
245
+ 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:
246
+
247
+ #### Available Methods
248
+
249
+ ```typescript
250
+
251
+ client.registerAddToCartEvent({
252
+ productId: 'ProductIdentifier', // {string} - Required
253
+ quantity: 1, // {number} - Required
254
+ variantId: 'VariantIdentifier' // {string} - Optional
255
+ });
256
+
257
+ client.registerSubmitCheckoutEvent({
258
+ productId: 'ProductIdentifier', // {string} - Required
259
+ quantity: 1, // {number} - Required
260
+ variantId: 'VariantIdentifier' // {string} - Optional
261
+ });
262
+ ```
package/dist/Dialog.d.ts CHANGED
@@ -32,10 +32,14 @@ export declare class Dialog {
32
32
  }): Promise<void>;
33
33
  registerAddToCartEvent({ productId, variantId, quantity, }: {
34
34
  productId: string;
35
- variantId: string;
35
+ variantId?: string;
36
+ quantity: number;
37
+ }): void;
38
+ registerSubmitCheckoutEvent({ productId, variantId, quantity, }: {
39
+ productId: string;
40
+ variantId?: string;
36
41
  quantity: number;
37
42
  }): void;
38
- registerSubmitCheckoutEvent(): void;
39
43
  private _loadAssistant;
40
44
  }
41
45
  //# sourceMappingURL=Dialog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../src/Dialog.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBA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AAI,MAAM,CAE1B;IACD,IAAW,MAAM,IAAI,MAAM,CAE1B;IAEM,2BAA2B,IAAI,kBAAkB,GAAG,IAAI;IAI/D,OAAO,CAAC,uBAAuB;IAkBlB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAK5D,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAKjD,cAAc,IAAI,IAAI;IAItB,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAIxD,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAOxD,UAAU,CACf,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC;IAIhB,SAAS,CAAC,EACrB,SAAS,EACT,QAAQ,EACR,SAAS,GACV,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMV,sBAAsB,CAAC,EAC5B,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI;IAUD,2BAA2B,CAAC,EACjC,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI;IAUR,OAAO,CAAC,cAAc;CA0BvB"}
package/dist/Dialog.js CHANGED
@@ -77,18 +77,28 @@ 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, variantId, }) {
81
+ await this._callbacks.addToCart({ productId, variantId, quantity });
82
+ this.registerAddToCartEvent({ productId, variantId, quantity });
83
+ return;
82
84
  }
83
85
  registerAddToCartEvent({ productId, variantId, quantity, }) {
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,
88
92
  });
89
93
  }
90
- registerSubmitCheckoutEvent() {
91
- this._tracking.track(TrackingEvents.USER_SUBMITTED_CHECKOUT);
94
+ registerSubmitCheckoutEvent({ productId, variantId, quantity, }) {
95
+ this._tracking.track(TrackingEvents.USER_SUBMITTED_CHECKOUT, {
96
+ user_id: this._userId,
97
+ product_id: productId,
98
+ variant_id: variantId,
99
+ quantity,
100
+ locale: this._locale,
101
+ });
92
102
  }
93
103
  _loadAssistant() {
94
104
  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.16",
4
4
  "private": false,
5
5
  "description": "Dialog SDK",
6
6
  "main": "dist/index.js",