@askdialog/dialog-sdk 2.0.1 → 2.2.0

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
@@ -52,6 +52,7 @@ import { Dialog } from '@dialog/dialog-sdk';
52
52
  const client = new Dialog({
53
53
  apiKey: 'YOUR_API_KEY', // required
54
54
  locale: 'TARGETED_LOCALE', // required
55
+ countryCode: 'FR', // optional, ISO 3166 alpha-2
55
56
  callbacks: {
56
57
  addToCart: async ({
57
58
  productId,
@@ -76,6 +77,13 @@ const client = new Dialog({
76
77
 
77
78
  The apiKey is required to authenticate with our API and interact with our assistant.
78
79
  The locale specifies the language you want to use.
80
+
81
+ The optional `countryCode` (ISO 3166 alpha-2, e.g. `'FR'`, `'US'`) sets the region used to format prices (separators, symbol placement) and the language variant. It does not change the currency itself, which comes from each product. The effective region is resolved in this order:
82
+
83
+ 1. the `countryCode` parameter, when provided;
84
+ 2. the region embedded in `locale` (e.g. `'en-US'` → `US`);
85
+ 3. the region guessed from the language (e.g. `'fr'` → `FR`).
86
+
79
87
  The addToCart function is triggered when a user clicks the AddToCart button.
80
88
  The getProduct function is used to display product information in the assistant.
81
89
 
@@ -330,12 +338,25 @@ client.registerAddToCartEvent({
330
338
  price: '12.00' // {string} - Optional
331
339
  });
332
340
 
341
+ // Checkout is order-level: call ONCE per completed order with the order total.
342
+ // `orderValue` is what the "Revenue generated" dashboard reads.
343
+ // Do NOT call this per line item — without an order total, revenue resolves to 0.
333
344
  client.registerSubmitCheckoutEvent({
334
- productId: 'ProductIdentifier', // {string} - Required
335
- quantity: 1, // {number} - Required
336
- price: '12.00', // {string} - Required
345
+ orderValue: 59.98, // {number} - Required - the order total
337
346
  currency: 'EUR', // {string} - Optional
338
- variantId: 'VariantIdentifier' // {string} - Optional
347
+ transactionId: 'OrderIdentifier', // {string} - Optional - order id, used to de-duplicate reloads
348
+ items: [ // {array} - Optional - line items, for product-level attribution only
349
+ { productId: 'ProductIdentifier', quantity: 1, price: 29.99, variantId: 'VariantIdentifier' },
350
+ ],
351
+ });
352
+
353
+ // Deprecated per-line signature — still accepted for backward compatibility,
354
+ // but carries no order total so revenue cannot be computed. Prefer the call above.
355
+ client.registerSubmitCheckoutEvent({
356
+ productId: 'ProductIdentifier',
357
+ quantity: 1,
358
+ price: '12.00',
359
+ currency: 'EUR',
339
360
  });
340
361
  ```
341
362
 
package/dist/Dialog.d.ts CHANGED
@@ -2,7 +2,7 @@ import { DialogConstructor } from "./types/constructor";
2
2
  import { Theme } from "./types/theme";
3
3
  import { DetailedLocaleInfo } from "./utils/localization";
4
4
  import { Suggestion } from "./types/suggestion";
5
- import { GenericQuestionPayload, OpenAssistantPayload, ProductQuestionPayload } from "./types/events";
5
+ import { GenericQuestionPayload, LegacyCheckoutParams, OpenAssistantPayload, ProductQuestionPayload, SubmitCheckoutParams } from "./types/events";
6
6
  import { SimplifiedProduct } from "./types/product";
7
7
  import { EventsHandler } from "./EventsHandler";
8
8
  import { AssistantEvent } from "./types/assistantEvent";
@@ -10,11 +10,12 @@ export declare class Dialog {
10
10
  static readonly VERSION: string;
11
11
  private _apiKey;
12
12
  private _locale;
13
+ private _countryCode?;
13
14
  private _callbacks;
14
15
  private _theme;
15
16
  private _userId;
16
17
  private _eventsHandler;
17
- constructor({ apiKey, locale, callbacks, theme, userId }: DialogConstructor);
18
+ constructor({ apiKey, locale, countryCode, callbacks, theme, userId, }: DialogConstructor);
18
19
  get apiKey(): string;
19
20
  get theme(): Theme;
20
21
  get userId(): string;
@@ -44,13 +45,7 @@ export declare class Dialog {
44
45
  currency?: string;
45
46
  variantId?: string;
46
47
  }): void;
47
- registerSubmitCheckoutEvent({ productId, quantity, currency, variantId, price, }: {
48
- productId: string;
49
- quantity: number;
50
- price: string;
51
- currency?: string;
52
- variantId?: string;
53
- }): void;
48
+ registerSubmitCheckoutEvent(params: SubmitCheckoutParams | LegacyCheckoutParams): void;
54
49
  private _loadAssistant;
55
50
  }
56
51
  //#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AAC;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,gBAAgB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;IAIjE,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAInD,UAAU,CACf,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC;IAIhB,SAAS,CAAC,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBV,sBAAsB,CAAC,EAC5B,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI;IAkBD,2BAA2B,CAChC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,GAClD,IAAI;IA0BP,OAAO,CAAC,cAAc;CA4BvB"}
package/dist/Dialog.js CHANGED
@@ -12,13 +12,15 @@ export class Dialog {
12
12
  static VERSION = packageJson.version;
13
13
  _apiKey;
14
14
  _locale;
15
+ _countryCode;
15
16
  _callbacks;
16
17
  _theme;
17
18
  _userId;
18
19
  _eventsHandler;
19
- constructor({ apiKey, locale, callbacks, theme, userId }) {
20
+ constructor({ apiKey, locale, countryCode, callbacks, theme, userId, }) {
20
21
  this._apiKey = apiKey;
21
22
  this._locale = locale;
23
+ this._countryCode = countryCode;
22
24
  this._callbacks = callbacks;
23
25
  this._theme = { ...defaultTheme, ...theme };
24
26
  this._userId = this._createOrRetrieveUserId(userId);
@@ -45,7 +47,7 @@ export class Dialog {
45
47
  return this._eventsHandler;
46
48
  }
47
49
  getLocalizationInformations() {
48
- return getDetailedLocaleInfo(this._locale);
50
+ return getDetailedLocaleInfo(this._locale, this._countryCode);
49
51
  }
50
52
  _createOrRetrieveUserId(userId) {
51
53
  if (userId !== undefined) {
@@ -113,25 +115,42 @@ export class Dialog {
113
115
  currency,
114
116
  });
115
117
  }
116
- registerSubmitCheckoutEvent({ productId, quantity, currency, variantId, price, }) {
118
+ // Order-level: call ONCE per completed order with the order total.
119
+ // `orderValue` is what the dashboard's "Revenue generated" reads — do not
120
+ // call this per line item (that has no total and revenue resolves to 0).
121
+ //
122
+ // The legacy per-line signature (`{ productId, quantity, price }`) is still
123
+ // accepted for backward compatibility so existing installs keep working
124
+ // after an upgrade, but it is deprecated: it carries no order total.
125
+ registerSubmitCheckoutEvent(params) {
126
+ if ("orderValue" in params) {
127
+ this._eventsHandler.emitExternalEvent(DialogEvents.TRACK_SUBMIT_CHECKOUT, {
128
+ userId: this._userId,
129
+ orderValue: params.orderValue,
130
+ currency: params.currency,
131
+ transactionId: params.transactionId,
132
+ items: params.items,
133
+ });
134
+ return;
135
+ }
117
136
  this._eventsHandler.emitExternalEvent(DialogEvents.TRACK_SUBMIT_CHECKOUT, {
118
137
  userId: this._userId,
119
- productId,
120
- variantId,
121
- quantity,
122
- price,
123
- currency,
138
+ productId: params.productId,
139
+ variantId: params.variantId,
140
+ quantity: params.quantity,
141
+ price: params.price,
142
+ currency: params.currency,
124
143
  });
125
144
  }
126
145
  _loadAssistant() {
127
- const localeInfo = getDetailedLocaleInfo(this._locale);
146
+ const localeInfo = getDetailedLocaleInfo(this._locale, this._countryCode);
128
147
  if (localeInfo === null) {
129
148
  console.error("Missing locale information");
130
149
  return;
131
150
  }
132
151
  const div = document.createElement("div");
133
152
  div.id = "dialog-shopify-ai";
134
- div.dataset.shopIsoCode = this._locale;
153
+ div.dataset.shopIsoCode = localeInfo.languageCode;
135
154
  div.dataset.apiKey = this._apiKey;
136
155
  div.dataset.userId = this._userId;
137
156
  div.dataset.countryCode = localeInfo.countryCode;
@@ -3,6 +3,12 @@ import { Theme } from "./theme";
3
3
  export interface DialogConstructor {
4
4
  apiKey: string;
5
5
  locale: string;
6
+ /**
7
+ * Optional ISO 3166 country code used to format prices (e.g. 'FR', 'US').
8
+ * When provided it takes precedence over the country derived from `locale`.
9
+ * Omit it to keep deriving the country from the locale (backward compatible).
10
+ */
11
+ countryCode?: string;
6
12
  callbacks: {
7
13
  addToCart: ({ productId, quantity, price, variantId, currency, }: {
8
14
  productId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../src/types/constructor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE;QACT,SAAS,EAAE,CAAC,EACV,SAAS,EACT,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,GACT,EAAE;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,QAAQ,EAAE,MAAM,CAAC;YACjB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;SACnB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACpB,UAAU,EAAE,CACV,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,KACf,OAAO,CAAC,iBAAiB,CAAC,CAAC;KACjC,CAAC;IACF,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../src/types/constructor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE;QACT,SAAS,EAAE,CAAC,EACV,SAAS,EACT,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,GACT,EAAE;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,QAAQ,EAAE,MAAM,CAAC;YACjB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;SACnB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACpB,UAAU,EAAE,CACV,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,KACf,OAAO,CAAC,iBAAiB,CAAC,CAAC;KACjC,CAAC;IACF,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -42,7 +42,38 @@ export interface TrackEventPayload {
42
42
  price?: string;
43
43
  currency?: string;
44
44
  }
45
- export type DialogEventPayload = ProductQuestionPayload | GenericQuestionPayload | DiagnosticPayload | OpenAssistantPayload | TrackEventPayload;
45
+ export interface CheckoutLineItem {
46
+ productId: string;
47
+ variantId?: string;
48
+ quantity: number;
49
+ price?: number;
50
+ }
51
+ export interface SubmitCheckoutEventPayload {
52
+ userId?: string;
53
+ orderValue: number;
54
+ currency?: string;
55
+ transactionId?: string;
56
+ items?: CheckoutLineItem[];
57
+ }
58
+ export interface SubmitCheckoutParams {
59
+ orderValue: number;
60
+ currency?: string;
61
+ transactionId?: string;
62
+ items?: CheckoutLineItem[];
63
+ }
64
+ /**
65
+ * @deprecated Per-line checkout has no order total, so "Revenue generated"
66
+ * resolves to 0. Pass the order total via {@link SubmitCheckoutParams} instead,
67
+ * once per completed order.
68
+ */
69
+ export interface LegacyCheckoutParams {
70
+ productId: string;
71
+ quantity: number;
72
+ price?: string;
73
+ currency?: string;
74
+ variantId?: string;
75
+ }
76
+ export type DialogEventPayload = ProductQuestionPayload | GenericQuestionPayload | DiagnosticPayload | OpenAssistantPayload | TrackEventPayload | SubmitCheckoutEventPayload;
46
77
  export interface DialogEvent<T = DialogEventPayload> {
47
78
  type: DialogEvents;
48
79
  payload: T;
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAEhE,oBAAY,YAAY;IACtB,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,YAAY,qBAAqB;IACjC,qBAAqB,qBAAqB;IAC1C,iBAAiB,sBAAsB;IACvC,qBAAqB,0BAA0B;CAChD;AACD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAA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AM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAGD,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,kBAAkB,GAC1B,sBAAsB,GACtB,sBAAsB,GACtB,iBAAiB,GACjB,oBAAoB,GACpB,iBAAiB,GACjB,0BAA0B,CAAC;AAE/B,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,kBAAkB;IACjD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,CAAC,CAAC;CACZ"}
@@ -1,8 +1,23 @@
1
1
  export interface DetailedLocaleInfo {
2
2
  language: string;
3
+ languageCode: string;
3
4
  countryCode: string;
4
5
  formatted: string;
5
6
  locale: string;
6
7
  }
7
- export declare const getDetailedLocaleInfo: (locale: string) => DetailedLocaleInfo | null;
8
+ export declare const isValidCountryCode: (countryCode: string | undefined) => countryCode is string;
9
+ /**
10
+ * Resolves the detailed locale information used by the assistant.
11
+ *
12
+ * The effective region follows this precedence:
13
+ * 1. `countryCodeOverride` (explicit SDK parameter),
14
+ * 2. the region embedded in `locale` (e.g. `en-US` -> `US`),
15
+ * 3. the region guessed from the language via `Intl.Locale.maximize()`.
16
+ *
17
+ * The override (1) and the locale region (2) are considered "explicit" and also
18
+ * drive the language display name (e.g. `en-GB` -> "British English"). The
19
+ * `maximize()` fallback (3) only feeds the country code: a bare language code
20
+ * therefore keeps a generic language name ("French", not "French (France)").
21
+ */
22
+ export declare const getDetailedLocaleInfo: (locale: string, countryCodeOverride?: string) => DetailedLocaleInfo | null;
8
23
  //# sourceMappingURL=localization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/utils/localization.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,KACb,kBAAkB,GAAG,IAsBvB,CAAC"}
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/utils/localization.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,GAAG,SAAS,KAC9B,WAAW,IAAI,MAC8C,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,EACd,sBAAsB,MAAM,KAC3B,kBAAkB,GAAG,IAoCvB,CAAC"}
@@ -1,15 +1,40 @@
1
- export const getDetailedLocaleInfo = (locale) => {
1
+ export const isValidCountryCode = (countryCode) => countryCode !== undefined && /^[A-Za-z]{2}$/.test(countryCode);
2
+ /**
3
+ * Resolves the detailed locale information used by the assistant.
4
+ *
5
+ * The effective region follows this precedence:
6
+ * 1. `countryCodeOverride` (explicit SDK parameter),
7
+ * 2. the region embedded in `locale` (e.g. `en-US` -> `US`),
8
+ * 3. the region guessed from the language via `Intl.Locale.maximize()`.
9
+ *
10
+ * The override (1) and the locale region (2) are considered "explicit" and also
11
+ * drive the language display name (e.g. `en-GB` -> "British English"). The
12
+ * `maximize()` fallback (3) only feeds the country code: a bare language code
13
+ * therefore keeps a generic language name ("French", not "French (France)").
14
+ */
15
+ export const getDetailedLocaleInfo = (locale, countryCodeOverride) => {
2
16
  try {
3
17
  const localeObj = new Intl.Locale(locale);
4
18
  const language = localeObj.language;
5
- const countryCode = localeObj.region ?? localeObj.maximize().region;
19
+ const overrideRegion = isValidCountryCode(countryCodeOverride)
20
+ ? countryCodeOverride.toUpperCase()
21
+ : undefined;
22
+ const explicitRegion = overrideRegion ?? localeObj.region;
23
+ const countryCode = explicitRegion ?? localeObj.maximize().region;
24
+ if (countryCode === undefined) {
25
+ return null;
26
+ }
27
+ const baseNameForLanguage = explicitRegion !== undefined
28
+ ? `${language}-${explicitRegion}`
29
+ : localeObj.baseName;
6
30
  const languageNames = new Intl.DisplayNames(["en"], { type: "language" });
7
- const languageName = languageNames.of(localeObj.baseName);
8
- if (languageName === undefined || countryCode === undefined) {
31
+ const languageName = languageNames.of(baseNameForLanguage);
32
+ if (languageName === undefined) {
9
33
  return null;
10
34
  }
11
35
  return {
12
36
  language: languageName,
37
+ languageCode: language,
13
38
  countryCode,
14
39
  formatted: `${language}-${countryCode}`,
15
40
  locale,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askdialog/dialog-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "private": false,
5
5
  "description": "Dialog SDK",
6
6
  "main": "dist/index.js",