@braze/web-sdk 4.9.0 → 5.0.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.
Files changed (111) hide show
  1. package/index.d.ts +2204 -2230
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +1 -1
  4. package/shared-lib/event-types.js +9 -9
  5. package/shared-lib/indexed-db-adapter.js +13 -13
  6. package/shared-lib/logger.js +2 -2
  7. package/shared-lib/supported-options.js +8 -8
  8. package/src/Card/models/captioned-image.js +19 -19
  9. package/src/Card/models/card.js +95 -94
  10. package/src/Card/models/classic-card.js +19 -19
  11. package/src/Card/models/control-card.js +9 -9
  12. package/src/Card/models/image-only.js +21 -22
  13. package/src/Card/models/index.js +0 -1
  14. package/src/Card/util/card-factory.js +39 -39
  15. package/src/ContentCards/content-cards-provider.js +114 -114
  16. package/src/ContentCards/get-cached-content-cards.js +1 -1
  17. package/src/ContentCards/index.js +0 -1
  18. package/src/ContentCards/request-content-cards-refresh.js +1 -1
  19. package/src/ContentCards/subscribe-to-content-cards-updates.js +3 -3
  20. package/src/ContentCards/ui/hide-content-cards.js +2 -2
  21. package/src/ContentCards/ui/show-content-cards.js +14 -14
  22. package/src/Core/add-sdk-metadata.js +2 -2
  23. package/src/Core/change-user.js +2 -2
  24. package/src/Core/disable-sdk.js +4 -4
  25. package/src/Core/enable-sdk.js +4 -4
  26. package/src/Core/get-device-id.js +9 -7
  27. package/src/Core/handle-braze-action.js +14 -14
  28. package/src/Core/is-disabled.js +2 -2
  29. package/src/Core/open-session.js +5 -5
  30. package/src/Core/set-sdk-authentication-signature.js +2 -2
  31. package/src/Core/wipe-data.js +4 -4
  32. package/src/FeatureFlags/feature-flag-factory.js +10 -10
  33. package/src/FeatureFlags/feature-flag.js +7 -7
  34. package/src/FeatureFlags/feature-flags-provider.js +50 -50
  35. package/src/FeatureFlags/get-all-feature-flags.js +1 -1
  36. package/src/FeatureFlags/get-feature-flag.js +3 -5
  37. package/src/Feed/feed-provider-factory.js +8 -8
  38. package/src/Feed/feed-provider.js +15 -15
  39. package/src/Feed/get-cached-feed.js +2 -2
  40. package/src/Feed/request-feed-refresh.js +2 -2
  41. package/src/Feed/subscribe-to-feed-updates.js +2 -2
  42. package/src/Feed/ui/hide-feed.js +2 -2
  43. package/src/Feed/ui/show-feed.js +13 -13
  44. package/src/InAppMessage/display/html-message-to-html.js +11 -12
  45. package/src/InAppMessage/display/in-app-message-to-html.js +15 -15
  46. package/src/InAppMessage/display/modal-utils.js +8 -8
  47. package/src/InAppMessage/in-app-message-factory.js +4 -4
  48. package/src/InAppMessage/in-app-message-manager.js +38 -38
  49. package/src/InAppMessage/models/full-screen-message.js +31 -31
  50. package/src/InAppMessage/models/html-message.js +16 -16
  51. package/src/InAppMessage/models/in-app-message-button.js +5 -5
  52. package/src/InAppMessage/models/in-app-message.js +46 -46
  53. package/src/InAppMessage/models/modal-message.js +30 -30
  54. package/src/InAppMessage/models/slide-up-message.js +26 -26
  55. package/src/InAppMessage/ui/show-in-app-message.js +9 -9
  56. package/src/Push/is-push-blocked.js +2 -2
  57. package/src/Push/is-push-permission-granted.js +2 -2
  58. package/src/Push/is-push-supported.js +2 -2
  59. package/src/Push/push-manager.js +31 -31
  60. package/src/Push/utils/push-utils.js +9 -9
  61. package/src/User/user-manager.js +8 -8
  62. package/src/User/user.js +38 -37
  63. package/src/common/base-feed.js +15 -14
  64. package/src/common/base-provider.js +1 -1
  65. package/src/common/event-logger.js +2 -2
  66. package/src/common/feed-display.js +32 -32
  67. package/src/l10n/l10n-manager-factory.js +9 -9
  68. package/src/managers/auth-manager.js +6 -6
  69. package/src/managers/braze-instance.js +84 -92
  70. package/src/managers/device-manager.js +9 -9
  71. package/src/managers/network-manager.js +72 -69
  72. package/src/managers/server-config-manager.js +13 -13
  73. package/src/managers/session-manager.js +9 -9
  74. package/src/managers/storage-manager-factory.js +11 -11
  75. package/src/managers/storage-manager.js +110 -110
  76. package/src/managers/subscription-manager.js +3 -3
  77. package/src/models/backend-errors.js +5 -5
  78. package/src/models/braze-event.js +7 -7
  79. package/src/models/identifier.js +1 -1
  80. package/src/models/push-token.js +1 -1
  81. package/src/models/server-config.js +6 -6
  82. package/src/request-controller.js +129 -125
  83. package/src/triggers/models/custom-event-data.js +1 -1
  84. package/src/triggers/models/custom-event-property-data.js +6 -6
  85. package/src/triggers/models/filter-set.js +8 -8
  86. package/src/triggers/models/filter.js +31 -31
  87. package/src/triggers/models/in-app-message-click-data.js +1 -1
  88. package/src/triggers/models/purchase-data.js +1 -1
  89. package/src/triggers/models/purchase-property-data.js +4 -4
  90. package/src/triggers/models/push-click-data.js +3 -3
  91. package/src/triggers/models/trigger-condition.js +30 -30
  92. package/src/triggers/models/trigger-events.js +1 -1
  93. package/src/triggers/models/trigger.js +32 -32
  94. package/src/triggers/triggers-provider.js +55 -55
  95. package/src/ui/js/attach-css.js +1 -1
  96. package/src/ui/js/feed-css.js +5 -5
  97. package/src/ui/js/iam-css.js +4 -4
  98. package/src/ui/js/load-font-awesome.js +1 -1
  99. package/src/util/braze-actions.js +4 -4
  100. package/src/util/browser-detector.js +11 -11
  101. package/src/util/client-hints-parser.js +5 -5
  102. package/src/util/component-utils.js +2 -2
  103. package/src/util/date-utils.js +2 -2
  104. package/src/util/device-constants.js +4 -5
  105. package/src/util/dom-utils.js +5 -5
  106. package/src/util/net.js +1 -1
  107. package/src/util/request-header-utils.js +17 -17
  108. package/src/util/user-agent-parser.js +11 -16
  109. package/src/util/validation-utils.js +9 -9
  110. package/src/Card/models/banner.js +0 -31
  111. package/src/ContentCards/log-content-cards-displayed.js +0 -5
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Type definitions for @braze/web-sdk v4.9.0
2
+ * Type definitions for @braze/web-sdk v5.0.0
3
3
  * Project: https://github.com/braze-inc/braze-web-sdk
4
4
  * (c) Braze, Inc. 2023 - http://braze.com
5
5
  * License available at https://github.com/braze-inc/braze-web-sdk/blob/master/LICENSE
@@ -7,2534 +7,2508 @@
7
7
 
8
8
  /* eslint-disable no-unused-vars, no-use-before-define */
9
9
 
10
- /**
11
- * Enum to represent the accepted SDK Metadata tags. See `addSdkMetadata` for more info.
12
- *
13
- * @readonly
14
- * @enum {string}
15
- */
16
- export class BrazeSdkMetadata {
17
- /** Automatically added when loading Braze via Google Tag Manager */
18
- static readonly GOOGLE_TAG_MANAGER: string;
19
- /** Automatically added when loading Braze via mParticle */
20
- static readonly MPARTICLE: string;
21
- /** Automatically added when loading Braze via Segment */
22
- static readonly SEGMENT: string;
23
- /** Automatically added when loading Braze via Tealium */
24
- static readonly TEALIUM: string;
25
- /** Automatically added when loading Braze via npm */
26
- static readonly NPM: string;
27
- /** Automatically added when loading Braze via Braze's CDN (js.appboycdn.com) */
28
- static readonly CDN: string;
29
- /** Automatically added when loading Braze via Shopify Integration */
30
- static readonly SHOPIFY: string;
31
- /** Use this tag if you have integrated or loaded the Braze Web SDK using none of the other methods */
32
- static readonly MANUAL: string;
33
- }
34
-
35
- /**
10
+ /**
11
+ * Enum to represent the accepted SDK Metadata tags. See `addSdkMetadata` for more info.
12
+ *
13
+ * @readonly
14
+ * @enum {string}
15
+ */
16
+ export class BrazeSdkMetadata {
17
+ /** Automatically added when loading Braze via Google Tag Manager */
18
+ static readonly GOOGLE_TAG_MANAGER: string;
19
+ /** Automatically added when loading Braze via mParticle */
20
+ static readonly MPARTICLE: string;
21
+ /** Automatically added when loading Braze via Segment */
22
+ static readonly SEGMENT: string;
23
+ /** Automatically added when loading Braze via Tealium */
24
+ static readonly TEALIUM: string;
25
+ /** Automatically added when loading Braze via npm */
26
+ static readonly NPM: string;
27
+ /** Automatically added when loading Braze via Braze's CDN (js.appboycdn.com) */
28
+ static readonly CDN: string;
29
+ /** Automatically added when loading Braze via Shopify Integration */
30
+ static readonly SHOPIFY: string;
31
+ /** Use this tag if you have integrated or loaded the Braze Web SDK using none of the other methods */
32
+ static readonly MANUAL: string;
33
+ }
34
+
35
+ /**
36
36
  * Enum to represent the allowlistable set of device properties. By default, all properties are collected.
37
37
  * See the `devicePropertyAllowlist` option of `initialize` for more info.
38
38
 
39
39
  * @readonly
40
40
  * @enum {string}
41
41
  */
42
- export class DeviceProperties {
43
- /** The name of the browser - e.g. "Chrome" */
44
- static readonly BROWSER: string;
45
- /** The version of the browser - e.g. "59.234.1234" */
46
- static readonly BROWSER_VERSION: string;
47
- /** The name of the operating system - e.g. "Android" */
48
- static readonly OS: string;
49
- /** The screen resolution of the device - e.g. "1024x768" */
50
- static readonly RESOLUTION: string;
51
- /** The language the browser is set to use - e.g. "en-us" */
52
- static readonly LANGUAGE: string;
53
- /** The time zone of the device - e.g. "America/New_York" */
54
- static readonly TIME_ZONE: string;
55
- /** The user agent string of the browser - see [this link](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) for more info */
56
- static readonly USER_AGENT: string;
57
- }
58
-
59
- /**
60
- * Abstract base for news feed and Content Cards cards. Use subclasses `ClassicCard`, `CaptionedImage`,
61
- * `ImageOnly`, and `ControlCard`.
62
- */
63
- export class Card {
64
- /**
65
- * Call this method if you wish to programmatically remove the card from the feed and log a dismissal. This method
66
- * is meant to be used with the Braze UI.
67
- *
68
- * If you are using your own UI, this method will have no effect. Instead, you should use `logCardDismissal` to
69
- * log analytics and then remove the card from the DOM manually.
70
- */
71
- dismissCard(): void;
72
-
73
- /** Remove all event subscriptions from this message. */
74
- removeAllSubscriptions(): void;
75
-
76
- /**
77
- * Remove an event subscription that you previously subscribed to.
78
- *
79
- * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
80
- * you initially used to create it.
81
- */
82
- removeSubscription(subscriptionGuid: string): void;
83
-
84
- /**
85
- * Subscribe to receive click events. The subscriber callback will be called whenever this card is clicked by the
86
- * user.
87
- *
88
- * @param subscriber - The callback function to receive click events. This function will be invoked with
89
- * no arguments when this card records a click.
90
- *
91
- * @returns The identifier of the subscription created. This can be passed to `Card.removeSubscription`
92
- * to cancel the subscription. Returns null if the subscriber passed is not a function.
93
- */
94
- subscribeToClickedEvent(subscriber: () => void): string | null;
95
-
96
- /**
97
- * Subscribe to receive dismissed events. The subscriber callback will be called whenever this card is dismissed by the
98
- * user.
99
- *
100
- * @param subscriber - The callback function to receive dismissed events. This function will be invoked with
101
- * no arguments when this card records a dismissal.
102
- *
103
- * @returns The identifier of the subscription created. This can be passed to `Card.removeSubscription`
104
- * to cancel the subscription. Returns null if the subscriber passed is not a function.
105
- */
106
- subscribeToDismissedEvent(subscriber: () => void): string | null;
107
-
108
- /** The id of the card. This will be reported back to Braze with events for analytics purposes. */
109
- id?: string;
110
-
111
- /** Whether this card has been shown to the user. */
112
- viewed: boolean;
113
-
114
- /** When this card was last modified. */
115
- updated: Date | null;
116
-
117
- /** When this card expires and should stop being shown to the user. */
118
- expiresAt: Date | null;
119
-
120
- /** Object of string/string key/value pairs. Defaults to empty object {}. */
121
- extras: Record<string, string>;
122
-
123
- /** Whether to pin this card to the top of the view. */
124
- pinned: boolean;
125
-
126
- /** Whether this card is a ControlCard. */
127
- isControl: boolean;
128
-
129
-
130
- }
42
+ export class DeviceProperties {
43
+ /** The name of the browser - e.g. "Chrome" */
44
+ static readonly BROWSER: string;
45
+ /** The version of the browser - e.g. "59.234.1234" */
46
+ static readonly BROWSER_VERSION: string;
47
+ /** The name of the operating system - e.g. "Android" */
48
+ static readonly OS: string;
49
+ /** The screen resolution of the device - e.g. "1024x768" */
50
+ static readonly RESOLUTION: string;
51
+ /** The language the browser is set to use - e.g. "en-us" */
52
+ static readonly LANGUAGE: string;
53
+ /** The time zone of the device - e.g. "America/New_York" */
54
+ static readonly TIME_ZONE: string;
55
+ /** The user agent string of the browser - see [this link](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) for more info */
56
+ static readonly USER_AGENT: string;
57
+ }
58
+
59
+ /**
60
+ * Abstract base for news feed and Content Cards cards. Use subclasses `ClassicCard`, `CaptionedImage`,
61
+ * `ImageOnly`, and `ControlCard`.
62
+ */
63
+ export class Card {
64
+ /**
65
+ * Call this method if you wish to programmatically remove the card from the feed and log a dismissal. This method
66
+ * is meant to be used with the Braze UI.
67
+ *
68
+ * If you are using your own UI, this method will have no effect. Instead, you should use `logCardDismissal` to
69
+ * log analytics and then remove the card from the DOM manually.
70
+ */
71
+ dismissCard(): void;
72
+
73
+ /** Remove all event subscriptions from this message. */
74
+ removeAllSubscriptions(): void;
131
75
 
132
76
  /**
133
- * @deprecated This class has been deprecated in favor of `ImageOnly`.
77
+ * Remove an event subscription that you previously subscribed to.
78
+ *
79
+ * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
80
+ * you initially used to create it.
134
81
  */
135
- export class Banner extends Card {
136
- /**
137
- * A card with only an image, which can be passed to `showFeed` or handled manually.
138
- * Subscribe to receive new cards via `subscribeToFeedUpdates`
139
- *
140
- * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
141
- * @param viewed - Whether this card has been shown to the user.
142
- * @param imageUrl - The url for this card's image.
143
- * @param created - When this card was created.
144
- * @param updated - When this card was last modified.
145
- * @param categories - Purely for organization in your custom implementation, these categories can be set in
146
- * the dashboard composer.
147
- * @param expiresAt - When this card expires and should stop being shown to the user.
148
- * @param url - A url to open when this card is clicked.
149
- * @param linkText - The display text for the url.
150
- * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
151
- * image loading completes. Note that the field may not be supplied in certain circumstances.
152
- * @param extras - Object of string/string key/value pairs.
153
- * @param pinned - Whether to pin this card to the top of the view.
154
- * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
155
- * @param clicked - Whether this card has ever been clicked on this device.
156
- */
157
- constructor(
158
- id?: string,
159
- viewed?: boolean,
160
- imageUrl?: string,
161
- created?: Date,
162
- updated?: Date,
163
- categories?: string[],
164
- expiresAt?: Date,
165
- url?: string,
166
- linkText?: string,
167
- aspectRatio?: number,
168
- extras?: Record<string, string>,
169
- pinned?: boolean,
170
- dismissible?: boolean,
171
- clicked?: boolean
172
- );
173
-
174
- /** The url for this card's image. */
175
- imageUrl?: string;
176
-
177
- /** When this card was created. */
178
- created: Date | null;
179
-
180
- /**
181
- * Purely for organization in your custom implementation, these categories can be set in
182
- * the dashboard composer.
183
- */
184
- categories: string[];
185
-
186
- /** A url to open when this card is clicked. */
187
- url?: string;
188
-
189
- /** The display text for the url. */
190
- linkText?: string;
191
-
192
- /**
193
- * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
194
- * Note that the field may not be supplied in certain circumstances.
195
- * */
196
- aspectRatio: number | null;
197
-
198
- /** Whether this card has been dismissed. */
199
- dismissed: boolean;
200
-
201
- /** Whether to allow the user to dismiss this card, removing it from the view. */
202
- dismissible: boolean;
203
-
204
- /** Whether this card has ever been clicked on this device. */
205
- clicked: boolean;
206
- }
207
-
208
- export class ImageOnly extends Card {
209
- /**
210
- * A card with only an image, which can be passed to `showFeed` or handled manually.
211
- * Subscribe to receive new cards via `subscribeToFeedUpdates`
212
- *
213
- * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
214
- * @param viewed - Whether this card has been shown to the user.
215
- * @param imageUrl - The url for this card's image.
216
- * @param created - When this card was created.
217
- * @param updated - When this card was last modified.
218
- * @param categories - Purely for organization in your custom implementation, these categories can be set in
219
- * the dashboard composer.
220
- * @param expiresAt - When this card expires and should stop being shown to the user.
221
- * @param url - A url to open when this card is clicked.
222
- * @param linkText - The display text for the url.
223
- * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
224
- * image loading completes. Note that the field may not be supplied in certain circumstances.
225
- * @param extras - Object of string/string key/value pairs.
226
- * @param pinned - Whether to pin this card to the top of the view.
227
- * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
228
- * @param clicked - Whether this card has ever been clicked on this device.
229
- */
230
- constructor(
231
- id?: string,
232
- viewed?: boolean,
233
- imageUrl?: string,
234
- created?: Date,
235
- updated?: Date,
236
- categories?: string[],
237
- expiresAt?: Date,
238
- url?: string,
239
- linkText?: string,
240
- aspectRatio?: number,
241
- extras?: Record<string, string>,
242
- pinned?: boolean,
243
- dismissible?: boolean,
244
- clicked?: boolean
245
- );
246
-
247
- /** The url for this card's image. */
248
- imageUrl?: string;
249
-
250
- /** When this card was created. */
251
- created: Date | null;
252
-
253
- /**
254
- * Purely for organization in your custom implementation, these categories can be set in
255
- * the dashboard composer.
256
- */
257
- categories: string[];
258
-
259
- /** A url to open when this card is clicked. */
260
- url?: string;
261
-
262
- /** The display text for the url. */
263
- linkText?: string;
264
-
265
- /**
266
- * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
267
- * Note that the field may not be supplied in certain circumstances.
268
- * */
269
- aspectRatio: number | null;
270
-
271
- /** Whether this card has been dismissed. */
272
- dismissed: boolean;
273
-
274
- /** Whether to allow the user to dismiss this card, removing it from the view. */
275
- dismissible: boolean;
276
-
277
- /** Whether this card has ever been clicked on this device. */
278
- clicked: boolean;
279
- }
280
-
281
- export class CaptionedImage extends Card {
282
- /**
283
- * A card with a large image and descriptive text, which can be passed to `showFeed` or handled manually.
284
- * Subscribe to receive new cards via `subscribeToFeedUpdates`.
285
- *
286
- * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
287
- * @param viewed - Whether this card has been shown to the user.
288
- * @param title - The title text for this card.
289
- * @param imageUrl - The url for this card's image.
290
- * @param description - The body text for this card.
291
- * @param created - When this card was created.
292
- * @param updated - When this card was last modified.
293
- * @param categories - Purely for organization in your custom implementation, these categories can be set in
294
- * the dashboard composer.
295
- * @param expiresAt - When this card expires and should stop being shown to the user.
296
- * @param url - A url to open when this card is clicked.
297
- * @param linkText - The display text for the url.
298
- * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
299
- * image loading completes. Note that the field may not be supplied in certain circumstances.
300
- * @param extras - Object of string/string key/value pairs.
301
- * @param pinned - Whether to pin this card to the top of the view.
302
- * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
303
- * @param clicked - Whether this card has ever been clicked on this device.
304
- */
305
- constructor(
306
- id?: string,
307
- viewed?: boolean,
308
- title?: string,
309
- imageUrl?: string,
310
- description?: string,
311
- created?: Date,
312
- updated?: Date,
313
- categories?: string[],
314
- expiresAt?: Date,
315
- url?: string,
316
- linkText?: string,
317
- aspectRatio?: number,
318
- extras?: Record<string, string>,
319
- pinned?: boolean,
320
- dismissible?: boolean,
321
- clicked?: boolean
322
- );
323
-
324
- /** The title text for this card. */
325
- title: string;
326
-
327
- /** The url for this card's image. */
328
- imageUrl?: string;
329
-
330
- /** The body text for this card. */
331
- description: string;
332
-
333
- /** When this card was created. */
334
- created: Date | null;
335
-
336
- /**
337
- * Purely for organization in your custom implementation, these categories can be set in
338
- * the dashboard composer.
339
- */
340
- categories: string[];
341
-
342
- /** A url to open when this card is clicked. */
343
- url?: string;
82
+ removeSubscription(subscriptionGuid: string): void;
344
83
 
345
- /** The display text for the url. */
346
- linkText?: string;
347
-
348
- /**
349
- * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
350
- * Note that the field may not be supplied in certain circumstances.
351
- */
352
- aspectRatio: number | null;
353
-
354
- /** Whether this card has been dismissed. */
355
- dismissed: boolean;
356
-
357
- /** Whether to allow the user to dismiss this card, removing it from the view. */
358
- dismissible: boolean;
359
-
360
- /** Whether this card has ever been clicked on this device. */
361
- clicked: boolean;
362
- }
363
-
364
- export class ClassicCard extends Card {
365
- /**
366
- * A card with a title, body, and optionally a small image, which can be passed to
367
- * `showFeed` or handled manually.
368
- * Subscribe to receive new cards via `subscribeToFeedUpdates`.
369
- *
370
- * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
371
- * @param viewed - Whether this card has been shown to the user.
372
- * @param title - The title text for this card.
373
- * @param imageUrl - The url for this card's image.
374
- * @param description - The body text for this card.
375
- * @param created - When this card was created.
376
- * @param updated - When this card was last modified.
377
- * @param categories - Purely for organization in your custom implementation, these categories can be set in
378
- * the dashboard composer.
379
- * @param expiresAt - When this card expires and should stop being shown to the user.
380
- * @param url - A url to open when this card is clicked.
381
- * @param linkText - The display text for the url.
382
- * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
383
- * image loading completes. Note that the field may not be supplied in certain circumstances.
384
- * @param extras - Object of string/string key/value pairs.
385
- * @param pinned - Whether to pin this card to the top of the view.
386
- * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
387
- * @param clicked - Whether this card has ever been clicked on this device.
388
- */
389
- constructor(
390
- id?: string,
391
- viewed?: boolean,
392
- title?: string,
393
- imageUrl?: string,
394
- description?: string,
395
- created?: Date,
396
- updated?: Date,
397
- categories?: string[],
398
- expiresAt?: Date,
399
- url?: string,
400
- linkText?: string,
401
- aspectRatio?: number,
402
- extras?: Record<string, string>,
403
- pinned?: boolean,
404
- dismissible?: boolean,
405
- clicked?: boolean
406
- );
407
-
408
- /** The title text for this card. */
409
- title: string;
410
-
411
- /** The url for this card's image. */
412
- imageUrl?: string;
413
-
414
- /** The body text for this card. */
415
- description: string;
416
-
417
- /** When this card was created. */
418
- created: Date | null;
419
-
420
- /**
421
- * Purely for organization in your custom implementation, these categories can be set in
422
- * the dashboard composer.
423
- */
424
- categories: string[];
425
-
426
- /** A url to open when this card is clicked. */
427
- url?: string;
428
-
429
- /** The display text for the url. */
430
- linkText?: string;
431
-
432
- /**
433
- * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
434
- * Note that the field may not be supplied in certain circumstances.
435
- */
436
- aspectRatio: number | null;
437
-
438
- /** Whether this card has been dismissed. */
439
- dismissed: boolean;
440
-
441
- /** Whether to allow the user to dismiss this card, removing it from the view. */
442
- dismissible: boolean;
443
-
444
- /** Whether this card has ever been clicked on this device. */
445
- clicked: boolean;
446
- }
84
+ /**
85
+ * Subscribe to receive click events. The subscriber callback will be called whenever this card is clicked by the
86
+ * user.
87
+ *
88
+ * @param subscriber - The callback function to receive click events. This function will be invoked with
89
+ * no arguments when this card records a click.
90
+ *
91
+ * @returns The identifier of the subscription created. This can be passed to `Card.removeSubscription`
92
+ * to cancel the subscription. Returns null if the subscriber passed is not a function.
93
+ */
94
+ subscribeToClickedEvent(subscriber: () => void): string | null;
447
95
 
448
- export class ControlCard extends Card {
449
- /**
450
- * A card with no display that logs impressions, which can be passed to
451
- * `showFeed` or handled manually.
452
- * Not supported in legacy news feed.
453
- * Subscribe to receive new cards via `subscribeToFeedUpdates`.
454
- *
455
- * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
456
- * @param viewed - Whether this card has been shown to the user.
457
- * @param updated - When this card was last modified.
458
- * @param expiresAt - When this card expires and should stop being shown to the user.
459
- * @param extras - Object of string/string key/value pairs.
460
- * @param pinned - Whether to pin this card to the top of the view.
461
- */
462
- constructor(
463
- id?: string,
464
- viewed?: boolean,
465
- updated?: Date,
466
- expiresAt?: Date,
467
- extras?: Record<string, string>,
468
- pinned?: boolean
469
- );
470
-
471
- /** Whether this card is a ControlCard. */
472
- isControl: true;
473
- }
474
-
475
- export class ContentCards {
476
- /**
477
- * A collection of `Card` descendents (`ClassicCard`, `CaptionedImage`, `Banner`).
478
- * If you use Braze's UI to render content cards, you generally shouldn't need to
479
- * interact with this class, but if you are building your own content cards class manually, use
480
- * `getCachedContentCards` to get the most recent ContentCards object.
481
- *
482
- * @param cards - Array of `Card` descendents (`ClassicCard`, `CaptionedImage`, `Banner`).
483
- * @param lastUpdated - When this collection of cards was received from Braze servers. If null, it means the
484
- * content cards are still being fetched for this user.
485
- */
486
- constructor(cards: Card[], lastUpdated: Date | null);
96
+ /**
97
+ * Subscribe to receive dismissed events. The subscriber callback will be called whenever this card is dismissed by the
98
+ * user.
99
+ *
100
+ * @param subscriber - The callback function to receive dismissed events. This function will be invoked with
101
+ * no arguments when this card records a dismissal.
102
+ *
103
+ * @returns The identifier of the subscription created. This can be passed to `Card.removeSubscription`
104
+ * to cancel the subscription. Returns null if the subscriber passed is not a function.
105
+ */
106
+ subscribeToDismissedEvent(subscriber: () => void): string | null;
487
107
 
488
- /** Array of `Card` descendents (`ClassicCard`, `CaptionedImage`, `Banner`). */
489
- cards: Card[];
108
+ /** The id of the card. This will be reported back to Braze with events for analytics purposes. */
109
+ id?: string;
490
110
 
491
- /**
492
- * When this collection of cards was received from Braze servers. If null, it means the
493
- * content cards are still being fetched for this user.
494
- */
495
- lastUpdated: Date | null;
111
+ /** Whether this card has been shown to the user. */
112
+ viewed: boolean;
496
113
 
497
- /**
498
- * Get the current unviewed card count. This is useful for powering badges on your control for showing the content cards.
499
- * `ControlCard` cards do not count towards the unviewed count.
500
- */
501
- getUnviewedCardCount(): number;
502
- }
114
+ /** When this card was last modified. */
115
+ updated: Date | null;
503
116
 
504
- export class Feed {
505
- /**
506
- * A collection of `Card` descendents (`ClassicCard`, `CaptionedImage`, `Banner`).
507
- * Subscribe to receive feed updates via `subscribeToFeedUpdates`,
508
- * or get the currently cached feed with `getCachedFeed`.
509
- *
510
- * @param cards - Array of `Card` descendents (`ClassicCard`, `CaptionedImage`,
511
- * `Banner`). Can be passed directly to `showFeed`.
512
- * @param lastUpdated - When this collection of cards was received from Braze servers. If null, it means the
513
- * feed has never been fetched for this user.
514
- */
515
- constructor(cards: Card[], lastUpdated: Date | null);
117
+ /** When this card expires and should stop being shown to the user. */
118
+ expiresAt: Date | null;
516
119
 
517
- /**
518
- * Array of `Card` descendents (`ClassicCard`, `CaptionedImage`, `Banner`).
519
- * Can be passed directly to `showFeed`.
520
- */
521
- cards: Card[];
120
+ /** Object of string/string key/value pairs. Defaults to empty object {}. */
121
+ extras: Record<string, string>;
522
122
 
523
- /**
524
- * When this collection of cards was received from Braze servers. If null, it means the
525
- * content cards are still being fetched for this user.
526
- */
527
- lastUpdated: Date | null;
123
+ /** Whether to pin this card to the top of the view. */
124
+ pinned: boolean;
528
125
 
529
- /**
530
- * Get the current unread card count. This is useful for powering badges on your control for showing the news feed.
531
- * Note that Braze will not refresh news feed cards on new page loads (and so this function will return 0) until you
532
- * call `showFeed` or `requestFeedRefresh`. `ControlCard` cards do not count towards the
533
- * unread count.
534
- */
535
- getUnreadCardCount(): number;
536
- }
126
+ /** Whether this card is a ControlCard. */
127
+ isControl: boolean;
537
128
 
538
- export class ControlMessage {
539
- /**
540
- * A non-showing message placeholder that represents this user receiving the the control for a multivariate
541
- * test. Can be passed to `showInAppMessage` to log the user's
542
- * entrollment in the control or handled manually.
543
- *
544
- * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
545
- * Braze with in-app message analytics events.
546
- */
547
- constructor(triggerId?: string);
548
129
 
549
- /**
550
- * The id of the trigger that created this message. The SDK will report back this to
551
- * Braze with in-app message analytics events.
552
- */
553
- triggerId?: string;
130
+ }
554
131
 
555
- /** Object of string/string key/value pairs. */
556
- extras: Record<string, string>;
132
+ export class ImageOnly extends Card {
133
+ /**
134
+ * A card with only an image, which can be passed to `showFeed` or handled manually.
135
+ * Subscribe to receive new cards via `subscribeToFeedUpdates`
136
+ *
137
+ * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
138
+ * @param viewed - Whether this card has been shown to the user.
139
+ * @param imageUrl - The url for this card's image.
140
+ * @param created - When this card was created.
141
+ * @param updated - When this card was last modified.
142
+ * @param categories - Purely for organization in your custom implementation, these categories can be set in
143
+ * the dashboard composer.
144
+ * @param expiresAt - When this card expires and should stop being shown to the user.
145
+ * @param url - A url to open when this card is clicked.
146
+ * @param linkText - The display text for the url.
147
+ * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
148
+ * image loading completes. Note that the field may not be supplied in certain circumstances.
149
+ * @param extras - Object of string/string key/value pairs.
150
+ * @param pinned - Whether to pin this card to the top of the view.
151
+ * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
152
+ * @param clicked - Whether this card has ever been clicked on this device.
153
+ */
154
+ constructor(
155
+ id?: string,
156
+ viewed?: boolean,
157
+ imageUrl?: string,
158
+ created?: Date,
159
+ updated?: Date,
160
+ categories?: string[],
161
+ expiresAt?: Date,
162
+ url?: string,
163
+ linkText?: string,
164
+ aspectRatio?: number,
165
+ extras?: Record<string, string>,
166
+ pinned?: boolean,
167
+ dismissible?: boolean,
168
+ clicked?: boolean,
169
+ );
557
170
 
558
- /** Whether this message is a ControlMessage. */
559
- isControl: true;
560
- }
171
+ /** The url for this card's image. */
172
+ imageUrl?: string;
561
173
 
562
-
563
- type SlideFrom = typeof InAppMessage.SlideFrom[keyof typeof InAppMessage.SlideFrom];
174
+ /** When this card was created. */
175
+ created: Date | null;
564
176
 
565
-
566
- type ClickAction = typeof InAppMessage.ClickAction[keyof typeof InAppMessage.ClickAction];
177
+ /**
178
+ * Purely for organization in your custom implementation, these categories can be set in
179
+ * the dashboard composer.
180
+ */
181
+ categories: string[];
567
182
 
568
-
569
- type DismissType = typeof InAppMessage.DismissType[keyof typeof InAppMessage.DismissType];
183
+ /** A url to open when this card is clicked. */
184
+ url?: string;
570
185
 
571
-
572
- type OpenTarget = typeof InAppMessage.OpenTarget[keyof typeof InAppMessage.OpenTarget];
186
+ /** The display text for the url. */
187
+ linkText?: string;
573
188
 
574
-
575
- type ImageStyle = typeof InAppMessage.ImageStyle[keyof typeof InAppMessage.ImageStyle];
189
+ /**
190
+ * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
191
+ * Note that the field may not be supplied in certain circumstances.
192
+ * */
193
+ aspectRatio: number | null;
576
194
 
577
-
578
- type Orientation = typeof InAppMessage.Orientation[keyof typeof InAppMessage.Orientation];
195
+ /** Whether this card has been dismissed. */
196
+ dismissed: boolean;
579
197
 
580
-
581
- type TextAlignment = typeof InAppMessage.TextAlignment[keyof typeof InAppMessage.TextAlignment];
198
+ /** Whether to allow the user to dismiss this card, removing it from the view. */
199
+ dismissible: boolean;
200
+
201
+ /** Whether this card has ever been clicked on this device. */
202
+ clicked: boolean;
203
+ }
204
+
205
+ export class CaptionedImage extends Card {
206
+ /**
207
+ * A card with a large image and descriptive text, which can be passed to `showFeed` or handled manually.
208
+ * Subscribe to receive new cards via `subscribeToFeedUpdates`.
209
+ *
210
+ * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
211
+ * @param viewed - Whether this card has been shown to the user.
212
+ * @param title - The title text for this card.
213
+ * @param imageUrl - The url for this card's image.
214
+ * @param description - The body text for this card.
215
+ * @param created - When this card was created.
216
+ * @param updated - When this card was last modified.
217
+ * @param categories - Purely for organization in your custom implementation, these categories can be set in
218
+ * the dashboard composer.
219
+ * @param expiresAt - When this card expires and should stop being shown to the user.
220
+ * @param url - A url to open when this card is clicked.
221
+ * @param linkText - The display text for the url.
222
+ * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
223
+ * image loading completes. Note that the field may not be supplied in certain circumstances.
224
+ * @param extras - Object of string/string key/value pairs.
225
+ * @param pinned - Whether to pin this card to the top of the view.
226
+ * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
227
+ * @param clicked - Whether this card has ever been clicked on this device.
228
+ */
229
+ constructor(
230
+ id?: string,
231
+ viewed?: boolean,
232
+ title?: string,
233
+ imageUrl?: string,
234
+ description?: string,
235
+ created?: Date,
236
+ updated?: Date,
237
+ categories?: string[],
238
+ expiresAt?: Date,
239
+ url?: string,
240
+ linkText?: string,
241
+ aspectRatio?: number,
242
+ extras?: Record<string, string>,
243
+ pinned?: boolean,
244
+ dismissible?: boolean,
245
+ clicked?: boolean,
246
+ );
247
+
248
+ /** The title text for this card. */
249
+ title: string;
250
+
251
+ /** The url for this card's image. */
252
+ imageUrl?: string;
253
+
254
+ /** The body text for this card. */
255
+ description: string;
256
+
257
+ /** When this card was created. */
258
+ created: Date | null;
259
+
260
+ /**
261
+ * Purely for organization in your custom implementation, these categories can be set in
262
+ * the dashboard composer.
263
+ */
264
+ categories: string[];
265
+
266
+ /** A url to open when this card is clicked. */
267
+ url?: string;
582
268
 
583
-
584
- type CropType = typeof InAppMessage.CropType[keyof typeof InAppMessage.CropType];
269
+ /** The display text for the url. */
270
+ linkText?: string;
585
271
 
586
272
  /**
587
- * Abstract base for in-app messages. Use subclasses `SlideUpMessage`,
588
- * `ModalMessage`, `FullScreenMessage`, and `HtmlMessage`.
273
+ * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
274
+ * Note that the field may not be supplied in certain circumstances.
589
275
  */
590
- export class InAppMessage {
591
- static SlideFrom: {
592
- TOP: "TOP";
593
- BOTTOM: "BOTTOM";
594
- };
276
+ aspectRatio: number | null;
277
+
278
+ /** Whether this card has been dismissed. */
279
+ dismissed: boolean;
280
+
281
+ /** Whether to allow the user to dismiss this card, removing it from the view. */
282
+ dismissible: boolean;
283
+
284
+ /** Whether this card has ever been clicked on this device. */
285
+ clicked: boolean;
286
+ }
287
+
288
+ export class ClassicCard extends Card {
289
+ /**
290
+ * A card with a title, body, and optionally a small image, which can be passed to
291
+ * `showFeed` or handled manually.
292
+ * Subscribe to receive new cards via `subscribeToFeedUpdates`.
293
+ *
294
+ * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
295
+ * @param viewed - Whether this card has been shown to the user.
296
+ * @param title - The title text for this card.
297
+ * @param imageUrl - The url for this card's image.
298
+ * @param description - The body text for this card.
299
+ * @param created - When this card was created.
300
+ * @param updated - When this card was last modified.
301
+ * @param categories - Purely for organization in your custom implementation, these categories can be set in
302
+ * the dashboard composer.
303
+ * @param expiresAt - When this card expires and should stop being shown to the user.
304
+ * @param url - A url to open when this card is clicked.
305
+ * @param linkText - The display text for the url.
306
+ * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
307
+ * image loading completes. Note that the field may not be supplied in certain circumstances.
308
+ * @param extras - Object of string/string key/value pairs.
309
+ * @param pinned - Whether to pin this card to the top of the view.
310
+ * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
311
+ * @param clicked - Whether this card has ever been clicked on this device.
312
+ */
313
+ constructor(
314
+ id?: string,
315
+ viewed?: boolean,
316
+ title?: string,
317
+ imageUrl?: string,
318
+ description?: string,
319
+ created?: Date,
320
+ updated?: Date,
321
+ categories?: string[],
322
+ expiresAt?: Date,
323
+ url?: string,
324
+ linkText?: string,
325
+ aspectRatio?: number,
326
+ extras?: Record<string, string>,
327
+ pinned?: boolean,
328
+ dismissible?: boolean,
329
+ clicked?: boolean,
330
+ );
595
331
 
596
- static ClickAction: {
597
- NEWS_FEED: "NEWS_FEED";
598
- URI: "URI";
599
- NONE: "NONE";
600
- };
332
+ /** The title text for this card. */
333
+ title: string;
601
334
 
602
- static DismissType: {
603
- AUTO_DISMISS: "AUTO_DISMISS";
604
- MANUAL: "SWIPE";
605
- };
335
+ /** The url for this card's image. */
336
+ imageUrl?: string;
606
337
 
607
- static OpenTarget: {
608
- NONE: "NONE";
609
- BLANK: "BLANK";
610
- };
338
+ /** The body text for this card. */
339
+ description: string;
611
340
 
612
- static ImageStyle: {
613
- TOP: "TOP";
614
- GRAPHIC: "GRAPHIC";
615
- };
341
+ /** When this card was created. */
342
+ created: Date | null;
616
343
 
617
- static Orientation: {
618
- PORTRAIT: "PORTRAIT";
619
- LANDSCAPE: "LANDSCAPE";
620
- };
621
-
622
- static TextAlignment: {
623
- START: "START";
624
- CENTER: "CENTER";
625
- END: "END";
626
- };
344
+ /**
345
+ * Purely for organization in your custom implementation, these categories can be set in
346
+ * the dashboard composer.
347
+ */
348
+ categories: string[];
627
349
 
628
- static CropType: {
629
- /**
630
- * Centers the image in the available space and crops any overflowing edges.
631
- */
632
- CENTER_CROP: "CENTER_CROP";
350
+ /** A url to open when this card is clicked. */
351
+ url?: string;
633
352
 
634
- /**
635
- * Fits the image within the available space, causing blank space on the shorter
636
- * axis (e.g. tall images will have bars of blank space on the left/right)
637
- */
638
- FIT_CENTER: "FIT_CENTER";
639
- };
353
+ /** The display text for the url. */
354
+ linkText?: string;
640
355
 
641
- /** The message to display to the user. */
642
- message?: string;
356
+ /**
357
+ * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
358
+ * Note that the field may not be supplied in certain circumstances.
359
+ */
360
+ aspectRatio: number | null;
643
361
 
644
- /** Object of string/string key/value pairs. */
645
- extras: Record<string, string>;
362
+ /** Whether this card has been dismissed. */
363
+ dismissed: boolean;
646
364
 
647
- /**
648
- * The id of the trigger that created this message. The SDK will report back this to
649
- * Braze with in-app message analytics events.
650
- */
651
- triggerId?: string;
365
+ /** Whether to allow the user to dismiss this card, removing it from the view. */
366
+ dismissible: boolean;
652
367
 
653
- /**
654
- * How the message is dismissed, via a timer or requiring interaction from the user.
655
- * See the `DismissType` enum.
656
- */
657
- dismissType: DismissType;
368
+ /** Whether this card has ever been clicked on this device. */
369
+ clicked: boolean;
370
+ }
658
371
 
659
- /**
660
- * Length of time in milliseconds until auto-dismiss should occur. Only used when
661
- * dismissType is `DismissType`.AUTO_DISMISS
662
- */
663
- duration: number;
372
+ export class ControlCard extends Card {
373
+ /**
374
+ * A card with no display that logs impressions, which can be passed to
375
+ * `showFeed` or handled manually.
376
+ * Not supported in legacy news feed.
377
+ * Subscribe to receive new cards via `subscribeToFeedUpdates`.
378
+ *
379
+ * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
380
+ * @param viewed - Whether this card has been shown to the user.
381
+ * @param updated - When this card was last modified.
382
+ * @param expiresAt - When this card expires and should stop being shown to the user.
383
+ * @param extras - Object of string/string key/value pairs.
384
+ * @param pinned - Whether to pin this card to the top of the view.
385
+ */
386
+ constructor(
387
+ id?: string,
388
+ viewed?: boolean,
389
+ updated?: Date,
390
+ expiresAt?: Date,
391
+ extras?: Record<string, string>,
392
+ pinned?: boolean,
393
+ );
664
394
 
665
- /** Whether to animate the showing of this message. */
666
- animateIn: boolean;
395
+ /** Whether this card is a ControlCard. */
396
+ isControl: true;
397
+ }
667
398
 
668
- /** Whether to animate the hiding of this message. */
669
- animateOut: boolean;
399
+ export class ContentCards {
400
+ /**
401
+ * A collection of `Card` descendents (`ClassicCard`, `CaptionedImage`, `ImageOnly`).
402
+ * If you use Braze's UI to render content cards, you generally shouldn't need to
403
+ * interact with this class, but if you are building your own content cards class manually, use
404
+ * `getCachedContentCards` to get the most recent ContentCards object.
405
+ *
406
+ * @param cards - Array of `Card` descendents (`ClassicCard`, `CaptionedImage`, `ImageOnly`).
407
+ * @param lastUpdated - When this collection of cards was received from Braze servers. If null, it means the
408
+ * content cards are still being fetched for this user.
409
+ */
410
+ constructor(cards: Card[], lastUpdated: Date | null);
670
411
 
671
- /** The ID to give the parent HTML element that this message is rendered into. */
672
- htmlId?: string;
412
+ /** Array of `Card` descendents (`ClassicCard`, `CaptionedImage`, `ImageOnly`). */
413
+ cards: Card[];
673
414
 
674
- /**
675
- * Custom CSS to apply to the page while this element is shown. All selectors should be scoped
676
- * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
677
- */
678
- css?: string;
415
+ /**
416
+ * When this collection of cards was received from Braze servers. If null, it means the
417
+ * content cards are still being fetched for this user.
418
+ */
419
+ lastUpdated: Date | null;
679
420
 
680
- /** Whether this message is a ControlMessage. */
681
- isControl: false;
421
+ /**
422
+ * Get the current unviewed card count. This is useful for powering badges on your control for showing the content cards.
423
+ * `ControlCard` cards do not count towards the unviewed count.
424
+ */
425
+ getUnviewedCardCount(): number;
426
+ }
682
427
 
683
- /**
684
- * Call this method if you wish to programmatically remove the message from the DOM. This method will only
685
- * work with the Braze UI.
686
- */
687
- closeMessage(): void;
428
+ export class Feed {
429
+ /**
430
+ * A collection of `Card` descendents (`ClassicCard`, `CaptionedImage`, `ImageOnly`).
431
+ * Subscribe to receive feed updates via `subscribeToFeedUpdates`,
432
+ * or get the currently cached feed with `getCachedFeed`.
433
+ *
434
+ * @param cards - Array of `Card` descendents (`ClassicCard`, `CaptionedImage`,
435
+ * `ImageOnly`). Can be passed directly to `showFeed`.
436
+ * @param lastUpdated - When this collection of cards was received from Braze servers. If null, it means the
437
+ * feed has never been fetched for this user.
438
+ */
439
+ constructor(cards: Card[], lastUpdated: Date | null);
688
440
 
689
- /** Remove all event subscriptions from this message. */
690
- removeAllSubscriptions(): void;
441
+ /**
442
+ * Array of `Card` descendents (`ClassicCard`, `CaptionedImage`, `ImageOnly`).
443
+ * Can be passed directly to `showFeed`.
444
+ */
445
+ cards: Card[];
691
446
 
692
- /**
693
- * Remove an event subscription that you previously subscribed to.
694
- *
695
- * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
696
- * you initially used to create it.
697
- */
698
- removeSubscription(subscriptionGuid: string): void;
447
+ /**
448
+ * When this collection of cards was received from Braze servers. If null, it means the
449
+ * content cards are still being fetched for this user.
450
+ */
451
+ lastUpdated: Date | null;
699
452
 
700
- /**
701
- * Subscribe to receive click events. The subscriber callback will be called whenever this message is clicked by the
702
- * user.
703
- *
704
- * @param subscriber - The callback function to receive click events. This function will be invoked with
705
- * no arguments when this message records a click.
706
- *
707
- * @returns The identifier of the subscription created. This can be passed to `removeSubscription`
708
- * to cancel the subscription. Returns null if the subscriber passed is not a function.
709
- */
710
- subscribeToClickedEvent(subscriber: () => void): string | null;
453
+ /**
454
+ * Get the current unread card count. This is useful for powering badges on your control for showing the news feed.
455
+ * Note that Braze will not refresh news feed cards on new page loads (and so this function will return 0) until you
456
+ * call `showFeed` or `requestFeedRefresh`. `ControlCard` cards do not count towards the
457
+ * unread count.
458
+ */
459
+ getUnreadCardCount(): number;
460
+ }
711
461
 
712
- /**
713
- * Subscribe to receive dismissed events. The subscriber callback will be called whenever this message is closed
714
- * by the user, or when it's dismissed automatically (depending on the dismissType).
715
- *
716
- * @param subscriber - The callback function to receive dismissed events. This function will be invoked with
717
- * no arguments when this message records a dismissal.
718
- *
719
- * @returns The identifier of the subscription created. This can be passed to `removeSubscription`
720
- * to cancel the subscription. Returns null if the subscriber passed is not a function.
721
- */
722
- subscribeToDismissedEvent(subscriber: () => void): string | null;
462
+ export class ControlMessage {
463
+ /**
464
+ * A non-showing message placeholder that represents this user receiving the the control for a multivariate
465
+ * test. Can be passed to `showInAppMessage` to log the user's
466
+ * entrollment in the control or handled manually.
467
+ *
468
+ * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
469
+ * Braze with in-app message analytics events.
470
+ */
471
+ constructor(triggerId?: string);
723
472
 
473
+ /**
474
+ * The id of the trigger that created this message. The SDK will report back this to
475
+ * Braze with in-app message analytics events.
476
+ */
477
+ triggerId?: string;
724
478
 
725
- }
479
+ /** Object of string/string key/value pairs. */
480
+ extras: Record<string, string>;
726
481
 
727
- export class FullScreenMessage extends InAppMessage {
728
- /**
729
- * A modal in-app message object which can be passed to `showInAppMessage`
730
- * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`.
731
- *
732
- * @param message - The message to display to the user.
733
- * @param messageAlignment - How to align message text. See the `TextAlignment` enum.
734
- * @param extras - Object of string/string key/value pairs.
735
- * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
736
- * Braze with in-app message analytics events.
737
- * @param clickAction - Where the user should be brought when clicking on this message. See the
738
- * `ClickAction` enum.
739
- * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
740
- * user clicks on this message.
741
- * @param openTarget - If ```clickAction``` is `ClickAction`.URI, whether to open clicks
742
- * in a new tab/window. See the `OpenTarget` enum.
743
- * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
744
- * See the `DismissType` enum.
745
- * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
746
- * dismissType is `DismissType`.AUTO_DISMISS
747
- * @param icon - A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
748
- * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
749
- * @param imageUrl - Url of an image to include in this message. The message will only display an image *or*
750
- * an icon, and will prioritize the image if present.
751
- * @param imageStyle - Whether the image should be shown as normal on the top of the in-app message or used
752
- * as the entire content of the message. See the `ImageStyle` enum.
753
- * @param iconColor - Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green).
754
- * @param iconBackgroundColor - Background color of icon. Hex value with opacity (e.g. 0xff00ff00
755
- * is opaque green).
756
- * @param backgroundColor - Background color of entire message. Hex value with opacity (e.g.
757
- * 0xff00ff00 is opaque green).
758
- * @param textColor - Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque
759
- * green).
760
- * @param closeButtonColor - Color of close button. Hex value with opacity (e.g. 0xff00ff00 is
761
- * opaque green).
762
- * @param animateIn - Whether to animate the showing of this message.
763
- * @param animateOut - Whether to animate the hiding of this message.
764
- * @param header - Header text to
765
- * @param headerAlignment - How to align header text. See the `TextAlignment` enum.
766
- * @param headerTextColor - Color of header text. Hex value with opacity (e.g. 0xff00ff00 is
767
- * opaque green).
768
- * @param frameColor - Color of the background frame which blocks page interaction while the
769
- * message is showing.
770
- * @param buttons - Array of up to two `InAppMessageButton` objects.
771
- * @param cropType - How to crop and fit images in the allowable space. See the `CropType` enum.
772
- * @param orientation - Whether to lay out this in-app message as a portrait or landscape. See the
773
- * `Orientation` enum.
774
- * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
775
- * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
776
- * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
777
- */
778
- constructor(
779
- message?: string,
780
- messageAlignment?: TextAlignment,
781
- extras?: Record<string, string>,
782
- triggerId?: string,
783
- clickAction?: ClickAction,
784
- uri?: string,
785
- openTarget?: OpenTarget,
786
- dismissType?: DismissType,
787
- duration?: number,
788
- icon?: string,
789
- imageUrl?: string,
790
- imageStyle?: ImageStyle,
791
- iconColor?: number,
792
- iconBackgroundColor?: number,
793
- backgroundColor?: number,
794
- textColor?: number,
795
- closeButtonColor?: number,
796
- animateIn?: boolean,
797
- animateOut?: boolean,
798
- header?: string,
799
- headerAlignment?: TextAlignment,
800
- headerTextColor?: number,
801
- frameColor?: number,
802
- buttons?: InAppMessageButton[],
803
- cropType?: CropType,
804
- orientation?: Orientation,
805
- htmlId?: string,
806
- css?: string
807
- );
808
-
809
- /** How to align message text. See the `TextAlignment` enum. */
810
- messageAlignment: TextAlignment;
482
+ /** Whether this message is a ControlMessage. */
483
+ isControl: true;
484
+ }
811
485
 
812
- /**
813
- * Where the user should be brought when clicking on this message. See the
814
- * `ClickAction` enum.
815
- */
816
- clickAction: ClickAction;
817
486
 
818
- /**
819
- * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
820
- * user clicks on this message.
821
- */
822
- uri?: string;
487
+ type SlideFrom =
488
+ (typeof InAppMessage.SlideFrom)[keyof typeof InAppMessage.SlideFrom];
823
489
 
824
- /**
825
- * If ```clickAction``` is `ClickAction`.URI, whether to open clicks
826
- * in a new tab/window. See the `OpenTarget` enum.
827
- */
828
- openTarget: OpenTarget;
829
490
 
830
- /**
831
- * A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
832
- * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
833
- */
834
- icon?: string;
491
+ type ClickAction =
492
+ (typeof InAppMessage.ClickAction)[keyof typeof InAppMessage.ClickAction];
835
493
 
836
- /**
837
- * Url of an image to include in this message. The message will only display an image *or*
838
- * an icon, and will prioritize the image if present.
839
- */
840
- imageUrl?: string;
841
494
 
842
- /**
843
- * Whether the image should be shown as normal on the top of the in-app message or used
844
- * as the entire content of the message. See the `ImageStyle` enum.
845
- */
846
- imageStyle: ImageStyle;
495
+ type DismissType =
496
+ (typeof InAppMessage.DismissType)[keyof typeof InAppMessage.DismissType];
847
497
 
848
- /** Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
849
- iconColor: number;
850
498
 
851
- /** Background color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
852
- iconBackgroundColor: number;
499
+ type OpenTarget =
500
+ (typeof InAppMessage.OpenTarget)[keyof typeof InAppMessage.OpenTarget];
853
501
 
854
- /** Background color of entire message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
855
- backgroundColor: number;
856
502
 
857
- /** Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
858
- textColor: number;
503
+ type ImageStyle =
504
+ (typeof InAppMessage.ImageStyle)[keyof typeof InAppMessage.ImageStyle];
859
505
 
860
- /** Color of close button. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
861
- closeButtonColor: number;
862
506
 
863
- /** Header text to */
864
- header?: string;
507
+ type Orientation =
508
+ (typeof InAppMessage.Orientation)[keyof typeof InAppMessage.Orientation];
865
509
 
866
- /** How to align header text. See the `TextAlignment` enum. */
867
- headerAlignment: TextAlignment;
868
510
 
869
- /** Color of header text. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
870
- headerTextColor: number;
511
+ type TextAlignment =
512
+ (typeof InAppMessage.TextAlignment)[keyof typeof InAppMessage.TextAlignment];
871
513
 
872
- /** Color of the background frame which blocks page interaction while the message is showing. */
873
- frameColor: number;
874
514
 
875
- /** Array of up to two `InAppMessageButton` objects. */
876
- buttons: InAppMessageButton[];
515
+ type CropType =
516
+ (typeof InAppMessage.CropType)[keyof typeof InAppMessage.CropType];
877
517
 
878
- /** How to crop and fit images in the allowable space. See the `CropType` enum. */
879
- cropType: CropType;
518
+ /**
519
+ * Abstract base for in-app messages. Use subclasses `SlideUpMessage`,
520
+ * `ModalMessage`, `FullScreenMessage`, and `HtmlMessage`.
521
+ */
522
+ export class InAppMessage {
523
+ static SlideFrom: {
524
+ TOP: "TOP";
525
+ BOTTOM: "BOTTOM";
526
+ };
880
527
 
881
- /**
882
- * Whether to lay out this in-app message as a portrait or landscape. See the
883
- * `Orientation` enum.
884
- */
885
- orientation: Orientation;
886
- }
528
+ static ClickAction: {
529
+ NEWS_FEED: "NEWS_FEED";
530
+ URI: "URI";
531
+ NONE: "NONE";
532
+ };
887
533
 
888
- export class ModalMessage extends InAppMessage {
889
- /**
890
- * A modal in-app message object which can be passed to `showInAppMessage`
891
- * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
892
- *
893
- * @param message - The message to display to the user.
894
- * @param messageAlignment - How to align message text. See the `TextAlignment` enum.
895
- * @param extras - Object of string/string key/value pairs.
896
- * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
897
- * Braze with in-app message analytics events.
898
- * @param clickAction - Where the user should be brought when clicking on this message. See the
899
- * `ClickAction` enum.
900
- * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
901
- * user clicks on this message.
902
- * @param openTarget - If ```clickAction``` is `ClickAction`.URI, whether to open clicks
903
- * in a new tab/window. See the `OpenTarget` enum.
904
- * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
905
- * See the `DismissType` enum.
906
- * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
907
- * dismissType is `DismissType`.AUTO_DISMISS
908
- * @param icon - A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
909
- * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
910
- * @param imageUrl - Url of an image to include in this message. The message will only display an image *or*
911
- * an icon, and will prioritize the image if present.
912
- * @param imageStyle - Whether the image should be shown as normal on the top of the in-app message or used
913
- * as the entire content of the message. See the `ImageStyle` enum.
914
- * @param iconColor - Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green).
915
- * @param iconBackgroundColor - Background color of icon. Hex value with opacity (e.g. 0xff00ff00
916
- * is opaque green).
917
- * @param backgroundColor - Background color of entire message. Hex value with opacity (e.g.
918
- * 0xff00ff00 is opaque green).
919
- * @param textColor - Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque
920
- * green).
921
- * @param closeButtonColor - Color of close button. Hex value with opacity (e.g. 0xff00ff00 is
922
- * opaque green).
923
- * @param animateIn - Whether to animate the showing of this message.
924
- * @param animateOut - Whether to animate the hiding of this message.
925
- * @param header - Header text to
926
- * @param headerAlignment - How to align header text. See the `TextAlignment` enum.
927
- * @param headerTextColor - Color of header text. Hex value with opacity (e.g. 0xff00ff00 is
928
- * opaque green).
929
- * @param frameColor - Color of the background frame which blocks page interaction while the
930
- * message is showing.
931
- * @param buttons - Array of up to two`InAppMessageButton` objects.
932
- * @param cropType - How to crop and fit images in the allowable space. See the `CropType` enum.
933
- * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
934
- * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
935
- * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
936
- */
937
- constructor(
938
- message?: string,
939
- messageAlignment?: TextAlignment,
940
- extras?: Record<string, string>,
941
- triggerId?: string,
942
- clickAction?: ClickAction,
943
- uri?: string,
944
- openTarget?: OpenTarget,
945
- dismissType?: DismissType,
946
- duration?: number,
947
- icon?: string,
948
- imageUrl?: string,
949
- imageStyle?: ImageStyle,
950
- iconColor?: number,
951
- iconBackgroundColor?: number,
952
- backgroundColor?: number,
953
- textColor?: number,
954
- closeButtonColor?: number,
955
- animateIn?: boolean,
956
- animateOut?: boolean,
957
- header?: string,
958
- headerAlignment?: TextAlignment,
959
- headerTextColor?: number,
960
- frameColor?: number,
961
- buttons?: InAppMessageButton[],
962
- cropType?: CropType,
963
- htmlId?: string,
964
- css?: string
965
- );
966
-
967
- /** How to align message text. See the `TextAlignment` enum. */
968
- messageAlignment: TextAlignment;
534
+ static DismissType: {
535
+ AUTO_DISMISS: "AUTO_DISMISS";
536
+ MANUAL: "SWIPE";
537
+ };
969
538
 
970
- /**
971
- * Where the user should be brought when clicking on this message. See the
972
- * `ClickAction` enum.
973
- */
974
- clickAction: ClickAction;
539
+ static OpenTarget: {
540
+ NONE: "NONE";
541
+ BLANK: "BLANK";
542
+ };
975
543
 
976
- /**
977
- * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
978
- * user clicks on this message.
979
- */
980
- uri?: string;
544
+ static ImageStyle: {
545
+ TOP: "TOP";
546
+ GRAPHIC: "GRAPHIC";
547
+ };
981
548
 
982
- /**
983
- * If ```clickAction``` is `ClickAction`.URI, whether to open clicks
984
- * in a new tab/window. See the `OpenTarget` enum.
985
- */
986
- openTarget: OpenTarget;
549
+ static Orientation: {
550
+ PORTRAIT: "PORTRAIT";
551
+ LANDSCAPE: "LANDSCAPE";
552
+ };
987
553
 
988
- /**
989
- * A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
990
- * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
991
- */
992
- icon?: string;
554
+ static TextAlignment: {
555
+ START: "START";
556
+ CENTER: "CENTER";
557
+ END: "END";
558
+ };
993
559
 
560
+ static CropType: {
994
561
  /**
995
- * Url of an image to include in this message. The message will only display an image *or*
996
- * an icon, and will prioritize the image if present.
562
+ * Centers the image in the available space and crops any overflowing edges.
997
563
  */
998
- imageUrl?: string;
564
+ CENTER_CROP: "CENTER_CROP";
999
565
 
1000
566
  /**
1001
- * Whether the image should be shown as normal on the top of the in-app message or used
1002
- * as the entire content of the message. See the `ImageStyle` enum.
567
+ * Fits the image within the available space, causing blank space on the shorter
568
+ * axis (e.g. tall images will have bars of blank space on the left/right)
1003
569
  */
1004
- imageStyle: ImageStyle;
1005
-
1006
- /** Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1007
- iconColor: number;
1008
-
1009
- /** Background color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1010
- iconBackgroundColor: number;
1011
-
1012
- /** Background color of entire message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1013
- backgroundColor: number;
1014
-
1015
- /** Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1016
- textColor: number;
1017
-
1018
- /** Color of close button. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1019
- closeButtonColor: number;
1020
-
1021
- /** Header text to */
1022
- header?: string;
1023
-
1024
- /** How to align header text. See the `TextAlignment` enum. */
1025
- headerAlignment: TextAlignment;
1026
-
1027
- /** Color of header text. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1028
- headerTextColor: number;
1029
-
1030
- /** Color of the background frame which blocks page interaction while the message is showing. */
1031
- frameColor: number;
1032
-
1033
- /** Array of up to two`InAppMessageButton` objects. */
1034
- buttons: InAppMessageButton[];
570
+ FIT_CENTER: "FIT_CENTER";
571
+ };
1035
572
 
1036
- /** How to crop and fit images in the allowable space. See the `CropType` enum. */
1037
- cropType: CropType;
1038
- }
573
+ /** The message to display to the user. */
574
+ message?: string;
1039
575
 
1040
- export class HtmlMessage extends InAppMessage {
1041
- /**
1042
- * An html-content in-app message object which can be passed to `showInAppMessage`
1043
- * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
1044
- *
1045
- * @param message - The html content to display to the user.
1046
- * @param extras - Object of string/string key/value pairs.
1047
- * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
1048
- * Braze with in-app message analytics events.
1049
- * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
1050
- * See the `TextAlignment` enum.
1051
- * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
1052
- * dismissType is `DismissType`.AUTO_DISMISS.
1053
- * @param animateIn - Whether to animate the showing of this message.
1054
- * @param animateOut - Whether to animate the hiding of this message.
1055
- * @param frameColor - Color of the background frame which blocks page interaction while the message is showing.
1056
- * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
1057
- * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
1058
- * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
1059
- * @param messageFields - Structured data provided by the Braze backend.
1060
- */
1061
- constructor(
1062
- message: string,
1063
- extras?: Record<string, string>,
1064
- triggerId?: string,
1065
- dismissType?: DismissType,
1066
- duration?: number,
1067
- animateIn?: boolean,
1068
- animateOut?: boolean,
1069
- frameColor?: number,
1070
- htmlId?: string,
1071
- css?: string,
1072
- messageFields?: Record<string, any>
1073
- );
1074
-
1075
- /** Color of the background frame which blocks page interaction while the message is showing. */
1076
- frameColor: number;
1077
-
1078
- /** Structured data provided by the Braze backend. */
1079
- messageFields?: Record<string, any>;
1080
- }
576
+ /** Object of string/string key/value pairs. */
577
+ extras: Record<string, string>;
1081
578
 
1082
579
  /**
1083
- * A slide-up in-app message object which can be passed to `showInAppMessage`
1084
- * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
580
+ * The id of the trigger that created this message. The SDK will report back this to
581
+ * Braze with in-app message analytics events.
1085
582
  */
1086
- export class SlideUpMessage extends InAppMessage {
1087
- /**
1088
- * A slide-up in-app message object which can be passed to `showInAppMessage`
1089
- * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
1090
- *
1091
- * @param message - The message to display to the user.
1092
- * @param messageAlignment - How to align message text. See the `TextAlignment` enum.
1093
- * @param slideFrom - Where the message should slide in from. See the `SlideFrom` enum.
1094
- * @param extras - Object of string/string key/value pairs.
1095
- * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
1096
- * Braze with in-app message analytics events.
1097
- * @param clickAction - Where the user should be brought when clicking on this message. See the
1098
- * `ClickAction` enum.
1099
- * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1100
- * user clicks on this message.
1101
- * @param openTarget - If ```clickAction``` is `ClickAction`.URI, whether to open clicks
1102
- * in a new tab/window. See the `OpenTarget` enum.
1103
- * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
1104
- * See the `DismissType` enum.
1105
- * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
1106
- * dismissType is `DismissType`.AUTO_DISMISS
1107
- * @param icon - A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
1108
- * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
1109
- * @param imageUrl - Url of an image to include in this message. The message will only display an image *or*
1110
- * an icon, and will prioritize the image if present.
1111
- * @param iconColor - Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green).
1112
- * @param iconBackgroundColor - Background color of icon. Hex value with opacity (e.g. 0xff00ff00
1113
- * is opaque green).
1114
- * @param backgroundColor - Background color of entire message. Hex value with opacity (e.g.
1115
- * 0xff00ff00 is opaque green).
1116
- * @param textColor - Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque
1117
- * green).
1118
- * @param closeButtonColor - Color of close button. Hex value with opacity (e.g. 0xff00ff00 is
1119
- * opaque green).
1120
- * @param animateIn - Whether to animate the showing of this message.
1121
- * @param animateOut - Whether to animate the hiding of this message.
1122
- * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
1123
- * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
1124
- * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
1125
- */
1126
- constructor(
1127
- message: string,
1128
- messageAlignment?: TextAlignment,
1129
- slideFrom?: SlideFrom,
1130
- extras?: Record<string, string>,
1131
- triggerId?: string,
1132
- clickAction?: ClickAction,
1133
- uri?: string,
1134
- openTarget?: OpenTarget,
1135
- dismissType?: DismissType,
1136
- duration?: number,
1137
- icon?: string,
1138
- imageUrl?: string,
1139
- iconColor?: number,
1140
- iconBackgroundColor?: number,
1141
- backgroundColor?: number,
1142
- textColor?: number,
1143
- closeButtonColor?: number,
1144
- animateIn?: boolean,
1145
- animateOut?: boolean,
1146
- htmlId?: string,
1147
- css?: string
1148
- );
1149
-
1150
- /** How to align message text. See the `TextAlignment` enum. */
1151
- messageAlignment: TextAlignment;
1152
-
1153
- /** Where the message should slide in from. See the `SlideFrom` enum. */
1154
- slideFrom: SlideFrom;
583
+ triggerId?: string;
1155
584
 
1156
- /**
1157
- * Where the user should be brought when clicking on this message. See the
1158
- * `ClickAction` enum.
1159
- */
1160
- clickAction: ClickAction;
1161
-
1162
- /**
1163
- * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1164
- * user clicks on this message.
1165
- */
1166
- uri?: string;
1167
-
1168
- /**
1169
- * If ```clickAction``` is `ClickAction`.URI, whether to open clicks
1170
- * in a new tab/window. See the `OpenTarget` enum.
1171
- */
1172
- openTarget: OpenTarget;
1173
-
1174
- /**
1175
- * A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
1176
- * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
1177
- */
1178
- icon?: string;
585
+ /**
586
+ * How the message is dismissed, via a timer or requiring interaction from the user.
587
+ * See the `DismissType` enum.
588
+ */
589
+ dismissType: DismissType;
1179
590
 
1180
- /**
1181
- * Url of an image to include in this message. The message will only display an image *or*
1182
- * an icon, and will prioritize the image if present.
1183
- */
1184
- imageUrl?: string;
591
+ /**
592
+ * Length of time in milliseconds until auto-dismiss should occur. Only used when
593
+ * dismissType is `DismissType`.AUTO_DISMISS
594
+ */
595
+ duration: number;
1185
596
 
1186
- /** Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1187
- iconColor: number;
597
+ /** Whether to animate the showing of this message. */
598
+ animateIn: boolean;
1188
599
 
1189
- /** Background color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1190
- iconBackgroundColor: number;
600
+ /** Whether to animate the hiding of this message. */
601
+ animateOut: boolean;
1191
602
 
1192
- /** Background color of entire message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1193
- backgroundColor: number;
603
+ /** The ID to give the parent HTML element that this message is rendered into. */
604
+ htmlId?: string;
1194
605
 
1195
- /** Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1196
- textColor: number;
606
+ /**
607
+ * Custom CSS to apply to the page while this element is shown. All selectors should be scoped
608
+ * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
609
+ */
610
+ css?: string;
1197
611
 
1198
- /** Color of close button. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1199
- closeButtonColor: number;
1200
- }
612
+ /** Whether this message is a ControlMessage. */
613
+ isControl: false;
1201
614
 
1202
-
1203
- type Genders = typeof User.Genders[keyof typeof User.Genders];
615
+ /**
616
+ * Call this method if you wish to programmatically remove the message from the DOM. This method will only
617
+ * work with the Braze UI.
618
+ */
619
+ closeMessage(): void;
1204
620
 
1205
-
1206
- type NotificationSubscriptionTypes = typeof User.NotificationSubscriptionTypes[keyof typeof User.NotificationSubscriptionTypes];
621
+ /** Remove all event subscriptions from this message. */
622
+ removeAllSubscriptions(): void;
1207
623
 
1208
624
  /**
1209
- * Do not construct directly - use `getUser` to get the user object.
1210
- * User provides an object which lets you update the attributes stored by Braze for your user.
625
+ * Remove an event subscription that you previously subscribed to.
1211
626
  *
1212
- * This class has been designed to provide fire and forget semantics and to not impact the performance or lifecycle of
1213
- * calling code. As such, changes made to an User are enqueued locally and flushed to Braze's servers
1214
- * asynchronously.
627
+ * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
628
+ * you initially used to create it.
1215
629
  */
1216
- export class User {
1217
- /** Enum to represent valid genders. */
1218
- static Genders: {
1219
- MALE: "m";
1220
- FEMALE: "f";
1221
- OTHER: "o";
1222
- UNKNOWN: "u";
1223
- NOT_APPLICABLE: "n";
1224
- PREFER_NOT_TO_SAY: "p";
1225
- };
1226
-
1227
- /** Enum to represent notification status for email and push notifications. */
1228
- static NotificationSubscriptionTypes: {
1229
- OPTED_IN: "opted_in";
1230
- SUBSCRIBED: "subscribed";
1231
- UNSUBSCRIBED: "unsubscribed";
1232
- };
1233
-
1234
- /**
1235
- * Adds an an alias for the user. (alias, label) pairs can exist on one and only one user.
1236
- * If a different user already has this alias or external user id, the alias attempt will be rejected
1237
- * on the server.
1238
- *
1239
- * @param alias - An identifier for this user.
1240
- * @param label - A label for the alias. e.g. the source of the alias, like "internal_id"
1241
- *
1242
- * @returns Whether the update was successfully enqueued.
1243
- */
1244
- addAlias(alias: string, label: string): boolean;
1245
-
1246
- /**
1247
- * Adds a string to a custom attribute string array, or creates that array if one doesn't exist.
1248
- *
1249
- * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1250
- * a $, and can only contain alphanumeric characters and punctuation.
1251
- * @param value - The string to be added to the array. Strings are limited to 255 characters in length, cannot
1252
- * begin with a $, and can only contain alphanumeric characters and punctuation.
1253
- *
1254
- * @returns Whether the update was successfully enqueued.
1255
- */
1256
- addToCustomAttributeArray(key: string, value: string): boolean;
1257
-
1258
- /**
1259
- * Adds a user to an email or SMS subscription group.
1260
- *
1261
- * @param subscriptionGroupId - The unique identifier of the subscription group.
1262
- *
1263
- * @returns Whether the update was successfully enqueued.
1264
- */
1265
- addToSubscriptionGroup(subscriptionGroupId: string): boolean;
1266
-
1267
- /**
1268
- * Asynchronously retrieves the current user's id, or null if the user is anonymous / has not been identified.
1269
- * For example:
1270
- *
1271
- * ```
1272
- * braze.getUser().getUserId(function(userId) {
1273
- * console.log('The user is ' + userId);
1274
- * });
1275
- * ```
1276
- *
1277
- * @param callback - Asynchronous callback - this will be invoked with the userId.
1278
- */
1279
- getUserId(callback: (userId: string | null) => void): void;
1280
-
1281
- /**
1282
- * Increment/decrement the value of a custom attribute. Only numeric custom attributes
1283
- * can be incremented. Attempts to increment a custom attribute that is not numeric
1284
- * will be ignored. If you increment a custom attribute that has not previously been
1285
- * set, a custom attribute will be created and assigned the value of incrementValue.
1286
- * To decrement the value of a custom attribute, use a negative incrementValue.
1287
- *
1288
- * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1289
- * a $, and can only contain alphanumeric characters and punctuation.
1290
- * @param incrementValue - Default 1. May be negative to decrement.
1291
- *
1292
- * @returns Whether the update was successfully enqueued.
1293
- */
1294
- incrementCustomUserAttribute(key: string, incrementValue?: number): boolean;
1295
-
1296
- /**
1297
- * Removes a string from a custom attribute string array.
1298
- *
1299
- * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1300
- * a $, and can only contain alphanumeric characters and punctuation.
1301
- * @param value - The string to be removed from the array. Strings are limited to 255 characters in length,
1302
- * cannot begin with a $, and can only contain alphanumeric characters and punctuation.
1303
- *
1304
- * @returns Whether the update was successfully enqueued.
1305
- */
1306
- removeFromCustomAttributeArray(key: string, value: string): boolean;
1307
-
1308
- /**
1309
- * Removes a user from an email or SMS subscription group.
1310
- *
1311
- * @param subscriptionGroupId - The unique identifier of the subscription group.
1312
- *
1313
- * @returns Whether the update was successfully enqueued.
1314
- */
1315
- removeFromSubscriptionGroup(subscriptionGroupId: string): boolean;
1316
-
1317
- /**
1318
- * Sets the country for the user.
1319
- *
1320
- * @param country - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1321
- *
1322
- * @returns Whether the update was successfully enqueued.
1323
- */
1324
- setCountry(country: string | null): boolean;
1325
-
1326
- /**
1327
- * Sets a custom user location attribute.
1328
- *
1329
- * @param key - The identifier of the custom location attribute. Limited to 255 characters in length, cannot begin with
1330
- * a $, and can only contain alphanumeric characters and punctuation.
1331
- * @param latitude - The latitude of the user's location in (valid values are between -90 to 90 degrees). Passing a null
1332
- * value for both latitude and longitude will remove this custom attribute from the user.
1333
- * @param longitude - The longitude of the user's location (valid values are between -180 to 180 degrees). Passing a null
1334
- * value for both latitude and longitude will remove this custom attribute from the user.
1335
- *
1336
- * @returns Whether the update was successfully enqueued.
1337
- */
1338
- setCustomLocationAttribute(
1339
- key: string,
1340
- latitude: number | null,
1341
- longitude: number | null
1342
- ): boolean;
1343
-
1344
- /**
1345
- * Sets a custom user attribute. This can be any key/value pair and is used to collect extra
1346
- * information about the user.
1347
- *
1348
- * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1349
- * a $, and can only contain alphanumeric characters and punctuation.
1350
- * @param value - Can be numeric, boolean, a Date object, a string, or an array of strings. Strings are limited to
1351
- * 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
1352
- * Passing a null value will remove this custom attribute from the user.
1353
- * @param merge - Whether the value should be merged with the existing value on the backend. If `false` (default), any existing
1354
- * attribute will be overwritten. If `true`, existing objects and arrays of objects will be merged. To update an array of objects,
1355
- * follow the guidelines in our
1356
- * [public docs](https://www.braze.com/docs/user_guide/data_and_analytics/custom_data/custom_attributes/array_of_objects/#usage-examples).
1357
- *
1358
- * @returns {boolean} Whether the update was successfully enqueued.
1359
- */
1360
- setCustomUserAttribute(
1361
- key: string,
1362
- value: number | boolean | Date | string | string[] | object | object[] | null,
1363
- merge?: boolean
1364
- ): boolean;
1365
-
1366
- /**
1367
- * Sets the date of birth of the user. Alternatively takes in null values for all parameters
1368
- * to set date of birth to null.
1369
- *
1370
- * @param year
1371
- * @param month - 1-12
1372
- * @param day
1373
- *
1374
- * @returns Whether the update was successfully enqueued.
1375
- */
1376
- setDateOfBirth(
1377
- year: number | null,
1378
- month: number | null,
1379
- day: number | null
1380
- ): boolean;
1381
-
1382
- /**
1383
- * Sets the email address of the user.
1384
- *
1385
- * @param email - Must pass RFC-5322 email address validation. Accepts an explicit null value to
1386
- * null out attribute.
1387
- *
1388
- * @returns Whether the update was successfully enqueued.
1389
- */
1390
- setEmail(email: string | null): boolean;
630
+ removeSubscription(subscriptionGuid: string): void;
631
+
632
+ /**
633
+ * Subscribe to receive click events. The subscriber callback will be called whenever this message is clicked by the
634
+ * user.
635
+ *
636
+ * @param subscriber - The callback function to receive click events. This function will be invoked with
637
+ * no arguments when this message records a click.
638
+ *
639
+ * @returns The identifier of the subscription created. This can be passed to `removeSubscription`
640
+ * to cancel the subscription. Returns null if the subscriber passed is not a function.
641
+ */
642
+ subscribeToClickedEvent(subscriber: () => void): string | null;
643
+
644
+ /**
645
+ * Subscribe to receive dismissed events. The subscriber callback will be called whenever this message is closed
646
+ * by the user, or when it's dismissed automatically (depending on the dismissType).
647
+ *
648
+ * @param subscriber - The callback function to receive dismissed events. This function will be invoked with
649
+ * no arguments when this message records a dismissal.
650
+ *
651
+ * @returns The identifier of the subscription created. This can be passed to `removeSubscription`
652
+ * to cancel the subscription. Returns null if the subscriber passed is not a function.
653
+ */
654
+ subscribeToDismissedEvent(subscriber: () => void): string | null;
655
+
656
+
657
+ }
658
+
659
+ export class FullScreenMessage extends InAppMessage {
660
+ /**
661
+ * A modal in-app message object which can be passed to `showInAppMessage`
662
+ * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`.
663
+ *
664
+ * @param message - The message to display to the user.
665
+ * @param messageAlignment - How to align message text. See the `TextAlignment` enum.
666
+ * @param extras - Object of string/string key/value pairs.
667
+ * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
668
+ * Braze with in-app message analytics events.
669
+ * @param clickAction - Where the user should be brought when clicking on this message. See the
670
+ * `ClickAction` enum.
671
+ * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
672
+ * user clicks on this message.
673
+ * @param openTarget - If ```clickAction``` is `ClickAction`.URI, whether to open clicks
674
+ * in a new tab/window. See the `OpenTarget` enum.
675
+ * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
676
+ * See the `DismissType` enum.
677
+ * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
678
+ * dismissType is `DismissType`.AUTO_DISMISS
679
+ * @param icon - A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
680
+ * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
681
+ * @param imageUrl - Url of an image to include in this message. The message will only display an image *or*
682
+ * an icon, and will prioritize the image if present.
683
+ * @param imageStyle - Whether the image should be shown as normal on the top of the in-app message or used
684
+ * as the entire content of the message. See the `ImageStyle` enum.
685
+ * @param iconColor - Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green).
686
+ * @param iconBackgroundColor - Background color of icon. Hex value with opacity (e.g. 0xff00ff00
687
+ * is opaque green).
688
+ * @param backgroundColor - Background color of entire message. Hex value with opacity (e.g.
689
+ * 0xff00ff00 is opaque green).
690
+ * @param textColor - Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque
691
+ * green).
692
+ * @param closeButtonColor - Color of close button. Hex value with opacity (e.g. 0xff00ff00 is
693
+ * opaque green).
694
+ * @param animateIn - Whether to animate the showing of this message.
695
+ * @param animateOut - Whether to animate the hiding of this message.
696
+ * @param header - Header text to
697
+ * @param headerAlignment - How to align header text. See the `TextAlignment` enum.
698
+ * @param headerTextColor - Color of header text. Hex value with opacity (e.g. 0xff00ff00 is
699
+ * opaque green).
700
+ * @param frameColor - Color of the background frame which blocks page interaction while the
701
+ * message is showing.
702
+ * @param buttons - Array of up to two `InAppMessageButton` objects.
703
+ * @param cropType - How to crop and fit images in the allowable space. See the `CropType` enum.
704
+ * @param orientation - Whether to lay out this in-app message as a portrait or landscape. See the
705
+ * `Orientation` enum.
706
+ * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
707
+ * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
708
+ * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
709
+ */
710
+ constructor(
711
+ message?: string,
712
+ messageAlignment?: TextAlignment,
713
+ extras?: Record<string, string>,
714
+ triggerId?: string,
715
+ clickAction?: ClickAction,
716
+ uri?: string,
717
+ openTarget?: OpenTarget,
718
+ dismissType?: DismissType,
719
+ duration?: number,
720
+ icon?: string,
721
+ imageUrl?: string,
722
+ imageStyle?: ImageStyle,
723
+ iconColor?: number,
724
+ iconBackgroundColor?: number,
725
+ backgroundColor?: number,
726
+ textColor?: number,
727
+ closeButtonColor?: number,
728
+ animateIn?: boolean,
729
+ animateOut?: boolean,
730
+ header?: string,
731
+ headerAlignment?: TextAlignment,
732
+ headerTextColor?: number,
733
+ frameColor?: number,
734
+ buttons?: InAppMessageButton[],
735
+ cropType?: CropType,
736
+ orientation?: Orientation,
737
+ htmlId?: string,
738
+ css?: string,
739
+ );
1391
740
 
1392
- /**
1393
- * Sets whether the user should be sent email campaigns.
1394
- *
1395
- * @param notificationSubscriptionType - Notification setting (explicitly opted-in, subscribed, or unsubscribed).
1396
- * See the `NotificationSubscriptionTypes` enum.
1397
- *
1398
- * @returns Whether the update was successfully enqueued.
1399
- */
1400
- setEmailNotificationSubscriptionType(
1401
- notificationSubscriptionType: NotificationSubscriptionTypes
1402
- ): boolean;
741
+ /** How to align message text. See the `TextAlignment` enum. */
742
+ messageAlignment: TextAlignment;
1403
743
 
1404
- /**
1405
- * Sets the first name of the user.
1406
- *
1407
- * @param firstName - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1408
- *
1409
- * @returns Whether the update was successfully enqueued.
1410
- */
1411
- setFirstName(firstName: string | null): boolean;
744
+ /**
745
+ * Where the user should be brought when clicking on this message. See the
746
+ * `ClickAction` enum.
747
+ */
748
+ clickAction: ClickAction;
1412
749
 
1413
- /**
1414
- * Sets the gender of the user.
1415
- *
1416
- * @param gender - Generally 'm' or 'f'. Accepts an explicit null value to null out attribute. Use `Genders`
1417
- * enum when setting this value.
1418
- *
1419
- * @returns Whether the update was successfully enqueued.
1420
- */
1421
- setGender(gender: Genders | null): boolean;
750
+ /**
751
+ * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
752
+ * user clicks on this message.
753
+ */
754
+ uri?: string;
755
+
756
+ /**
757
+ * If ```clickAction``` is `ClickAction`.URI, whether to open clicks
758
+ * in a new tab/window. See the `OpenTarget` enum.
759
+ */
760
+ openTarget: OpenTarget;
761
+
762
+ /**
763
+ * A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
764
+ * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
765
+ */
766
+ icon?: string;
767
+
768
+ /**
769
+ * Url of an image to include in this message. The message will only display an image *or*
770
+ * an icon, and will prioritize the image if present.
771
+ */
772
+ imageUrl?: string;
773
+
774
+ /**
775
+ * Whether the image should be shown as normal on the top of the in-app message or used
776
+ * as the entire content of the message. See the `ImageStyle` enum.
777
+ */
778
+ imageStyle: ImageStyle;
1422
779
 
1423
- /**
1424
- * Sets the home city for the user.
1425
- *
1426
- * @param homeCity - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1427
- *
1428
- * @returns Whether the update was successfully enqueued.
1429
- */
1430
- setHomeCity(homeCity: string | null): boolean;
780
+ /** Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
781
+ iconColor: number;
1431
782
 
1432
- /**
1433
- * Sets the language for this user. By default, the user's language is detected automatically
1434
- * from the browser. If you call this method, Braze will ignore the detected language and use
1435
- * the language you have provided instead.
1436
- *
1437
- * @param language - An [ISO 639-1 Language Code](https://www.w3schools.com/tags/ref_language_codes.asp).
1438
- * Accepts an explicit null value to null out attribute.
1439
- *
1440
- * @returns {boolean} Whether the update was successfully enqueued.
1441
- */
1442
- setLanguage(language: string | null): boolean;
783
+ /** Background color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
784
+ iconBackgroundColor: number;
1443
785
 
1444
- /**
1445
- * Sets the last known location for the user.
1446
- *
1447
- * @param latitude - The latitude of the user's location in (valid values are between -90 to 90 degrees)
1448
- * @param longitude - The longitude of the user's location (valid values are between -180 to 180 degrees)
1449
- * @param accuracy - The accuracy of the user's lat/long in meters.
1450
- * @param altitude - The altitude of the user's location in meters above or below the WGS 84 reference
1451
- * ellipsoid.
1452
- * @param altitudeAccuracy - The accuracy of the user's altitude in meters.
1453
- *
1454
- * @returns Whether the update was successfully enqueued.
1455
- */
1456
- setLastKnownLocation(
1457
- latitude: number,
1458
- longitude: number,
1459
- accuracy?: number,
1460
- altitude?: number,
1461
- altitudeAccuracy?: number
1462
- ): boolean;
786
+ /** Background color of entire message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
787
+ backgroundColor: number;
1463
788
 
1464
- /**
1465
- * Sets the last name of the user.
1466
- *
1467
- * @param lastName - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1468
- *
1469
- * @returns Whether the update was successfully enqueued.
1470
- */
1471
- setLastName(lastName: string | null): boolean;
789
+ /** Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
790
+ textColor: number;
1472
791
 
1473
- /**
1474
- * Sets the phone number of the user.
1475
- *
1476
- * @param phoneNumber - A phone number is considered valid if it is no more than 255 characters in length and
1477
- * contains only numbers, whitespace, and the following special characters +.-() Accepts an explicit null value to
1478
- * null out attribute.
1479
- *
1480
- * @returns Whether the update was successfully enqueued.
1481
- */
1482
- setPhoneNumber(phoneNumber: string | null): boolean;
792
+ /** Color of close button. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
793
+ closeButtonColor: number;
1483
794
 
1484
- /**
1485
- * Sets whether the user should be sent push campaigns.
1486
- *
1487
- * @param notificationSubscriptionType - Notification setting (explicitly opted-in, subscribed, or unsubscribed).
1488
- * See the `NotificationSubscriptionTypes` enum.
1489
- *
1490
- * @returns Whether the update was successfully enqueued.
1491
- */
1492
- setPushNotificationSubscriptionType(
1493
- notificationSubscriptionType: NotificationSubscriptionTypes
1494
- ): boolean;
1495
- }
795
+ /** Header text to */
796
+ header?: string;
1496
797
 
1497
- export class InAppMessageButton {
1498
- /**
1499
- * Represents a button on an `ModalMessage` or `FullScreenMessage`.
1500
- *
1501
- * @param text - The text to display on this button
1502
- * @param backgroundColor - The background color for this button. Hex value with opacity (e.g.
1503
- * 0xff00ff00 is opaque green).
1504
- * @param textColor - The color for the text of this button. Hex value with opacity (e.g.
1505
- * 0xff00ff00 is opaque green).
1506
- * @param borderColor - The color for the border of this button. Hex value with opacity (e.g.
1507
- * 0xff00ff00 is opaque green).
1508
- * @param clickAction - Where the user should be brought when clicking on this button. See the
1509
- * `ClickAction` enum.
1510
- * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1511
- * user clicks on this button.
1512
- * @param id - The id for this button. Used for analytics.
1513
- */
1514
- constructor(
1515
- text: string,
1516
- backgroundColor?: number,
1517
- textColor?: number,
1518
- borderColor?: number,
1519
- clickAction?: ClickAction,
1520
- uri?: string,
1521
- id?: number
1522
- );
1523
-
1524
- /** The text to display on this button */
1525
- text: string;
798
+ /** How to align header text. See the `TextAlignment` enum. */
799
+ headerAlignment: TextAlignment;
1526
800
 
1527
- /**
1528
- * The background color for this button. Hex value with opacity (e.g.
1529
- * 0xff00ff00 is opaque green).
1530
- */
1531
- backgroundColor: number;
801
+ /** Color of header text. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
802
+ headerTextColor: number;
1532
803
 
1533
- /**
1534
- * The color for the text of this button. Hex value with opacity (e.g.
1535
- * 0xff00ff00 is opaque green).
1536
- */
1537
- textColor: number;
804
+ /** Color of the background frame which blocks page interaction while the message is showing. */
805
+ frameColor: number;
1538
806
 
1539
- /**
1540
- * The color for the border of this button. Hex value with opacity (e.g.
1541
- * 0xff00ff00 is opaque green).
1542
- */
1543
- borderColor: number;
807
+ /** Array of up to two `InAppMessageButton` objects. */
808
+ buttons: InAppMessageButton[];
1544
809
 
1545
- /**
1546
- * Where the user should be brought when clicking on this button. See the
1547
- * `ClickAction` enum.
1548
- */
1549
- clickAction: ClickAction;
810
+ /** How to crop and fit images in the allowable space. See the `CropType` enum. */
811
+ cropType: CropType;
1550
812
 
1551
- /**
1552
- * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1553
- * user clicks on this button.
1554
- */
1555
- uri?: string;
1556
-
1557
- /** The id for this button. Used for analytics. */
1558
- id?: number;
813
+ /**
814
+ * Whether to lay out this in-app message as a portrait or landscape. See the
815
+ * `Orientation` enum.
816
+ */
817
+ orientation: Orientation;
818
+ }
1559
819
 
1560
- /** Remove all event subscriptions from this button. */
1561
- removeAllSubscriptions(): void;
820
+ export class ModalMessage extends InAppMessage {
821
+ /**
822
+ * A modal in-app message object which can be passed to `showInAppMessage`
823
+ * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
824
+ *
825
+ * @param message - The message to display to the user.
826
+ * @param messageAlignment - How to align message text. See the `TextAlignment` enum.
827
+ * @param extras - Object of string/string key/value pairs.
828
+ * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
829
+ * Braze with in-app message analytics events.
830
+ * @param clickAction - Where the user should be brought when clicking on this message. See the
831
+ * `ClickAction` enum.
832
+ * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
833
+ * user clicks on this message.
834
+ * @param openTarget - If ```clickAction``` is `ClickAction`.URI, whether to open clicks
835
+ * in a new tab/window. See the `OpenTarget` enum.
836
+ * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
837
+ * See the `DismissType` enum.
838
+ * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
839
+ * dismissType is `DismissType`.AUTO_DISMISS
840
+ * @param icon - A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
841
+ * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
842
+ * @param imageUrl - Url of an image to include in this message. The message will only display an image *or*
843
+ * an icon, and will prioritize the image if present.
844
+ * @param imageStyle - Whether the image should be shown as normal on the top of the in-app message or used
845
+ * as the entire content of the message. See the `ImageStyle` enum.
846
+ * @param iconColor - Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green).
847
+ * @param iconBackgroundColor - Background color of icon. Hex value with opacity (e.g. 0xff00ff00
848
+ * is opaque green).
849
+ * @param backgroundColor - Background color of entire message. Hex value with opacity (e.g.
850
+ * 0xff00ff00 is opaque green).
851
+ * @param textColor - Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque
852
+ * green).
853
+ * @param closeButtonColor - Color of close button. Hex value with opacity (e.g. 0xff00ff00 is
854
+ * opaque green).
855
+ * @param animateIn - Whether to animate the showing of this message.
856
+ * @param animateOut - Whether to animate the hiding of this message.
857
+ * @param header - Header text to
858
+ * @param headerAlignment - How to align header text. See the `TextAlignment` enum.
859
+ * @param headerTextColor - Color of header text. Hex value with opacity (e.g. 0xff00ff00 is
860
+ * opaque green).
861
+ * @param frameColor - Color of the background frame which blocks page interaction while the
862
+ * message is showing.
863
+ * @param buttons - Array of up to two`InAppMessageButton` objects.
864
+ * @param cropType - How to crop and fit images in the allowable space. See the `CropType` enum.
865
+ * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
866
+ * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
867
+ * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
868
+ */
869
+ constructor(
870
+ message?: string,
871
+ messageAlignment?: TextAlignment,
872
+ extras?: Record<string, string>,
873
+ triggerId?: string,
874
+ clickAction?: ClickAction,
875
+ uri?: string,
876
+ openTarget?: OpenTarget,
877
+ dismissType?: DismissType,
878
+ duration?: number,
879
+ icon?: string,
880
+ imageUrl?: string,
881
+ imageStyle?: ImageStyle,
882
+ iconColor?: number,
883
+ iconBackgroundColor?: number,
884
+ backgroundColor?: number,
885
+ textColor?: number,
886
+ closeButtonColor?: number,
887
+ animateIn?: boolean,
888
+ animateOut?: boolean,
889
+ header?: string,
890
+ headerAlignment?: TextAlignment,
891
+ headerTextColor?: number,
892
+ frameColor?: number,
893
+ buttons?: InAppMessageButton[],
894
+ cropType?: CropType,
895
+ htmlId?: string,
896
+ css?: string,
897
+ );
898
+
899
+ /** How to align message text. See the `TextAlignment` enum. */
900
+ messageAlignment: TextAlignment;
901
+
902
+ /**
903
+ * Where the user should be brought when clicking on this message. See the
904
+ * `ClickAction` enum.
905
+ */
906
+ clickAction: ClickAction;
907
+
908
+ /**
909
+ * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
910
+ * user clicks on this message.
911
+ */
912
+ uri?: string;
913
+
914
+ /**
915
+ * If ```clickAction``` is `ClickAction`.URI, whether to open clicks
916
+ * in a new tab/window. See the `OpenTarget` enum.
917
+ */
918
+ openTarget: OpenTarget;
919
+
920
+ /**
921
+ * A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
922
+ * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
923
+ */
924
+ icon?: string;
925
+
926
+ /**
927
+ * Url of an image to include in this message. The message will only display an image *or*
928
+ * an icon, and will prioritize the image if present.
929
+ */
930
+ imageUrl?: string;
931
+
932
+ /**
933
+ * Whether the image should be shown as normal on the top of the in-app message or used
934
+ * as the entire content of the message. See the `ImageStyle` enum.
935
+ */
936
+ imageStyle: ImageStyle;
937
+
938
+ /** Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
939
+ iconColor: number;
1562
940
 
1563
- /**
1564
- * Remove an event subscription that you previously subscribed to.
1565
- *
1566
- * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
1567
- * you initially used to create it.
1568
- */
1569
- removeSubscription(subscriptionGuid: string): void;
941
+ /** Background color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
942
+ iconBackgroundColor: number;
1570
943
 
1571
- /**
1572
- * Subscribe to receive click events on this button. The subscriber callback will be called whenever this button is
1573
- * clicked by the user.
1574
- *
1575
- * @param subscriber - The callback function to receive click events. This function will be invoked with
1576
- * no arguments when this button records a click.
1577
- *
1578
- * @returns The identifier of the subscription created. This can be passed to `removeSubscription`
1579
- * to cancel the subscription. Returns null if the subscriber passed is not a function.
1580
- */
1581
- subscribeToClickedEvent(subscriber: () => void): string | null;
1582
- }
944
+ /** Background color of entire message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
945
+ backgroundColor: number;
1583
946
 
1584
- export interface FeatureFlagStringProperty {
1585
- type: "string";
1586
- value: string;
1587
- }
947
+ /** Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
948
+ textColor: number;
1588
949
 
1589
- export interface FeatureFlagNumberProperty {
1590
- type: "number";
1591
- value: number;
1592
- }
950
+ /** Color of close button. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
951
+ closeButtonColor: number;
1593
952
 
1594
- export interface FeatureFlagBooleanProperty {
1595
- type: "boolean";
1596
- value: boolean;
1597
- }
953
+ /** Header text to */
954
+ header?: string;
1598
955
 
1599
- export class FeatureFlag {
1600
- /** Indicates whether or not this feature flag is enabled. */
1601
- enabled: boolean;
956
+ /** How to align header text. See the `TextAlignment` enum. */
957
+ headerAlignment: TextAlignment;
1602
958
 
1603
- /** Properties of this feature flag, listed as key-value pairs. */
1604
- properties: Partial<Record<string, FeatureFlagStringProperty | FeatureFlagNumberProperty | FeatureFlagBooleanProperty>>;
959
+ /** Color of header text. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
960
+ headerTextColor: number;
1605
961
 
1606
- /** The ID for this feature flag. */
1607
- id: string;
962
+ /** Color of the background frame which blocks page interaction while the message is showing. */
963
+ frameColor: number;
1608
964
 
1609
- /**
1610
- * Get value of a feature flag property of type string.
1611
- *
1612
- * @param key - The key of the property.
1613
- *
1614
- * @returns The value of the property if the key is found and is of type string.
1615
- * If the key is not found or if there is a type mismatch, this method will return a null.
1616
- */
1617
- getStringProperty(key: string): string | null;
965
+ /** Array of up to two`InAppMessageButton` objects. */
966
+ buttons: InAppMessageButton[];
1618
967
 
1619
- /**
1620
- * Get value of a feature flag property of type number.
1621
- *
1622
- * @param key - The key of the property.
1623
- *
1624
- * @returns The value of the property if the key is found and is of type number.
1625
- * If the key is not found or if there is a type mismatch, this method will return a null.
1626
- */
1627
- getNumberProperty(key: string): number | null;
1628
-
1629
- /**
1630
- * Get value of a feature flag property of type boolean.
1631
- *
1632
- * @param key - The key of the property.
1633
- *
1634
- * @returns The value of the property if the key is found and is of type boolean.
1635
- * If the key is not found or if there is a type mismatch, this method will return a null.
1636
- */
1637
- getBooleanProperty(key: string): boolean | null;
1638
- }
968
+ /** How to crop and fit images in the allowable space. See the `CropType` enum. */
969
+ cropType: CropType;
970
+ }
1639
971
 
972
+ export class HtmlMessage extends InAppMessage {
1640
973
  /**
1641
- * Automatically display in-app messages when they are triggered. This method should be called before
1642
- * calling `openSession`.
974
+ * An html-content in-app message object which can be passed to `showInAppMessage`
975
+ * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
1643
976
  *
1644
- * @returns The identifier of the subscription created. This can be passed to
1645
- * `removeSubscription` to cancel the subscription.
1646
- */
1647
- export function automaticallyShowInAppMessages(): string;
1648
-
977
+ * @param message - The html content to display to the user.
978
+ * @param extras - Object of string/string key/value pairs.
979
+ * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
980
+ * Braze with in-app message analytics events.
981
+ * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
982
+ * See the `TextAlignment` enum.
983
+ * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
984
+ * dismissType is `DismissType`.AUTO_DISMISS.
985
+ * @param animateIn - Whether to animate the showing of this message.
986
+ * @param animateOut - Whether to animate the hiding of this message.
987
+ * @param frameColor - Color of the background frame which blocks page interaction while the message is showing.
988
+ * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
989
+ * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
990
+ * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
991
+ * @param messageFields - Structured data provided by the Braze backend.
992
+ */
993
+ constructor(
994
+ message: string,
995
+ extras?: Record<string, string>,
996
+ triggerId?: string,
997
+ dismissType?: DismissType,
998
+ duration?: number,
999
+ animateIn?: boolean,
1000
+ animateOut?: boolean,
1001
+ frameColor?: number,
1002
+ htmlId?: string,
1003
+ css?: string,
1004
+ messageFields?: Record<string, any>,
1005
+ );
1006
+
1007
+ /** Color of the background frame which blocks page interaction while the message is showing. */
1008
+ frameColor: number;
1009
+
1010
+ /** Structured data provided by the Braze backend. */
1011
+ messageFields?: Record<string, any>;
1012
+ }
1013
+
1014
+ /**
1015
+ * A slide-up in-app message object which can be passed to `showInAppMessage`
1016
+ * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
1017
+ */
1018
+ export class SlideUpMessage extends InAppMessage {
1649
1019
  /**
1650
- * Destroy any Braze news feed currently showing. This method will appropriately clean up any retained resources
1651
- * and also display the hiding animation, and so should be used instead of manually removing feed html from the
1652
- * DOM.
1653
- */
1654
- export function destroyFeed(): void;
1655
-
1656
- /**
1657
- * Hide any Braze content cards currently showing in the parent node, or if none is provided, any content cards in the page.
1658
- * This method will appropriately clean up any retained resources and also display the hiding animation, and so should be
1659
- * used instead of manually removing content cards HTML from the DOM.
1020
+ * A slide-up in-app message object which can be passed to `showInAppMessage`
1021
+ * or handled manually. Subscribe to be notified when in-app messages are triggered via `subscribeToInAppMessage`
1660
1022
  *
1661
- * @param parentNode - The HTML node that denotes the parent of the content cards to be hidden. If null/undefined, all content
1662
- * cards on the page will be hidden.
1663
- */
1664
- export function hideContentCards(parentNode?: Element | null): void;
1023
+ * @param message - The message to display to the user.
1024
+ * @param messageAlignment - How to align message text. See the `TextAlignment` enum.
1025
+ * @param slideFrom - Where the message should slide in from. See the `SlideFrom` enum.
1026
+ * @param extras - Object of string/string key/value pairs.
1027
+ * @param triggerId - The id of the trigger that created this message. The SDK will report back this to
1028
+ * Braze with in-app message analytics events.
1029
+ * @param clickAction - Where the user should be brought when clicking on this message. See the
1030
+ * `ClickAction` enum.
1031
+ * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1032
+ * user clicks on this message.
1033
+ * @param openTarget - If ```clickAction``` is `ClickAction`.URI, whether to open clicks
1034
+ * in a new tab/window. See the `OpenTarget` enum.
1035
+ * @param dismissType - How the message is dismissed, via a timer or requiring interaction from the user.
1036
+ * See the `DismissType` enum.
1037
+ * @param duration - Length of time in milliseconds until auto-dismiss should occur. Only used when
1038
+ * dismissType is `DismissType`.AUTO_DISMISS
1039
+ * @param icon - A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
1040
+ * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
1041
+ * @param imageUrl - Url of an image to include in this message. The message will only display an image *or*
1042
+ * an icon, and will prioritize the image if present.
1043
+ * @param iconColor - Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green).
1044
+ * @param iconBackgroundColor - Background color of icon. Hex value with opacity (e.g. 0xff00ff00
1045
+ * is opaque green).
1046
+ * @param backgroundColor - Background color of entire message. Hex value with opacity (e.g.
1047
+ * 0xff00ff00 is opaque green).
1048
+ * @param textColor - Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque
1049
+ * green).
1050
+ * @param closeButtonColor - Color of close button. Hex value with opacity (e.g. 0xff00ff00 is
1051
+ * opaque green).
1052
+ * @param animateIn - Whether to animate the showing of this message.
1053
+ * @param animateOut - Whether to animate the hiding of this message.
1054
+ * @param htmlId - The ID to give the parent HTML element that this message is rendered into.
1055
+ * @param css - Custom CSS to apply to the page while this element is shown. All selectors should be scoped
1056
+ * to the htmlId of this message to prevent restyling elements outside of the message when it is shown.
1057
+ */
1058
+ constructor(
1059
+ message: string,
1060
+ messageAlignment?: TextAlignment,
1061
+ slideFrom?: SlideFrom,
1062
+ extras?: Record<string, string>,
1063
+ triggerId?: string,
1064
+ clickAction?: ClickAction,
1065
+ uri?: string,
1066
+ openTarget?: OpenTarget,
1067
+ dismissType?: DismissType,
1068
+ duration?: number,
1069
+ icon?: string,
1070
+ imageUrl?: string,
1071
+ iconColor?: number,
1072
+ iconBackgroundColor?: number,
1073
+ backgroundColor?: number,
1074
+ textColor?: number,
1075
+ closeButtonColor?: number,
1076
+ animateIn?: boolean,
1077
+ animateOut?: boolean,
1078
+ htmlId?: string,
1079
+ css?: string,
1080
+ );
1081
+
1082
+ /** How to align message text. See the `TextAlignment` enum. */
1083
+ messageAlignment: TextAlignment;
1084
+
1085
+ /** Where the message should slide in from. See the `SlideFrom` enum. */
1086
+ slideFrom: SlideFrom;
1087
+
1088
+ /**
1089
+ * Where the user should be brought when clicking on this message. See the
1090
+ * `ClickAction` enum.
1091
+ */
1092
+ clickAction: ClickAction;
1093
+
1094
+ /**
1095
+ * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1096
+ * user clicks on this message.
1097
+ */
1098
+ uri?: string;
1099
+
1100
+ /**
1101
+ * If ```clickAction``` is `ClickAction`.URI, whether to open clicks
1102
+ * in a new tab/window. See the `OpenTarget` enum.
1103
+ */
1104
+ openTarget: OpenTarget;
1105
+
1106
+ /**
1107
+ * A Font Awesome unicode string, e.g. "\uf042" to fa-adjust. See
1108
+ * [the Font Awesome cheatsheet](http://fortawesome.github.io/Font-Awesome/cheatsheet/) for details.
1109
+ */
1110
+ icon?: string;
1111
+
1112
+ /**
1113
+ * Url of an image to include in this message. The message will only display an image *or*
1114
+ * an icon, and will prioritize the image if present.
1115
+ */
1116
+ imageUrl?: string;
1117
+
1118
+ /** Color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1119
+ iconColor: number;
1120
+
1121
+ /** Background color of icon. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1122
+ iconBackgroundColor: number;
1123
+
1124
+ /** Background color of entire message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1125
+ backgroundColor: number;
1126
+
1127
+ /** Text color of message. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1128
+ textColor: number;
1129
+
1130
+ /** Color of close button. Hex value with opacity (e.g. 0xff00ff00 is opaque green). */
1131
+ closeButtonColor: number;
1132
+ }
1133
+
1134
+
1135
+ type Genders = (typeof User.Genders)[keyof typeof User.Genders];
1136
+
1137
+
1138
+ type NotificationSubscriptionTypes =
1139
+ (typeof User.NotificationSubscriptionTypes)[keyof typeof User.NotificationSubscriptionTypes];
1140
+
1141
+ /**
1142
+ * Do not construct directly - use `getUser` to get the user object.
1143
+ * User provides an object which lets you update the attributes stored by Braze for your user.
1144
+ *
1145
+ * This class has been designed to provide fire and forget semantics and to not impact the performance or lifecycle of
1146
+ * calling code. As such, changes made to an User are enqueued locally and flushed to Braze's servers
1147
+ * asynchronously.
1148
+ */
1149
+ export class User {
1150
+ /** Enum to represent valid genders. */
1151
+ static Genders: {
1152
+ MALE: "m";
1153
+ FEMALE: "f";
1154
+ OTHER: "o";
1155
+ UNKNOWN: "u";
1156
+ NOT_APPLICABLE: "n";
1157
+ PREFER_NOT_TO_SAY: "p";
1158
+ };
1665
1159
 
1666
- /**
1667
- * Display the user's content cards.
1668
- *
1669
- * @param parentNode - The HTML node to render the content cards into. If null/undefined, the content
1670
- * cards will be rendered in fixed position over the right-hand side of the page and appended to the `<body>`
1671
- * node. If the parent node already has a Braze content cards view as a direct descendant, the existing content
1672
- * cards will be replaced.
1673
- * @param filterFunction - A filter/sort function for cards displayed in this view. Invoked with the
1674
- * array of `Card` objects, sorted by {pinned, date}. Expected to return an array of sorted
1675
- * `Card` objects to render for this user. If omitted, all cards will be displayed.
1676
- */
1677
- export function showContentCards(
1678
- parentNode?: Element | null,
1679
- filterFunction?: (cards: Card[]) => Card[]
1680
- ): void;
1160
+ /** Enum to represent notification status for email and push notifications. */
1161
+ static NotificationSubscriptionTypes: {
1162
+ OPTED_IN: "opted_in";
1163
+ SUBSCRIBED: "subscribed";
1164
+ UNSUBSCRIBED: "unsubscribed";
1165
+ };
1681
1166
 
1682
1167
  /**
1683
- * Display the user's news feed.
1168
+ * Adds an an alias for the user. (alias, label) pairs can exist on one and only one user.
1169
+ * If a different user already has this alias or external user id, the alias attempt will be rejected
1170
+ * on the server.
1684
1171
  *
1685
- * @param parentNode - The HTML node to render the news feed into. If null/undefined, the feed will be
1686
- * rendered in fixed position over the right-hand side of the page and appended to the `<body>` node. If the
1687
- * parent node already has an Braze news feed as a direct descendant, the existing feed will be replaced.
1688
- * @param cards - A static set of cards to Each item in this Array should be a `Card`
1689
- * descendant. If this parameter is null/undefined, all unexpired cards from the last news feed refresh will be
1690
- * used automatically, a feed refresh will be kicked off automatically if the cached cards are more than 1 minute
1691
- * old, and the feed will automatically update when new cards are received while it is still showing. If you
1692
- * provide an explicit set of cards by using this parameter, no action will be taken when new cards are received,
1693
- * and you must subscribe to feed updates yourself with `subscribeToFeedUpdates` and request updates with
1694
- * `requestFeedRefresh` if you want to update this feed with new cards.
1695
- * @param allowedCategories - A set of categories to filter cards to. Each item in this Array should be a
1696
- * card category as set in the Braze dashboard. If omitted, all cards will be displayed.
1172
+ * @param alias - An identifier for this user.
1173
+ * @param label - A label for the alias. e.g. the source of the alias, like "internal_id"
1174
+ *
1175
+ * @returns Whether the update was successfully enqueued.
1697
1176
  */
1698
- export function showFeed(
1699
- parentNode?: Element | null,
1700
- cards?: Card[] | null,
1701
- allowedCategories?: string[]
1702
- ): void;
1177
+ addAlias(alias: string, label: string): boolean;
1703
1178
 
1704
1179
  /**
1705
- * Display a given in-app message.
1180
+ * Adds a string to a custom attribute string array, or creates that array if one doesn't exist.
1706
1181
  *
1707
- * @param inAppMessage - The message to
1708
- * @param parentNode - The HTML node to render the in-app message into. If null/undefined, the message
1709
- * will be rendered appended within the `<body>` node.
1710
- * @param onDisplayCallback - Optional callback to invoke once the message is on the screen.
1182
+ * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1183
+ * a $, and can only contain alphanumeric characters and punctuation.
1184
+ * @param value - The string to be added to the array. Strings are limited to 255 characters in length, cannot
1185
+ * begin with a $, and can only contain alphanumeric characters and punctuation.
1711
1186
  *
1712
- * @returns Whether or not the message was displayed (or, in the case of control messages, logged to
1713
- * Braze servers).
1187
+ * @returns Whether the update was successfully enqueued.
1714
1188
  */
1715
- export function showInAppMessage(
1716
- inAppMessage: InAppMessage | ControlMessage,
1717
- parentNode?: Element | null,
1718
- onDisplayCallback?: () => void
1719
- ): boolean;
1189
+ addToCustomAttributeArray(key: string, value: string): boolean;
1720
1190
 
1721
1191
  /**
1722
- * Defers the display of given in-app message for a future pageload.
1723
- * The deferred in-app message can be retrieved by calling `getDeferredInAppMessage`,
1724
- * and displayed using `showInAppMessage`.
1725
- * Deferring an in-app message will overwrite any previously deferred in-app message.
1726
- *
1727
- * Note: Be sure to subscribe to clicked / dismissed events on this in-app message only after retrieving it using `getDeferredInAppMessage`.
1728
- * Any subscriptions made before calling `deferInAppMessage` will not be persisted.
1729
- * Also note that the in-app message deferred here will be cleared out when in-app message triggers have been refreshed from the Braze backend.
1730
- *
1731
- * @param inAppMessage - The message to defer for later display.
1732
- *
1733
- * @returns Whether or not the message was successfully deferred.
1734
- * Returns undefined if the SDK has not been initialized.
1735
- */
1736
- export function deferInAppMessage(
1737
- inAppMessage: InAppMessage
1738
- ): boolean | undefined;
1739
-
1740
- /**
1741
- * Retrieves the in-app message that was most recently deferred for display with `deferInAppMessage`.
1742
- *
1743
- * Note: Retrieving the deferred in-app message here will clear it from storage.
1744
- *
1745
- * @returns The deferred in-app message if it exists, or returns null.
1746
- * Returns undefined if the SDK has not been initialized.
1192
+ * Adds a user to an email or SMS subscription group.
1193
+ *
1194
+ * @param subscriptionGroupId - The unique identifier of the subscription group.
1195
+ *
1196
+ * @returns Whether the update was successfully enqueued.
1747
1197
  */
1748
- export function getDeferredInAppMessage(): InAppMessage | null | undefined;
1198
+ addToSubscriptionGroup(subscriptionGroupId: string): boolean;
1749
1199
 
1750
1200
  /**
1751
- * Toggle the display of Braze content cards, showing them if they are not shown, and hiding them if they are. If you
1752
- * wish to display multiple content cards feeds on a page simultaneously, you should use `showContentCards` and `hideContentCards`
1753
- * to show/hide each feed individually instead of this method.
1201
+ * Asynchronously retrieves the current user's id, or null if the user is anonymous / has not been identified.
1202
+ * For example:
1754
1203
  *
1755
- * @param parentNode - The HTML node to render the content cards into. If null/undefined, the content
1756
- * cards will be rendered in fixed position over the right-hand side of the page and appended to the `<body>`
1757
- * node. If the parent node already has a Braze content cards view as a direct descendant, the existing content
1758
- * cards will be replaced.
1759
- * @param filterFunction - A filter/sort function for cards displayed in this view. Invoked with the
1760
- * array of `Card` objects, sorted by {pinned, date}. Expected to return an array of sorted
1761
- * `Card` objects to render for this user. If omitted, all cards will be displayed.
1204
+ * ```
1205
+ * braze.getUser().getUserId(function(userId) {
1206
+ * console.log('The user is ' + userId);
1207
+ * });
1208
+ * ```
1209
+ * @deprecated - The getUserId callback is deprecated. Access the method's return value directly instead.
1210
+ * @param callback - Asynchronous callback - this will be invoked with the userId.
1762
1211
  */
1763
- export function toggleContentCards(
1764
- parentNode?: Element | null,
1765
- filterFunction?: (cards: Card[]) => Card[]
1766
- ): void;
1767
-
1212
+ getUserId(callback: (userId: string | null) => void): void;
1768
1213
  /**
1769
- * Toggle the Braze news feed, creating it if it does not exist, and destroying it if it does.
1214
+ * Retrieves the current user's id, or null if the user is anonymous / has not been identified.
1215
+ * For example:
1770
1216
  *
1771
- * @param parentNode - The HTML node to render the news feed into. If null/undefined, the feed will be
1772
- * rendered in fixed position over the right-hand side of the page and appended to the `<body>` node. If the
1773
- * parent node already has an Braze news feed as a direct descendant, the existing feed will be replaced.
1774
- * @param cards - A static set of cards to Each item in this Array should be a `Card`
1775
- * descendant. If this parameter is null/undefined, all unexpired cards from the last news feed refresh will be
1776
- * used automatically, a feed refresh will be kicked off automatically if the cached cards are more than 1 minute
1777
- * old, and the feed will automatically update when new cards are received while it is still showing. If you
1778
- * provide an explicit set of cards by using this parameter, no action will be taken when new cards are received,
1779
- * and you must subscribe to feed updates yourself with `subscribeToFeedUpdates` and request updates with
1780
- * `requestFeedRefresh` if you want to update this feed with new cards.
1781
- * @param allowedCategories - A set of categories to filter cards to. Each item in this Array should be a
1782
- * card category as set in the Braze dashboard. If omitted, all cards will be displayed.
1217
+ * ```
1218
+ * console.log('The user is ' + braze.getUser().getUserId());
1219
+ * ```
1783
1220
  */
1784
- export function toggleFeed(
1785
- parentNode?: Element | null,
1786
- cards?: Card[] | null,
1787
- allowedCategories?: string[]
1788
- ): void;
1789
-
1221
+ getUserId(): string | null | undefined;
1790
1222
  /**
1791
- * When a user first uses Braze on a device they are considered "anonymous". Use this method to identify a user
1792
- * with a unique ID, which enables the following:
1793
- *
1794
- * - If the same user is identified on another device, their user profile, usage history and event history will
1795
- * be shared across devices.
1796
- * - If your app is used on the same browser by multiple people, you can assign each of them a unique identifier
1797
- * to track them separately. Only the most recent user on a particular browser will receive push
1798
- * notifications and in-app messages.
1223
+ * Increment/decrement the value of a custom attribute. Only numeric custom attributes
1224
+ * can be incremented. Attempts to increment a custom attribute that is not numeric
1225
+ * will be ignored. If you increment a custom attribute that has not previously been
1226
+ * set, a custom attribute will be created and assigned the value of incrementValue.
1227
+ * To decrement the value of a custom attribute, use a negative incrementValue.
1799
1228
  *
1800
- * When you request a user switch (which is any call to changeUser where the new user ID is not the same as the
1801
- * existing user ID), the current session for the previous user (anonymous or not) is automatically ended and
1802
- * a new session is started. Similarly, following a call to changeUser, any events which fire are guaranteed to
1803
- * be for the new user -- if an in-flight server request completes for the old user after the user switch no
1804
- * events will fire, so you do not need to worry about filtering out events from Braze for old users.
1229
+ * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1230
+ * a $, and can only contain alphanumeric characters and punctuation.
1231
+ * @param incrementValue - Default 1. May be negative to decrement.
1805
1232
  *
1806
- * Additionally, if you identify a user which has never been identified on another device, the entire history of
1807
- * that user as an "anonymous" user on this device will be preserved and associated with the newly identified
1808
- * user. However, if you identify a user which *has* been identified in another app, any history which was
1809
- * already flushed to the server for the anonymous user on this device will become orphaned and will not be
1810
- * associated with any future users. These orphaned users are not considered in your user counts and will not
1811
- * be messaged.
1812
- *
1813
- * Note: Once you identify a user, you cannot revert to the "anonymous" user. The transition from anonymous to
1814
- * identified tracking is only allowed once because the initial anonymous user receives special treatment to
1815
- * allow for preservation of their history. As a result, we recommend against changing the user ID just because
1816
- * your app has entered a "logged out" state because it makes you unable to target the previously logged out user
1817
- * with re-engagement campaigns. If you anticipate multiple users on the same device, but only want to target one
1818
- * of them when your app is in a logged out state, we recommend separately keeping track of the user ID you want
1819
- * to target while logged out and switching back to that user ID as part of your app's logout process.
1820
- *
1821
- * @param userId - A unique identifier for this user. Limit 997 bytes.
1822
- * These User IDs should be private and not easily guessable (e.g. not a plain email address or username).
1823
- * @param signature - An encrypted signature to be used to authenticate the current user. You can update the signature
1824
- * using the `setSdkAuthenticationSignature` method. This signature will only have an effect if the `enableSdkAuthentication`
1825
- * initialization option is set to true.
1826
- */
1827
- export function changeUser(userId: string, signature?: string): void;
1828
-
1829
- /**
1830
- * Destroys this `braze` instance, destroying all subscription callbacks and releasing member variables which
1831
- * retain memory.
1233
+ * @returns Whether the update was successfully enqueued.
1832
1234
  */
1833
- export function destroy(): void;
1235
+ incrementCustomUserAttribute(key: string, incrementValue?: number): boolean;
1834
1236
 
1835
1237
  /**
1836
- * Get all currently available cards from the last content cards refresh.
1238
+ * Removes a string from a custom attribute string array.
1837
1239
  *
1838
- * @returns - A `ContentCards` object which includes all currently available
1839
- * `Card` objects from the last content cards refresh.
1840
- */
1841
- export function getCachedContentCards(): ContentCards;
1842
-
1843
- /**
1844
- * Get all unexpired cards from the last news feed refresh.
1240
+ * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1241
+ * a $, and can only contain alphanumeric characters and punctuation.
1242
+ * @param value - The string to be removed from the array. Strings are limited to 255 characters in length,
1243
+ * cannot begin with a $, and can only contain alphanumeric characters and punctuation.
1845
1244
  *
1846
- * @returns - A `Feed` object which includes all unexpired `Card` objects from the last
1847
- * news feed refresh.
1245
+ * @returns Whether the update was successfully enqueued.
1848
1246
  */
1849
- export function getCachedFeed(): Feed;
1247
+ removeFromCustomAttributeArray(key: string, value: string): boolean;
1850
1248
 
1851
1249
  /**
1852
- * Asynchronously retrieves the 'device id,' a randomly generated ID that is stored on the browser.
1853
- * This ID resets for private browsing sessions and when website data is cleared. For example:
1250
+ * Removes a user from an email or SMS subscription group.
1854
1251
  *
1855
- * ```
1856
- * braze.getDeviceId(function(deviceId) {
1857
- * console.log('The device id is ' + deviceId);
1858
- * });
1859
- * ```
1252
+ * @param subscriptionGroupId - The unique identifier of the subscription group.
1860
1253
  *
1861
- * @param callback - Asynchronous callback - this will be invoked with the deviceId.
1254
+ * @returns Whether the update was successfully enqueued.
1862
1255
  */
1863
- export function getDeviceId(callback: (deviceId: string) => void): void;
1256
+ removeFromSubscriptionGroup(subscriptionGroupId: string): boolean;
1864
1257
 
1865
1258
  /**
1866
- * @returns The user currently being tracked by Braze, used for querying the tracked user id and setting
1867
- * user attributes. Should only be accessed via the `getUser` function. Returns undefined if the
1868
- * SDK has not been initialized.
1869
- */
1870
- export function getUser(): User | undefined;
1871
-
1872
- /**
1873
- * Initializes this `braze` instance with your API key. This method must be called before other Braze methods are
1874
- * invoked, and is part of the default loading snippets. Subsequent calls will be ignored until 'destroy`
1875
- * is called.
1259
+ * Sets the country for the user.
1876
1260
  *
1877
- * @param apiKey - Your app's Braze API Key. Your API keys can be found
1878
- * [here](https://dashboard.braze.com/app_settings/app_settings).
1879
- * @param options - Configuration options. See `InitializationOptions` for supported options.
1261
+ * @param country - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1880
1262
  *
1881
- * @returns - Whether or not the `braze` instance has been successfully initialized.
1882
- * Reasons for returning false include a missing API key/base URL, user opt out, and ignored crawler bot activity.
1263
+ * @returns Whether the update was successfully enqueued.
1883
1264
  */
1884
- export function initialize(apiKey: string, options: InitializationOptions): boolean;
1265
+ setCountry(country: string | null): boolean;
1885
1266
 
1886
1267
  /**
1887
- * @returns Whether or not the user has blocked push. If the user has blocked push, they cannot be
1888
- * prompted to register again, and must manually remove the block in order to receive push.
1889
- * Returns undefined if the SDK has not been initialized.
1890
- */
1891
- export function isPushBlocked(): boolean | undefined;
1892
-
1893
- /**
1894
- * Tests whether the user has given this browser push permission (they may still be unsubscribed from push via
1895
- * `User.setPushNotificationSubscriptionType`). A true value essentially means that
1896
- * `requestPushPermission` may be called without the user being prompted. Useful for migrating existing
1897
- * non-Braze push registrations to Braze.
1268
+ * Sets a custom user location attribute.
1269
+ *
1270
+ * @param key - The identifier of the custom location attribute. Limited to 255 characters in length, cannot begin with
1271
+ * a $, and can only contain alphanumeric characters and punctuation.
1272
+ * @param latitude - The latitude of the user's location in (valid values are between -90 to 90 degrees). Passing a null
1273
+ * value for both latitude and longitude will remove this custom attribute from the user.
1274
+ * @param longitude - The longitude of the user's location (valid values are between -180 to 180 degrees). Passing a null
1275
+ * value for both latitude and longitude will remove this custom attribute from the user.
1898
1276
  *
1899
- * @returns Whether or not the user has granted push permission. If this returns true,
1900
- * `requestPushPermission` may be called without the user being prompted. If this returns false,
1901
- * `requestPushPermission` may prompt the user (if `isPushSupported` returns true) or do
1902
- * nothing (if `isPushSupported` returns false). Returns undefined if the SDK has not been initialized.
1277
+ * @returns Whether the update was successfully enqueued.
1903
1278
  */
1904
- export function isPushPermissionGranted(): boolean | undefined;
1279
+ setCustomLocationAttribute(
1280
+ key: string,
1281
+ latitude: number | null,
1282
+ longitude: number | null,
1283
+ ): boolean;
1905
1284
 
1906
1285
  /**
1907
- * The [W3C Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) is partially supported
1908
- * across the browser landscape. This method allows you to programmatically determine whether push is supported
1909
- * in the current browser, and whether to show push-related user class elements to the user.
1910
- *
1911
- * @returns Whether or not push is supported in this environment. Returns undefined if the SDK has not been initialized.
1912
- */
1913
- export function isPushSupported(): boolean | undefined;
1286
+ * Sets a custom user attribute. This can be any key/value pair and is used to collect extra
1287
+ * information about the user.
1288
+ *
1289
+ * @param key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with
1290
+ * a $, and can only contain alphanumeric characters and punctuation.
1291
+ * @param value - Can be numeric, boolean, a Date object, a string, or an array of strings. Strings are limited to
1292
+ * 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
1293
+ * Passing a null value will remove this custom attribute from the user.
1294
+ * @param merge - Whether the value should be merged with the existing value on the backend. If `false` (default), any existing
1295
+ * attribute will be overwritten. If `true`, existing objects and arrays of objects will be merged. To update an array of objects,
1296
+ * follow the guidelines in our
1297
+ * [public docs](https://www.braze.com/docs/user_guide/data_and_analytics/custom_data/custom_attributes/array_of_objects/#usage-examples).
1298
+ *
1299
+ * @returns {boolean} Whether the update was successfully enqueued.
1300
+ */
1301
+ setCustomUserAttribute(
1302
+ key: string,
1303
+ value:
1304
+ | number
1305
+ | boolean
1306
+ | Date
1307
+ | string
1308
+ | string[]
1309
+ | object
1310
+ | object[]
1311
+ | null,
1312
+ merge?: boolean,
1313
+ ): boolean;
1914
1314
 
1915
1315
  /**
1916
- * Logs that the user clicked the given card. This is done automatically when you use Braze's display module
1917
- * and should only be called if you're bypassing that and manually building the DOM for displaying the cards in
1918
- * your own code.
1316
+ * Sets the date of birth of the user. Alternatively takes in null values for all parameters
1317
+ * to set date of birth to null.
1919
1318
  *
1920
- * @param card - the `Card` object that received a click
1921
- * @param forContentCards - whether to log this as a content cards event (as opposed to the legacy news feed)
1319
+ * @param year
1320
+ * @param month - 1-12
1321
+ * @param day
1922
1322
  *
1923
- * @returns Whether or not the event was successfully logged (to be flushed later).
1323
+ * @returns Whether the update was successfully enqueued.
1924
1324
  */
1925
- export function logCardClick(card: Card, forContentCards?: boolean): boolean;
1325
+ setDateOfBirth(
1326
+ year: number | null,
1327
+ month: number | null,
1328
+ day: number | null,
1329
+ ): boolean;
1926
1330
 
1927
1331
  /**
1928
- * Logs that the user dismissed the given card. This is done automatically when you use Braze's display module
1929
- * and should only be called if you're bypassing that and manually building the DOM for displaying the cards in
1930
- * your own code.
1332
+ * Sets the email address of the user.
1931
1333
  *
1932
- * @param card - the `Card` object that received a dismissal
1334
+ * @param email - Must pass RFC-5322 email address validation. Accepts an explicit null value to
1335
+ * null out attribute.
1933
1336
  *
1934
- * @returns Whether or not the event was successfully logged (to be flushed later).
1337
+ * @returns Whether the update was successfully enqueued.
1935
1338
  */
1936
- export function logCardDismissal(card: Card): boolean;
1339
+ setEmail(email: string | null): boolean;
1937
1340
 
1938
1341
  /**
1939
- * Logs that the user saw the given cards. This is done automatically when you use Braze's display module
1940
- * and should only be called if you're bypassing that and manually building the DOM for displaying the cards in
1941
- * your own code.
1342
+ * Sets whether the user should be sent email campaigns.
1942
1343
  *
1943
- * @param cards - array of `Card` objects that received impressions
1944
- * @param forContentCards - whether to log this as a content cards event (as opposed to the legacy news feed)
1344
+ * @param notificationSubscriptionType - Notification setting (explicitly opted-in, subscribed, or unsubscribed).
1345
+ * See the `NotificationSubscriptionTypes` enum.
1945
1346
  *
1946
- * @returns Whether or not the event was successfully logged (to be flushed later).
1347
+ * @returns Whether the update was successfully enqueued.
1947
1348
  */
1948
- export function logCardImpressions(
1949
- cards: Card[],
1950
- forContentCards?: boolean
1349
+ setEmailNotificationSubscriptionType(
1350
+ notificationSubscriptionType: NotificationSubscriptionTypes,
1951
1351
  ): boolean;
1952
1352
 
1953
1353
  /**
1954
- * A convenient method to log that the user saw the given Content Cards. This method is equivalent to
1955
- * calling [`logCardImpressions` method with `forContentCards` param set to true.
1956
- * This is done automatically when you use Braze's display module and should only be called
1957
- * if you're bypassing that and manually building the DOM for displaying content cards in
1958
- * your own code.
1354
+ * Sets the first name of the user.
1959
1355
  *
1960
- * @param contentCards - array of `Card` objects that received impressions
1356
+ * @param firstName - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1961
1357
  *
1962
- * @returns Whether or not the event was successfully logged (to be flushed later).
1358
+ * @returns Whether the update was successfully enqueued.
1963
1359
  */
1964
- export function logContentCardImpressions(contentCards: Card[]): boolean;
1360
+ setFirstName(firstName: string | null): boolean;
1965
1361
 
1966
1362
  /**
1967
- * A convenient method to log when user clicks on a Content Card. This method is equivalent to
1968
- * calling [`logCardClick` method with `forContentCards` param set to true.
1969
- * This is done automatically when you use Braze's display module and should only be called
1970
- * if you're bypassing that and manually building the DOM for displaying content cards in
1971
- * your own code.
1363
+ * Sets the gender of the user.
1972
1364
  *
1973
- * @param contentCard - the `Card` object that received a click
1365
+ * @param gender - Generally 'm' or 'f'. Accepts an explicit null value to null out attribute. Use `Genders`
1366
+ * enum when setting this value.
1974
1367
  *
1975
- * @returns Whether or not the event was successfully logged (to be flushed later).
1976
- */
1977
- export function logContentCardClick(contentCard: Card): boolean;
1978
-
1979
- /**
1980
- * @deprecated This method has been deprecated and is currently a no-op.
1368
+ * @returns Whether the update was successfully enqueued.
1981
1369
  */
1982
- export function logContentCardsDisplayed(): boolean;
1370
+ setGender(gender: Genders | null): boolean;
1983
1371
 
1984
1372
  /**
1985
- * Reports that the current user performed a custom named event.
1373
+ * Sets the home city for the user.
1986
1374
  *
1987
- * @param eventName - The identifier for the event to track. Value is limited to 255 characters in length,
1988
- * cannot begin with a $, and can only contain alphanumeric characters and punctuation.
1989
- * @param eventProperties - Hash of properties for this event. Keys are limited to 255 characters in length, cannot begin
1990
- * with a $, and can only contain alphanumeric characters and punctuation. Values can be numeric, boolean, Date objects,
1991
- * strings 255 characters or shorter, or nested objects whose values can be numeric, boolean, Date objects, arrays, strings,
1992
- * or null. Total size of event properties cannot exceed 50KB.
1375
+ * @param homeCity - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
1993
1376
  *
1994
- * @returns Whether or not the event was successfully logged (to be flushed later).
1377
+ * @returns Whether the update was successfully enqueued.
1995
1378
  */
1996
- export function logCustomEvent(eventName: string, eventProperties?: object): boolean;
1379
+ setHomeCity(homeCity: string | null): boolean;
1997
1380
 
1998
1381
  /**
1999
- * Logs that the news feed was displayed. This is done automatically when you use Braze's
2000
- * UI and should only be called if you're bypassing that and manually building
2001
- * the class for displaying the cards in your own code.
1382
+ * Sets the language for this user. By default, the user's language is detected automatically
1383
+ * from the browser. If you call this method, Braze will ignore the detected language and use
1384
+ * the language you have provided instead.
1385
+ *
1386
+ * @param language - An [ISO 639-1 Language Code](https://www.w3schools.com/tags/ref_language_codes.asp).
1387
+ * Accepts an explicit null value to null out attribute.
1388
+ *
1389
+ * @returns {boolean} Whether the update was successfully enqueued.
2002
1390
  */
2003
- export function logFeedDisplayed(): void;
1391
+ setLanguage(language: string | null): boolean;
2004
1392
 
2005
1393
  /**
2006
- * Logs that the user clicked the given in-app message button. This is done automatically when the user clicks on
2007
- * a button in a message generated by `showInAppMessage`,
2008
- * and should only be called if you're bypassing that method and manually displaying the message in your own
2009
- * code.
1394
+ * Sets the last known location for the user.
2010
1395
  *
2011
- * @param button - The button clicked
2012
- * @param inAppMessage - The message this button belongs to
1396
+ * @param latitude - The latitude of the user's location in (valid values are between -90 to 90 degrees)
1397
+ * @param longitude - The longitude of the user's location (valid values are between -180 to 180 degrees)
1398
+ * @param accuracy - The accuracy of the user's lat/long in meters.
1399
+ * @param altitude - The altitude of the user's location in meters above or below the WGS 84 reference
1400
+ * ellipsoid.
1401
+ * @param altitudeAccuracy - The accuracy of the user's altitude in meters.
2013
1402
  *
2014
- * @returns Whether or not the event was successfully logged (to be flushed later).
1403
+ * @returns Whether the update was successfully enqueued.
2015
1404
  */
2016
- export function logInAppMessageButtonClick(
2017
- button: InAppMessageButton,
2018
- inAppMessage: InAppMessage
1405
+ setLastKnownLocation(
1406
+ latitude: number,
1407
+ longitude: number,
1408
+ accuracy?: number,
1409
+ altitude?: number,
1410
+ altitudeAccuracy?: number,
2019
1411
  ): boolean;
2020
1412
 
2021
1413
  /**
2022
- * Logs that the user clicked the given in-app message. This is done automatically when the user clicks on a
2023
- * message generated by `showInAppMessage`, and should
2024
- * only be called if you're bypassing that method and manually displaying the message in your own code.
1414
+ * Sets the last name of the user.
2025
1415
  *
2026
- * @param inAppMessage
1416
+ * @param lastName - Limited to 255 characters in length. Accepts an explicit null value to null out attribute.
2027
1417
  *
2028
- * @returns Whether or not the event was successfully logged (to be flushed later).
1418
+ * @returns Whether the update was successfully enqueued.
2029
1419
  */
2030
- export function logInAppMessageClick(inAppMessage: InAppMessage): boolean;
1420
+ setLastName(lastName: string | null): boolean;
2031
1421
 
2032
1422
  /**
2033
- * Logs that the user clicked on a link in an html in-app message. This is done automatically when the user clicks
2034
- * on a message generated by `showInAppMessage`, and should
2035
- * only be called if you're bypassing that method and manually displaying the message in your own code.
1423
+ * Sets the phone number of the user.
2036
1424
  *
2037
- * @param inAppMessage - The message that was clicked
2038
- * @param buttonId - A button id to associate this click with for analytics
2039
- * @param url - The url that was clicked
1425
+ * @param phoneNumber - A phone number is considered valid if it is no more than 255 characters in length and
1426
+ * contains only numbers, whitespace, and the following special characters +.-() Accepts an explicit null value to
1427
+ * null out attribute.
2040
1428
  *
2041
- * @returns Whether or not the event was successfully logged (to be flushed later).
1429
+ * @returns Whether the update was successfully enqueued.
2042
1430
  */
2043
- export function logInAppMessageHtmlClick(
2044
- inAppMessage: HtmlMessage,
2045
- buttonId?: string,
2046
- url?: string
2047
- ): boolean;
1431
+ setPhoneNumber(phoneNumber: string | null): boolean;
2048
1432
 
2049
1433
  /**
2050
- * Logs that the user saw the given in-app message. This is performed automatically when you use `showInAppMessage`,
2051
- * and should only be called if you're bypassing that method and manually displaying the message in your own code.
1434
+ * Sets whether the user should be sent push campaigns.
2052
1435
  *
2053
- * @param inAppMessage
1436
+ * @param notificationSubscriptionType - Notification setting (explicitly opted-in, subscribed, or unsubscribed).
1437
+ * See the `NotificationSubscriptionTypes` enum.
2054
1438
  *
2055
- * @returns Whether or not the event was successfully logged (to be flushed later).
1439
+ * @returns Whether the update was successfully enqueued.
2056
1440
  */
2057
- export function logInAppMessageImpression(
2058
- inAppMessage: InAppMessage | ControlMessage
2059
- ): boolean;
2060
-
2061
- /**
2062
- * Reports that the current user made an in-app purchase. Useful for tracking and segmenting users.
2063
- *
2064
- * @param productId - A string identifier for the product purchased, e.g. an SKU. Value is limited to
2065
- * 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
2066
- * @param price - The price paid. Base units depend on the currency. As an example, USD should be
2067
- * reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen. All provided
2068
- * values will be rounded to two digits with toFixed(2)
2069
- * @param currencyCode - Default USD. Currencies should be represented as an ISO 4217 currency code. Supported
2070
- * currency symbols include: AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF,
2071
- * BMD, BND, BOB, BRL, BSD, BTC, BTN, BWP, BYR, BZD, CAD, CDF, CHF, CLF, CLP, CNY, COP, CRC, CUC, CUP, CVE,
2072
- * CZK, DJF, DKK, DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GGP, GHS, GIP, GMD, GNF, GTQ, GYD,
2073
- * HKD, HNL, HRK, HTG, HUF, IDR, ILS, IMP, INR, IQD, IRR, ISK, JEP, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW,
2074
- * KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRO, MTL,
2075
- * MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR,
2076
- * RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLL, SOS, SRD, STD, SVC, SYP, SZL, THB, TJS, TMT,
2077
- * TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, UYU, UZS, VEF, VND, VUV, WST, XAF, XAG, XAU, XCD, XDR, XOF,
2078
- * XPD, XPF, XPT, YER, ZAR, ZMK, ZMW, and ZWL. Any other provided currency symbol will result in a logged
2079
- * warning and no other action taken by the SDK.
2080
- * @param quantity - Default 1. The quantity of items purchased expressed as a whole number. Must be at least 1
2081
- * and at most 100.
2082
- * @param purchaseProperties - Hash of properties for this purchase. Keys are limited to 255
2083
- * characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
2084
- * Values can be numeric, boolean, Date objects, strings 255 characters or shorter, or nested objects whose values
2085
- * can be numeric, boolean, Date objects, arrays, strings, or null. Total size of purchase properties cannot exceed 50KB.
2086
- *
2087
- * @returns Whether or not the purchase was successfully attached to the session (to be flushed later).
2088
- */
2089
- export function logPurchase(
2090
- productId: string,
2091
- price: number,
2092
- currencyCode?: string,
2093
- quantity?: number,
2094
- purchaseProperties?: object
1441
+ setPushNotificationSubscriptionType(
1442
+ notificationSubscriptionType: NotificationSubscriptionTypes,
2095
1443
  ): boolean;
1444
+ }
2096
1445
 
1446
+ export class InAppMessageButton {
2097
1447
  /**
2098
- * Opens a new session, or resumes the previous session if this browser had activity within the `sessionTimeoutInSeconds` value.
2099
- * When a new session is opened, this refreshes In-App Messages. Content Cards are refreshed automatically if
2100
- * the `subscribeToContentCardsUpdates` has been registered prior to `openSession`. If the user has previously
2101
- * granted the site permission to send push, automatically sends the push registration to the Braze backend.
1448
+ * Represents a button on an `ModalMessage` or `FullScreenMessage`.
2102
1449
  *
2103
- * Be sure to call `openSession` at the end of your initialization code section, after any calls to `changeUser` or subscribing to Content Cards,
2104
- * In-App Message, and Feature Flag updates. Calling `openSession` before `changeUser` may result in a second session start event.
1450
+ * @param text - The text to display on this button
1451
+ * @param backgroundColor - The background color for this button. Hex value with opacity (e.g.
1452
+ * 0xff00ff00 is opaque green).
1453
+ * @param textColor - The color for the text of this button. Hex value with opacity (e.g.
1454
+ * 0xff00ff00 is opaque green).
1455
+ * @param borderColor - The color for the border of this button. Hex value with opacity (e.g.
1456
+ * 0xff00ff00 is opaque green).
1457
+ * @param clickAction - Where the user should be brought when clicking on this button. See the
1458
+ * `ClickAction` enum.
1459
+ * @param uri - If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1460
+ * user clicks on this button.
1461
+ * @param id - The id for this button. Used for analytics.
2105
1462
  */
2106
- export function openSession(): void;
1463
+ constructor(
1464
+ text: string,
1465
+ backgroundColor?: number,
1466
+ textColor?: number,
1467
+ borderColor?: number,
1468
+ clickAction?: ClickAction,
1469
+ uri?: string,
1470
+ id?: number,
1471
+ );
2107
1472
 
2108
- /**
2109
- * Register this browser environment to receive web push for this user. Supports browsers which implement the
2110
- * [W3C Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) (browsers in which
2111
- * `isPushSupported` returns true). If push is supported and the user is not already subscribed,
2112
- * this method will cause the browser to immediately request push permission from the user.
2113
- *
2114
- * In order to properly use this feature, there are some integration steps required on your end:
2115
- *
2116
- * - Your site must be https
2117
- * - Create a `service-worker.js` file with the content below and place it in the root directory of your website:
2118
- *
2119
- * ```
2120
- * self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.9/service-worker.js');
2121
- * ```
2122
- *
2123
- * For more details, see [Our Product Documentation](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/push_notifications/integration).
2124
- *
2125
- * @param successCallback - When the user subscribes to push successfully this callback will be
2126
- * invoked with the user's endpoint, public key, and user auth key (endpoint, publicKey, userAuth).
2127
- * @param deniedCallback - If push permission is denied or an error is encountered while registering, this callback will
2128
- * be invoked. If the denial is temporary, it will be invoked with a parameter of `true` - otherwise it will be invoked
2129
- * with a parameter of `false`.
2130
- */
2131
- export function requestPushPermission(
2132
- successCallback?: (
2133
- endpoint: string,
2134
- publicKey: string,
2135
- userAuth: string
2136
- ) => void,
2137
- deniedCallback?: (temporaryDenial: boolean) => void
2138
- ): void;
1473
+ /** The text to display on this button */
1474
+ text: string;
2139
1475
 
2140
1476
  /**
2141
- * Remove all event subscriptions.
1477
+ * The background color for this button. Hex value with opacity (e.g.
1478
+ * 0xff00ff00 is opaque green).
2142
1479
  */
2143
- export function removeAllSubscriptions(): void;
1480
+ backgroundColor: number;
2144
1481
 
2145
1482
  /**
2146
- * Remove an event subscription that you previously subscribed to.
2147
- *
2148
- * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
2149
- * you initially used to create it.
2150
- */
2151
- export function removeSubscription(subscriptionGuid: string): void;
2152
-
2153
- /**
2154
- * Requests an immediate refresh of content cards from Braze servers. By default, content cards are refreshed when
2155
- * a new session opens (see 'openSession` for more details), and when the user refreshes content cards manually via
2156
- * the refresh button. If you want to refresh content cards from the server at another time you must call this function.
2157
- *
2158
- * @param successCallback - Callback that is invoked when the content cards refresh request has been successfully completed.
2159
- * You should use `subscribeToContentCardsUpdates` to be notified of new cards. This callback is useful for determining when
2160
- * a request has completed regardless of whether new cards were returned.
2161
- * @param errorCallback - Callback that is invoked when an error occurs during the refresh.
1483
+ * The color for the text of this button. Hex value with opacity (e.g.
1484
+ * 0xff00ff00 is opaque green).
2162
1485
  */
2163
- export function requestContentCardsRefresh(successCallback?: () => void, errorCallback?: () => void): void;
1486
+ textColor: number;
2164
1487
 
2165
1488
  /**
2166
- * Requests an immediate refresh of the news feed from Braze servers. By default, the news feed is refreshed on
2167
- * `showFeed` (when stale - see
2168
- * `showFeed` for details). If you want to refresh the feed from the
2169
- * server at another time you must call this function. Results of this refresh are reported asynchronously to
2170
- * subscriptions created via 'subscribeToFeedUpdates` .
1489
+ * The color for the border of this button. Hex value with opacity (e.g.
1490
+ * 0xff00ff00 is opaque green).
2171
1491
  */
2172
- export function requestFeedRefresh(): void;
1492
+ borderColor: number;
2173
1493
 
2174
1494
  /**
2175
- * Requests an immediate refresh of feature flags from Braze servers. By default, feature flags are refreshed when
2176
- * a new session starts. If you want to refresh feature flags from the server at another time you must call this function.
2177
- *
2178
- * @param successCallback - Callback that is invoked when the feature flags refresh request has been successfully completed.
2179
- * This callback is useful for determining when a request has completed regardless of whether new feature flags were returned.
2180
- * @param errorCallback - Callback that is invoked when an error occurs during the refresh.
1495
+ * Where the user should be brought when clicking on this button. See the
1496
+ * `ClickAction` enum.
2181
1497
  */
2182
- export function refreshFeatureFlags(successCallback?: () => void, errorCallback?: () => void): void;
1498
+ clickAction: ClickAction;
2183
1499
 
2184
1500
  /**
2185
- * By default, data logged to Braze through the SDK is queued locally (in HTML 5 localStorage when available, and
2186
- * in memory otherwise) and sent to Braze's servers asynchronously on a regular interval (10 seconds when localStorage is available
2187
- * and not routinely cleared due to browser privacy features, otherwise 3 seconds). This is done to optimize network usage and
2188
- * provide resiliency against network or server outages. This method bypasses the interval and immediately flushes queued data.
2189
- *
2190
- * @param callback - Invoked when the flush completes with a boolean parameter that returns
2191
- * whether or not the flush was successful. If the flush is unsuccessful, pending data will be
2192
- * flushed during the next successful flush.
1501
+ * If ```clickAction``` is `ClickAction`.URI, the URI to follow when the
1502
+ * user clicks on this button.
2193
1503
  */
2194
- export function requestImmediateDataFlush(
2195
- callback?: (success: boolean) => void
2196
- ): void;
1504
+ uri?: string;
2197
1505
 
2198
- /**
2199
- * Removes the cookie set by `disableSDK`, causing subsequent calls to the Braze Web SDK to function. You must
2200
- * call `initialize` after calling this method before calling subsequent methods.
2201
- */
2202
- export function enableSDK(): void;
1506
+ /** The id for this button. Used for analytics. */
1507
+ id?: number;
2203
1508
 
2204
- /**
2205
- * Getter method to determine if the SDK is disabled based on whether the cookie set by `disableSdk` exists
2206
- */
2207
- export function isDisabled(): boolean;
1509
+ /** Remove all event subscriptions from this button. */
1510
+ removeAllSubscriptions(): void;
2208
1511
 
2209
1512
  /**
2210
- * By default, Braze logs to the browser console. Call this method to set a custom log action and enable debug-level log statements.
1513
+ * Remove an event subscription that you previously subscribed to.
2211
1514
  *
2212
- * @param loggerFunction - A function to invoke with log messages. Should accept a single string
2213
- * parameter for message.
1515
+ * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
1516
+ * you initially used to create it.
2214
1517
  */
2215
- export function setLogger(loggerFunction: (message: string) => void): void;
1518
+ removeSubscription(subscriptionGuid: string): void;
2216
1519
 
2217
1520
  /**
2218
- * Sets the signature to be used to authenticate the current user. You can also set the signature when calling `changeUser`.
2219
- * This signature will only have an effect if the `enableSdkAuthentication` initialization option is set to true.
1521
+ * Subscribe to receive click events on this button. The subscriber callback will be called whenever this button is
1522
+ * clicked by the user.
2220
1523
  *
2221
- * @param signature - The signature to add to network requests to authenticate the current user.
1524
+ * @param subscriber - The callback function to receive click events. This function will be invoked with
1525
+ * no arguments when this button records a click.
2222
1526
  *
2223
- * @returns Whether or not the signature is valid.
1527
+ * @returns The identifier of the subscription created. This can be passed to `removeSubscription`
1528
+ * to cancel the subscription. Returns null if the subscriber passed is not a function.
2224
1529
  */
2225
- export function setSdkAuthenticationSignature(signature: string): boolean;
1530
+ subscribeToClickedEvent(subscriber: () => void): string | null;
1531
+ }
1532
+
1533
+ export interface FeatureFlagStringProperty {
1534
+ type: "string";
1535
+ value: string;
1536
+ }
1537
+
1538
+ export interface FeatureFlagNumberProperty {
1539
+ type: "number";
1540
+ value: number;
1541
+ }
1542
+
1543
+ export interface FeatureFlagBooleanProperty {
1544
+ type: "boolean";
1545
+ value: boolean;
1546
+ }
2226
1547
 
1548
+ export class FeatureFlag {
1549
+ /** Indicates whether or not this feature flag is enabled. */
1550
+ enabled: boolean;
1551
+
1552
+ /** Properties of this feature flag, listed as key-value pairs. */
1553
+ properties: Partial<
1554
+ Record<
1555
+ string,
1556
+ | FeatureFlagStringProperty
1557
+ | FeatureFlagNumberProperty
1558
+ | FeatureFlagBooleanProperty
1559
+ >
1560
+ >;
1561
+
1562
+ /** The ID for this feature flag. */
1563
+ id: string;
1564
+
1565
+ /**
1566
+ * Get value of a feature flag property of type string.
1567
+ *
1568
+ * @param key - The key of the property.
1569
+ *
1570
+ * @returns The value of the property if the key is found and is of type string.
1571
+ * If the key is not found or if there is a type mismatch, this method will return a null.
1572
+ */
1573
+ getStringProperty(key: string): string | null;
1574
+
1575
+ /**
1576
+ * Get value of a feature flag property of type number.
1577
+ *
1578
+ * @param key - The key of the property.
1579
+ *
1580
+ * @returns The value of the property if the key is found and is of type number.
1581
+ * If the key is not found or if there is a type mismatch, this method will return a null.
1582
+ */
1583
+ getNumberProperty(key: string): number | null;
1584
+
1585
+ /**
1586
+ * Get value of a feature flag property of type boolean.
1587
+ *
1588
+ * @param key - The key of the property.
1589
+ *
1590
+ * @returns The value of the property if the key is found and is of type boolean.
1591
+ * If the key is not found or if there is a type mismatch, this method will return a null.
1592
+ */
1593
+ getBooleanProperty(key: string): boolean | null;
1594
+ }
1595
+
1596
+ /**
1597
+ * Automatically display in-app messages when they are triggered. This method should be called before
1598
+ * calling `openSession`.
1599
+ *
1600
+ * @returns The identifier of the subscription created. This can be passed to
1601
+ * `removeSubscription` to cancel the subscription.
1602
+ */
1603
+ export function automaticallyShowInAppMessages(): string;
1604
+
1605
+ /**
1606
+ * Destroy any Braze news feed currently showing. This method will appropriately clean up any retained resources
1607
+ * and also display the hiding animation, and so should be used instead of manually removing feed html from the
1608
+ * DOM.
1609
+ */
1610
+ export function destroyFeed(): void;
1611
+
1612
+ /**
1613
+ * Hide any Braze content cards currently showing in the parent node, or if none is provided, any content cards in the page.
1614
+ * This method will appropriately clean up any retained resources and also display the hiding animation, and so should be
1615
+ * used instead of manually removing content cards HTML from the DOM.
1616
+ *
1617
+ * @param parentNode - The HTML node that denotes the parent of the content cards to be hidden. If null/undefined, all content
1618
+ * cards on the page will be hidden.
1619
+ */
1620
+ export function hideContentCards(parentNode?: Element | null): void;
1621
+
1622
+ /**
1623
+ * Display the user's content cards.
1624
+ *
1625
+ * @param parentNode - The HTML node to render the content cards into. If null/undefined, the content
1626
+ * cards will be rendered in fixed position over the right-hand side of the page and appended to the `<body>`
1627
+ * node. If the parent node already has a Braze content cards view as a direct descendant, the existing content
1628
+ * cards will be replaced.
1629
+ * @param filterFunction - A filter/sort function for cards displayed in this view. Invoked with the
1630
+ * array of `Card` objects, sorted by {pinned, date}. Expected to return an array of sorted
1631
+ * `Card` objects to render for this user. If omitted, all cards will be displayed.
1632
+ */
1633
+ export function showContentCards(
1634
+ parentNode?: Element | null,
1635
+ filterFunction?: (cards: Card[]) => Card[],
1636
+ ): void;
1637
+
1638
+ /**
1639
+ * Display the user's news feed.
1640
+ *
1641
+ * @param parentNode - The HTML node to render the news feed into. If null/undefined, the feed will be
1642
+ * rendered in fixed position over the right-hand side of the page and appended to the `<body>` node. If the
1643
+ * parent node already has an Braze news feed as a direct descendant, the existing feed will be replaced.
1644
+ * @param cards - A static set of cards to Each item in this Array should be a `Card`
1645
+ * descendant. If this parameter is null/undefined, all unexpired cards from the last news feed refresh will be
1646
+ * used automatically, a feed refresh will be kicked off automatically if the cached cards are more than 1 minute
1647
+ * old, and the feed will automatically update when new cards are received while it is still showing. If you
1648
+ * provide an explicit set of cards by using this parameter, no action will be taken when new cards are received,
1649
+ * and you must subscribe to feed updates yourself with `subscribeToFeedUpdates` and request updates with
1650
+ * `requestFeedRefresh` if you want to update this feed with new cards.
1651
+ * @param allowedCategories - A set of categories to filter cards to. Each item in this Array should be a
1652
+ * card category as set in the Braze dashboard. If omitted, all cards will be displayed.
1653
+ */
1654
+ export function showFeed(
1655
+ parentNode?: Element | null,
1656
+ cards?: Card[] | null,
1657
+ allowedCategories?: string[],
1658
+ ): void;
1659
+
1660
+ /**
1661
+ * Display a given in-app message.
1662
+ *
1663
+ * @param inAppMessage - The message to
1664
+ * @param parentNode - The HTML node to render the in-app message into. If null/undefined, the message
1665
+ * will be rendered appended within the `<body>` node.
1666
+ * @param onDisplayCallback - Optional callback to invoke once the message is on the screen.
1667
+ *
1668
+ * @returns Whether or not the message was displayed (or, in the case of control messages, logged to
1669
+ * Braze servers).
1670
+ */
1671
+ export function showInAppMessage(
1672
+ inAppMessage: InAppMessage | ControlMessage,
1673
+ parentNode?: Element | null,
1674
+ onDisplayCallback?: () => void,
1675
+ ): boolean;
1676
+
1677
+ /**
1678
+ * Defers the display of given in-app message for a future pageload.
1679
+ * The deferred in-app message can be retrieved by calling `getDeferredInAppMessage`,
1680
+ * and displayed using `showInAppMessage`.
1681
+ * Deferring an in-app message will overwrite any previously deferred in-app message.
1682
+ *
1683
+ * Note: Be sure to subscribe to clicked / dismissed events on this in-app message only after retrieving it using `getDeferredInAppMessage`.
1684
+ * Any subscriptions made before calling `deferInAppMessage` will not be persisted.
1685
+ * Also note that the in-app message deferred here will be cleared out when in-app message triggers have been refreshed from the Braze backend.
1686
+ *
1687
+ * @param inAppMessage - The message to defer for later display.
1688
+ *
1689
+ * @returns Whether or not the message was successfully deferred.
1690
+ * Returns undefined if the SDK has not been initialized.
1691
+ */
1692
+ export function deferInAppMessage(
1693
+ inAppMessage: InAppMessage,
1694
+ ): boolean | undefined;
1695
+
1696
+ /**
1697
+ * Retrieves the in-app message that was most recently deferred for display with `deferInAppMessage`.
1698
+ *
1699
+ * Note: Retrieving the deferred in-app message here will clear it from storage.
1700
+ *
1701
+ * @returns The deferred in-app message if it exists, or returns null.
1702
+ * Returns undefined if the SDK has not been initialized.
1703
+ */
1704
+ export function getDeferredInAppMessage(): InAppMessage | null | undefined;
1705
+
1706
+ /**
1707
+ * Toggle the display of Braze content cards, showing them if they are not shown, and hiding them if they are. If you
1708
+ * wish to display multiple content cards feeds on a page simultaneously, you should use `showContentCards` and `hideContentCards`
1709
+ * to show/hide each feed individually instead of this method.
1710
+ *
1711
+ * @param parentNode - The HTML node to render the content cards into. If null/undefined, the content
1712
+ * cards will be rendered in fixed position over the right-hand side of the page and appended to the `<body>`
1713
+ * node. If the parent node already has a Braze content cards view as a direct descendant, the existing content
1714
+ * cards will be replaced.
1715
+ * @param filterFunction - A filter/sort function for cards displayed in this view. Invoked with the
1716
+ * array of `Card` objects, sorted by {pinned, date}. Expected to return an array of sorted
1717
+ * `Card` objects to render for this user. If omitted, all cards will be displayed.
1718
+ */
1719
+ export function toggleContentCards(
1720
+ parentNode?: Element | null,
1721
+ filterFunction?: (cards: Card[]) => Card[],
1722
+ ): void;
1723
+
1724
+ /**
1725
+ * Toggle the Braze news feed, creating it if it does not exist, and destroying it if it does.
1726
+ *
1727
+ * @param parentNode - The HTML node to render the news feed into. If null/undefined, the feed will be
1728
+ * rendered in fixed position over the right-hand side of the page and appended to the `<body>` node. If the
1729
+ * parent node already has an Braze news feed as a direct descendant, the existing feed will be replaced.
1730
+ * @param cards - A static set of cards to Each item in this Array should be a `Card`
1731
+ * descendant. If this parameter is null/undefined, all unexpired cards from the last news feed refresh will be
1732
+ * used automatically, a feed refresh will be kicked off automatically if the cached cards are more than 1 minute
1733
+ * old, and the feed will automatically update when new cards are received while it is still showing. If you
1734
+ * provide an explicit set of cards by using this parameter, no action will be taken when new cards are received,
1735
+ * and you must subscribe to feed updates yourself with `subscribeToFeedUpdates` and request updates with
1736
+ * `requestFeedRefresh` if you want to update this feed with new cards.
1737
+ * @param allowedCategories - A set of categories to filter cards to. Each item in this Array should be a
1738
+ * card category as set in the Braze dashboard. If omitted, all cards will be displayed.
1739
+ */
1740
+ export function toggleFeed(
1741
+ parentNode?: Element | null,
1742
+ cards?: Card[] | null,
1743
+ allowedCategories?: string[],
1744
+ ): void;
1745
+
1746
+ /**
1747
+ * When a user first uses Braze on a device they are considered "anonymous". Use this method to identify a user
1748
+ * with a unique ID, which enables the following:
1749
+ *
1750
+ * - If the same user is identified on another device, their user profile, usage history and event history will
1751
+ * be shared across devices.
1752
+ * - If your app is used on the same browser by multiple people, you can assign each of them a unique identifier
1753
+ * to track them separately. Only the most recent user on a particular browser will receive push
1754
+ * notifications and in-app messages.
1755
+ *
1756
+ * When you request a user switch (which is any call to changeUser where the new user ID is not the same as the
1757
+ * existing user ID), the current session for the previous user (anonymous or not) is automatically ended and
1758
+ * a new session is started. Similarly, following a call to changeUser, any events which fire are guaranteed to
1759
+ * be for the new user -- if an in-flight server request completes for the old user after the user switch no
1760
+ * events will fire, so you do not need to worry about filtering out events from Braze for old users.
1761
+ *
1762
+ * Additionally, if you identify a user which has never been identified on another device, the entire history of
1763
+ * that user as an "anonymous" user on this device will be preserved and associated with the newly identified
1764
+ * user. However, if you identify a user which *has* been identified in another app, any history which was
1765
+ * already flushed to the server for the anonymous user on this device will become orphaned and will not be
1766
+ * associated with any future users. These orphaned users are not considered in your user counts and will not
1767
+ * be messaged.
1768
+ *
1769
+ * Note: Once you identify a user, you cannot revert to the "anonymous" user. The transition from anonymous to
1770
+ * identified tracking is only allowed once because the initial anonymous user receives special treatment to
1771
+ * allow for preservation of their history. As a result, we recommend against changing the user ID just because
1772
+ * your app has entered a "logged out" state because it makes you unable to target the previously logged out user
1773
+ * with re-engagement campaigns. If you anticipate multiple users on the same device, but only want to target one
1774
+ * of them when your app is in a logged out state, we recommend separately keeping track of the user ID you want
1775
+ * to target while logged out and switching back to that user ID as part of your app's logout process.
1776
+ *
1777
+ * @param userId - A unique identifier for this user. Limit 997 bytes.
1778
+ * These User IDs should be private and not easily guessable (e.g. not a plain email address or username).
1779
+ * @param signature - An encrypted signature to be used to authenticate the current user. You can update the signature
1780
+ * using the `setSdkAuthenticationSignature` method. This signature will only have an effect if the `enableSdkAuthentication`
1781
+ * initialization option is set to true.
1782
+ */
1783
+ export function changeUser(userId: string, signature?: string): void;
1784
+
1785
+ /**
1786
+ * Destroys this `braze` instance, destroying all subscription callbacks and releasing member variables which
1787
+ * retain memory.
1788
+ */
1789
+ export function destroy(): void;
1790
+
1791
+ /**
1792
+ * Get all currently available cards from the last content cards refresh.
1793
+ *
1794
+ * @returns - A `ContentCards` object which includes all currently available
1795
+ * `Card` objects from the last content cards refresh.
1796
+ */
1797
+ export function getCachedContentCards(): ContentCards;
1798
+
1799
+ /**
1800
+ * Get all unexpired cards from the last news feed refresh.
1801
+ *
1802
+ * @returns - A `Feed` object which includes all unexpired `Card` objects from the last
1803
+ * news feed refresh.
1804
+ */
1805
+ export function getCachedFeed(): Feed;
1806
+
1807
+ /**
1808
+ * Retrieves the 'device id,' a randomly generated ID that is stored on the browser.
1809
+ * This ID resets for private browsing sessions and when website data is cleared. For example:
1810
+ *
1811
+ * ```
1812
+ * console.log('The device id is ' + braze.getDeviceId());
1813
+ * ```
1814
+ */
1815
+ export function getDeviceId(): string | undefined;
1816
+ /**
1817
+ * Asynchronously retrieves the 'device id,' a randomly generated ID that is stored on the browser.
1818
+ * This ID resets for private browsing sessions and when website data is cleared. For example:
1819
+ *
1820
+ * ```
1821
+ * braze.getDeviceId(function(deviceId) {
1822
+ * console.log('The device id is ' + deviceId);
1823
+ * });
1824
+ * ```
1825
+ * @deprecated - The getDeviceId callback is deprecated. Access the method's return value directly instead.
1826
+ * @param callback - Asynchronous callback - this will be invoked with the deviceId.
1827
+ */
1828
+ export function getDeviceId(callback: (deviceId: string) => void): void;
1829
+
1830
+ /**
1831
+ * @returns The user currently being tracked by Braze, used for querying the tracked user id and setting
1832
+ * user attributes. Should only be accessed via the `getUser` function. Returns undefined if the
1833
+ * SDK has not been initialized.
1834
+ */
1835
+ export function getUser(): User | undefined;
1836
+
1837
+ /**
1838
+ * Initializes this `braze` instance with your API key. This method must be called before other Braze methods are
1839
+ * invoked, and is part of the default loading snippets. Subsequent calls will be ignored until 'destroy`
1840
+ * is called.
1841
+ *
1842
+ * @param apiKey - Your app's Braze API Key. Your API keys can be found
1843
+ * [here](https://dashboard.braze.com/app_settings/app_settings).
1844
+ * @param options - Configuration options. See `InitializationOptions` for supported options.
1845
+ *
1846
+ * @returns - Whether or not the `braze` instance has been successfully initialized.
1847
+ * Reasons for returning false include a missing API key/base URL, user opt out, and ignored crawler bot activity.
1848
+ */
1849
+ export function initialize(
1850
+ apiKey: string,
1851
+ options: InitializationOptions,
1852
+ ): boolean;
1853
+
1854
+ /**
1855
+ * @returns Whether or not the user has blocked push. If the user has blocked push, they cannot be
1856
+ * prompted to register again, and must manually remove the block in order to receive push.
1857
+ * Returns undefined if the SDK has not been initialized.
1858
+ */
1859
+ export function isPushBlocked(): boolean | undefined;
1860
+
1861
+ /**
1862
+ * Tests whether the user has given this browser push permission (they may still be unsubscribed from push via
1863
+ * `User.setPushNotificationSubscriptionType`). A true value essentially means that
1864
+ * `requestPushPermission` may be called without the user being prompted. Useful for migrating existing
1865
+ * non-Braze push registrations to Braze.
1866
+ *
1867
+ * @returns Whether or not the user has granted push permission. If this returns true,
1868
+ * `requestPushPermission` may be called without the user being prompted. If this returns false,
1869
+ * `requestPushPermission` may prompt the user (if `isPushSupported` returns true) or do
1870
+ * nothing (if `isPushSupported` returns false). Returns undefined if the SDK has not been initialized.
1871
+ */
1872
+ export function isPushPermissionGranted(): boolean | undefined;
1873
+
1874
+ /**
1875
+ * The [W3C Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) is partially supported
1876
+ * across the browser landscape. This method allows you to programmatically determine whether push is supported
1877
+ * in the current browser, and whether to show push-related user class elements to the user.
1878
+ *
1879
+ * @returns Whether or not push is supported in this environment. Returns undefined if the SDK has not been initialized.
1880
+ */
1881
+ export function isPushSupported(): boolean | undefined;
1882
+
1883
+ /**
1884
+ * Logs that the user clicked the given card. This is done automatically when you use Braze's display module
1885
+ * and should only be called if you're bypassing that and manually building the DOM for displaying the cards in
1886
+ * your own code.
1887
+ *
1888
+ * @param card - the `Card` object that received a click
1889
+ * @param forContentCards - whether to log this as a content cards event (as opposed to the legacy news feed)
1890
+ *
1891
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1892
+ */
1893
+ export function logCardClick(card: Card, forContentCards?: boolean): boolean;
1894
+
1895
+ /**
1896
+ * Logs that the user dismissed the given card. This is done automatically when you use Braze's display module
1897
+ * and should only be called if you're bypassing that and manually building the DOM for displaying the cards in
1898
+ * your own code.
1899
+ *
1900
+ * @param card - the `Card` object that received a dismissal
1901
+ *
1902
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1903
+ */
1904
+ export function logCardDismissal(card: Card): boolean;
1905
+
1906
+ /**
1907
+ * Logs that the user saw the given cards. This is done automatically when you use Braze's display module
1908
+ * and should only be called if you're bypassing that and manually building the DOM for displaying the cards in
1909
+ * your own code.
1910
+ *
1911
+ * @param cards - array of `Card` objects that received impressions
1912
+ * @param forContentCards - whether to log this as a content cards event (as opposed to the legacy news feed)
1913
+ *
1914
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1915
+ */
1916
+ export function logCardImpressions(
1917
+ cards: Card[],
1918
+ forContentCards?: boolean,
1919
+ ): boolean;
1920
+
1921
+ /**
1922
+ * A convenient method to log that the user saw the given Content Cards. This method is equivalent to
1923
+ * calling [`logCardImpressions` method with `forContentCards` param set to true.
1924
+ * This is done automatically when you use Braze's display module and should only be called
1925
+ * if you're bypassing that and manually building the DOM for displaying content cards in
1926
+ * your own code.
1927
+ *
1928
+ * @param contentCards - array of `Card` objects that received impressions
1929
+ *
1930
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1931
+ */
1932
+ export function logContentCardImpressions(contentCards: Card[]): boolean;
1933
+
1934
+ /**
1935
+ * A convenient method to log when user clicks on a Content Card. This method is equivalent to
1936
+ * calling [`logCardClick` method with `forContentCards` param set to true.
1937
+ * This is done automatically when you use Braze's display module and should only be called
1938
+ * if you're bypassing that and manually building the DOM for displaying content cards in
1939
+ * your own code.
1940
+ *
1941
+ * @param contentCard - the `Card` object that received a click
1942
+ *
1943
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1944
+ */
1945
+ export function logContentCardClick(contentCard: Card): boolean;
1946
+
1947
+ /**
1948
+ * Reports that the current user performed a custom named event.
1949
+ *
1950
+ * @param eventName - The identifier for the event to track. Value is limited to 255 characters in length,
1951
+ * cannot begin with a $, and can only contain alphanumeric characters and punctuation.
1952
+ * @param eventProperties - Hash of properties for this event. Keys are limited to 255 characters in length, cannot begin
1953
+ * with a $, and can only contain alphanumeric characters and punctuation. Values can be numeric, boolean, Date objects,
1954
+ * strings 255 characters or shorter, or nested objects whose values can be numeric, boolean, Date objects, arrays, strings,
1955
+ * or null. Total size of event properties cannot exceed 50KB.
1956
+ *
1957
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1958
+ */
1959
+ export function logCustomEvent(
1960
+ eventName: string,
1961
+ eventProperties?: object,
1962
+ ): boolean;
1963
+
1964
+ /**
1965
+ * Logs that the news feed was displayed. This is done automatically when you use Braze's
1966
+ * UI and should only be called if you're bypassing that and manually building
1967
+ * the class for displaying the cards in your own code.
1968
+ */
1969
+ export function logFeedDisplayed(): void;
1970
+
1971
+ /**
1972
+ * Logs that the user clicked the given in-app message button. This is done automatically when the user clicks on
1973
+ * a button in a message generated by `showInAppMessage`,
1974
+ * and should only be called if you're bypassing that method and manually displaying the message in your own
1975
+ * code.
1976
+ *
1977
+ * @param button - The button clicked
1978
+ * @param inAppMessage - The message this button belongs to
1979
+ *
1980
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1981
+ */
1982
+ export function logInAppMessageButtonClick(
1983
+ button: InAppMessageButton,
1984
+ inAppMessage: InAppMessage,
1985
+ ): boolean;
1986
+
1987
+ /**
1988
+ * Logs that the user clicked the given in-app message. This is done automatically when the user clicks on a
1989
+ * message generated by `showInAppMessage`, and should
1990
+ * only be called if you're bypassing that method and manually displaying the message in your own code.
1991
+ *
1992
+ * @param inAppMessage
1993
+ *
1994
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1995
+ */
1996
+ export function logInAppMessageClick(inAppMessage: InAppMessage): boolean;
1997
+
1998
+ /**
1999
+ * Logs that the user clicked on a link in an html in-app message. This is done automatically when the user clicks
2000
+ * on a message generated by `showInAppMessage`, and should
2001
+ * only be called if you're bypassing that method and manually displaying the message in your own code.
2002
+ *
2003
+ * @param inAppMessage - The message that was clicked
2004
+ * @param buttonId - A button id to associate this click with for analytics
2005
+ * @param url - The url that was clicked
2006
+ *
2007
+ * @returns Whether or not the event was successfully logged (to be flushed later).
2008
+ */
2009
+ export function logInAppMessageHtmlClick(
2010
+ inAppMessage: HtmlMessage,
2011
+ buttonId?: string,
2012
+ url?: string,
2013
+ ): boolean;
2014
+
2015
+ /**
2016
+ * Logs that the user saw the given in-app message. This is performed automatically when you use `showInAppMessage`,
2017
+ * and should only be called if you're bypassing that method and manually displaying the message in your own code.
2018
+ *
2019
+ * @param inAppMessage
2020
+ *
2021
+ * @returns Whether or not the event was successfully logged (to be flushed later).
2022
+ */
2023
+ export function logInAppMessageImpression(
2024
+ inAppMessage: InAppMessage | ControlMessage,
2025
+ ): boolean;
2026
+
2027
+ /**
2028
+ * Reports that the current user made an in-app purchase. Useful for tracking and segmenting users.
2029
+ *
2030
+ * @param productId - A string identifier for the product purchased, e.g. an SKU. Value is limited to
2031
+ * 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
2032
+ * @param price - The price paid. Base units depend on the currency. As an example, USD should be
2033
+ * reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen. All provided
2034
+ * values will be rounded to two digits with toFixed(2)
2035
+ * @param currencyCode - Default USD. Currencies should be represented as an ISO 4217 currency code. Supported
2036
+ * currency symbols include: AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF,
2037
+ * BMD, BND, BOB, BRL, BSD, BTC, BTN, BWP, BYR, BZD, CAD, CDF, CHF, CLF, CLP, CNY, COP, CRC, CUC, CUP, CVE,
2038
+ * CZK, DJF, DKK, DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GGP, GHS, GIP, GMD, GNF, GTQ, GYD,
2039
+ * HKD, HNL, HRK, HTG, HUF, IDR, ILS, IMP, INR, IQD, IRR, ISK, JEP, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW,
2040
+ * KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRO, MTL,
2041
+ * MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR,
2042
+ * RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLL, SOS, SRD, STD, SVC, SYP, SZL, THB, TJS, TMT,
2043
+ * TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, UYU, UZS, VEF, VND, VUV, WST, XAF, XAG, XAU, XCD, XDR, XOF,
2044
+ * XPD, XPF, XPT, YER, ZAR, ZMK, ZMW, and ZWL. Any other provided currency symbol will result in a logged
2045
+ * warning and no other action taken by the SDK.
2046
+ * @param quantity - Default 1. The quantity of items purchased expressed as a whole number. Must be at least 1
2047
+ * and at most 100.
2048
+ * @param purchaseProperties - Hash of properties for this purchase. Keys are limited to 255
2049
+ * characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.
2050
+ * Values can be numeric, boolean, Date objects, strings 255 characters or shorter, or nested objects whose values
2051
+ * can be numeric, boolean, Date objects, arrays, strings, or null. Total size of purchase properties cannot exceed 50KB.
2052
+ *
2053
+ * @returns Whether or not the purchase was successfully attached to the session (to be flushed later).
2054
+ */
2055
+ export function logPurchase(
2056
+ productId: string,
2057
+ price: number,
2058
+ currencyCode?: string,
2059
+ quantity?: number,
2060
+ purchaseProperties?: object,
2061
+ ): boolean;
2062
+
2063
+ /**
2064
+ * Opens a new session, or resumes the previous session if this browser had activity within the `sessionTimeoutInSeconds` value.
2065
+ * When a new session is opened, this refreshes In-App Messages. Content Cards are refreshed automatically if
2066
+ * the `subscribeToContentCardsUpdates` has been registered prior to `openSession`. If the user has previously
2067
+ * granted the site permission to send push, automatically sends the push registration to the Braze backend.
2068
+ *
2069
+ * Be sure to call `openSession` at the end of your initialization code section, after any calls to `changeUser` or subscribing to Content Cards,
2070
+ * In-App Message, and Feature Flag updates. Calling `openSession` before `changeUser` may result in a second session start event.
2071
+ */
2072
+ export function openSession(): void;
2073
+
2074
+ /**
2075
+ * Register this browser environment to receive web push for this user. Supports browsers which implement the
2076
+ * [W3C Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) (browsers in which
2077
+ * `isPushSupported` returns true). If push is supported and the user is not already subscribed,
2078
+ * this method will cause the browser to immediately request push permission from the user.
2079
+ *
2080
+ * In order to properly use this feature, there are some integration steps required on your end:
2081
+ *
2082
+ * - Your site must be https
2083
+ * - Create a `service-worker.js` file with the content below and place it in the root directory of your website:
2084
+ *
2085
+ * ```
2086
+ * self.importScripts('https://js.appboycdn.com/web-sdk-develop/5.0/service-worker.js');
2087
+ * ```
2088
+ *
2089
+ * For more details, see [Our Product Documentation](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/push_notifications/integration).
2090
+ *
2091
+ * @param successCallback - When the user subscribes to push successfully this callback will be
2092
+ * invoked with the user's endpoint, public key, and user auth key (endpoint, publicKey, userAuth).
2093
+ * @param deniedCallback - If push permission is denied or an error is encountered while registering, this callback will
2094
+ * be invoked. If the denial is temporary, it will be invoked with a parameter of `true` - otherwise it will be invoked
2095
+ * with a parameter of `false`.
2096
+ */
2097
+ export function requestPushPermission(
2098
+ successCallback?: (
2099
+ endpoint: string,
2100
+ publicKey: string,
2101
+ userAuth: string,
2102
+ ) => void,
2103
+ deniedCallback?: (temporaryDenial: boolean) => void,
2104
+ ): void;
2105
+
2106
+ /**
2107
+ * Remove all event subscriptions.
2108
+ */
2109
+ export function removeAllSubscriptions(): void;
2110
+
2111
+ /**
2112
+ * Remove an event subscription that you previously subscribed to.
2113
+ *
2114
+ * @param subscriptionGuid - The identifier of the subscription you wish to remove, returned by the method
2115
+ * you initially used to create it.
2116
+ */
2117
+ export function removeSubscription(subscriptionGuid: string): void;
2118
+
2119
+ /**
2120
+ * Requests an immediate refresh of content cards from Braze servers. By default, content cards are refreshed when
2121
+ * a new session opens (see 'openSession` for more details), and when the user refreshes content cards manually via
2122
+ * the refresh button. If you want to refresh content cards from the server at another time you must call this function.
2123
+ *
2124
+ * @param successCallback - Callback that is invoked when the content cards refresh request has been successfully completed.
2125
+ * You should use `subscribeToContentCardsUpdates` to be notified of new cards. This callback is useful for determining when
2126
+ * a request has completed regardless of whether new cards were returned.
2127
+ * @param errorCallback - Callback that is invoked when an error occurs during the refresh.
2128
+ */
2129
+ export function requestContentCardsRefresh(
2130
+ successCallback?: () => void,
2131
+ errorCallback?: () => void,
2132
+ ): void;
2133
+
2134
+ /**
2135
+ * Requests an immediate refresh of the news feed from Braze servers. By default, the news feed is refreshed on
2136
+ * `showFeed` (when stale - see
2137
+ * `showFeed` for details). If you want to refresh the feed from the
2138
+ * server at another time you must call this function. Results of this refresh are reported asynchronously to
2139
+ * subscriptions created via 'subscribeToFeedUpdates` .
2140
+ */
2141
+ export function requestFeedRefresh(): void;
2142
+
2143
+ /**
2144
+ * Requests an immediate refresh of feature flags from Braze servers. By default, feature flags are refreshed when
2145
+ * a new session starts. If you want to refresh feature flags from the server at another time you must call this function.
2146
+ *
2147
+ * @param successCallback - Callback that is invoked when the feature flags refresh request has been successfully completed.
2148
+ * This callback is useful for determining when a request has completed regardless of whether new feature flags were returned.
2149
+ * @param errorCallback - Callback that is invoked when an error occurs during the refresh.
2150
+ */
2151
+ export function refreshFeatureFlags(
2152
+ successCallback?: () => void,
2153
+ errorCallback?: () => void,
2154
+ ): void;
2155
+
2156
+ /**
2157
+ * By default, data logged to Braze through the SDK is queued locally (in HTML 5 localStorage when available, and
2158
+ * in memory otherwise) and sent to Braze's servers asynchronously on a regular interval (10 seconds when localStorage is available
2159
+ * and not routinely cleared due to browser privacy features, otherwise 3 seconds). This is done to optimize network usage and
2160
+ * provide resiliency against network or server outages. This method bypasses the interval and immediately flushes queued data.
2161
+ *
2162
+ * @param callback - Invoked when the flush completes with a boolean parameter that returns
2163
+ * whether or not the flush was successful. If the flush is unsuccessful, pending data will be
2164
+ * flushed during the next successful flush.
2165
+ */
2166
+ export function requestImmediateDataFlush(
2167
+ callback?: (success: boolean) => void,
2168
+ ): void;
2169
+
2170
+ /**
2171
+ * Removes the cookie set by `disableSDK`, causing subsequent calls to the Braze Web SDK to function. You must
2172
+ * call `initialize` after calling this method before calling subsequent methods.
2173
+ */
2174
+ export function enableSDK(): void;
2175
+
2176
+ /**
2177
+ * Getter method to determine if the SDK is disabled based on whether the cookie set by `disableSdk` exists
2178
+ */
2179
+ export function isDisabled(): boolean;
2180
+
2181
+ /**
2182
+ * By default, Braze logs to the browser console. Call this method to set a custom log action and enable debug-level log statements.
2183
+ *
2184
+ * @param loggerFunction - A function to invoke with log messages. Should accept a single string
2185
+ * parameter for message.
2186
+ */
2187
+ export function setLogger(loggerFunction: (message: string) => void): void;
2188
+
2189
+ /**
2190
+ * Sets the signature to be used to authenticate the current user. You can also set the signature when calling `changeUser`.
2191
+ * This signature will only have an effect if the `enableSdkAuthentication` initialization option is set to true.
2192
+ *
2193
+ * @param signature - The signature to add to network requests to authenticate the current user.
2194
+ *
2195
+ * @returns Whether or not the signature is valid.
2196
+ */
2197
+ export function setSdkAuthenticationSignature(signature: string): boolean;
2198
+
2199
+ /**
2200
+ * Adds SDK Metadata. This method is automatically called based on the integration method.
2201
+ *
2202
+ * @param sdkMetadata - An array of metadata values from `BrazeSdkMetadata`.
2203
+ *
2204
+ * @returns Whether or not the array of metadata is valid.
2205
+ */
2206
+ export function addSdkMetadata(sdkMetadata: string[]): boolean;
2207
+
2208
+ /**
2209
+ * Sets a cookie that causes all subsequent calls to the Braze Web SDK to be ignored
2210
+ * and all subsequent analytics to cease being sent to the Braze backend.
2211
+ * If you have multiple subdomains, this method MUST be called from the same subdomain that push was registered from to work properly.
2212
+ * This is useful for customer opt-outs. If the customer clears website data, tracking will resume.
2213
+ */
2214
+ export function disableSDK(): void;
2215
+
2216
+ /**
2217
+ * Subscribe to content cards updates. The subscriber callback will be called whenever content cards are updated. This method
2218
+ * should be called before calling `openSession`.
2219
+ *
2220
+ * @param subscriber - The callback function to handle new cards. This function will be called with a `ContentCards`
2221
+ * object which includes all currently available `Card` objects. If you want to be notified when a refresh has completed
2222
+ * regardless of whether new cards are available, you should use the `successCallback` of `requestContentCardsRefresh`.
2223
+ *
2224
+ * @returns The identifier of the subscription created. This can be passed to `removeSubscription` to cancel the subscription.
2225
+ * Returns undefined if the SDK has not been initialized.
2226
+ */
2227
+ export function subscribeToContentCardsUpdates(
2228
+ subscriber: (cards: ContentCards) => void,
2229
+ ): string | undefined;
2230
+
2231
+ /**
2232
+ * Subscribe to news feed updates. The subscriber callback will be called whenever the news feed is updated.
2233
+ *
2234
+ * @param subscriber - The callback function to handle new cards. This function will be
2235
+ * called with a `Feed`object which includes all `Card` objects currently in the feed.
2236
+ *
2237
+ * @returns The identifier of the subscription created. This can be passed to `removeSubscription` to cancel
2238
+ * the subscription. Returns undefined if the SDK has not been initialized.
2239
+ */
2240
+ export function subscribeToFeedUpdates(
2241
+ subscriber: (feed: Feed) => void,
2242
+ ): string | undefined;
2243
+
2244
+ /**
2245
+ * Subscribe to receive in-app messages. The subscriber callback will be called whenever a new in-app message is
2246
+ * triggered. This method should be called before calling `openSession`. If you are using the build of Braze's
2247
+ * library with UI, the most basic usage of this would be
2248
+ *
2249
+ * ```
2250
+ * braze.subscribeToInAppMessage(function(inAppMessage) {
2251
+ * braze.showInAppMessage(inAppMessage);
2252
+ * });
2253
+ * ```
2254
+ * @param callback - The callback function to handle the in-app message. This function will be
2255
+ * called with an `InAppMessage` or a `ControlMessage` object. If you are using the build
2256
+ * of Braze's library with UI, you may wish to call `showInAppMessage`
2257
+ * with the provided message.
2258
+ *
2259
+ * @returns The identifier of the subscription created. This can be passed to 'removeSubscription` to cancel
2260
+ * the subscription. Returns undefined if the SDK has not been initialized.
2261
+ */
2262
+ export function subscribeToInAppMessage(
2263
+ callback: (inAppMessage: InAppMessage | ControlMessage) => void,
2264
+ ): string | undefined;
2265
+
2266
+ /**
2267
+ * Subscribe to be notified of network request failures that occured due to an SDK Authentication error. This
2268
+ * method can be used to determine when to call `setSdkAuthenticationSignature` to provide the SDK with a new signature.
2269
+ * If you do not have SDK Authentication enabled on the Braze dashboard, this subscription will never be invoked.
2270
+ *
2271
+ * @param subscriber - The subscriber function that is invoked whenever an SDK Authentication error occurs. It is
2272
+ * invoked with an object containing the `errorCode`, `reason` for the error, the `userId` of the request (if the
2273
+ * user is not anonymous), and the authentication `signature` that caused the error.
2274
+ *
2275
+ * @returns The identifier of the subscription created. This can be passed to 'removeSubscription` to cancel
2276
+ * the subscription. Returns undefined if the SDK has not been initialized.
2277
+ */
2278
+ export function subscribeToSdkAuthenticationFailures(
2279
+ subscriber: (error: {
2280
+ errorCode: number;
2281
+ reason?: string;
2282
+ userId?: string;
2283
+ signature?: string;
2284
+ }) => void,
2285
+ ): string | undefined;
2286
+
2287
+ /**
2288
+ * By default, Braze silences its logging to prevent spamming production js consoles. Call this method to
2289
+ * toggle logging.
2290
+ */
2291
+ export function toggleLogging(): void;
2292
+
2293
+ /**
2294
+ * Unregisters push notifications on this browser.
2295
+ * Note that for Safari, Apple does not offer any unsubscribe mechanism, so on Safari this method leaves the user
2296
+ * with push permission granted and simply sets their subscription status to unsubscribed.
2297
+ *
2298
+ * @param successCallback - When the unsubscribe is successfully recorded and processed by Braze, this
2299
+ * callback will be invoked.
2300
+ * @param errorCallback - If the unsubscribe fails for unknown reasons, this callback will be invoked.
2301
+ */
2302
+ export function unregisterPush(
2303
+ successCallback?: () => void,
2304
+ errorCallback?: () => void,
2305
+ ): void;
2306
+
2307
+ /**
2308
+ * Removes all locally stored SDK data, causing the user to be seen in subsequent calls as a new anonymous user on a new device.
2309
+ */
2310
+ export function wipeData(): void;
2311
+
2312
+ /**
2313
+ * Handle links from within a message. This method will redirect valid links, or will parse and handle valid Braze Click Actions (brazeActions://).
2314
+ * @param url - a valid URL, or a valid brazeActions URL with scheme brazeActions://v{versionInt}/{base64string}
2315
+ * @param openLinkInNewTab - Whether the URL should be opened in a new tab. Defaults to false.
2316
+ */
2317
+ export function handleBrazeAction(
2318
+ url: string,
2319
+ openLinkInNewTab?: boolean,
2320
+ ): void;
2321
+
2322
+ /**
2323
+ * Gets a feature flag by its ID.
2324
+ *
2325
+ * @param id - The ID of the feature flag.
2326
+ * @returns - An object of type `FeatureFlag`, if feature flag with given ID exists. The method returns null if feature flag does not exist,
2327
+ * or if feature flags are disabled. Returns undefined if the SDK has not been initialized.
2328
+ */
2329
+ export function getFeatureFlag(id: string): FeatureFlag | null | undefined;
2330
+
2331
+ /**
2332
+ * Subscribe to feature flag updates. The subscriber callback will be called whenever feature flags are updated. This method
2333
+ * should be called before calling `openSession`.
2334
+ *
2335
+ * @param subscriber - The callback function to handle new feature flags. This function is always called first with the
2336
+ * available cached list of `FeatureFlag` objects, and will also be called when feature flag updates are available.
2337
+ * If there is a failure in receiving updates, this function will be called with the cached list of `FeatureFlag` objects.
2338
+ * If you want to be notified when a refresh has completed regardless of whether new feature flags are available,
2339
+ * you should use the `successCallback` of `refreshFeatureFlags`.
2340
+ *
2341
+ * @returns The identifier of the subscription created. This can be passed to `removeSubscription` to cancel the subscription.
2342
+ * Returns undefined if the SDK has not been initialized.
2343
+ */
2344
+ export function subscribeToFeatureFlagsUpdates(
2345
+ subscriber: (featureFlags: FeatureFlag[]) => void,
2346
+ ): string | undefined;
2347
+
2348
+ /**
2349
+ * Gets all available feature flags.
2350
+ *
2351
+ * @returns - A list of `FeatureFlag` objects.
2352
+ */
2353
+ export function getAllFeatureFlags(): FeatureFlag[];
2354
+
2355
+ /**
2356
+ * Logs impression for a given feature flag.
2357
+ *
2358
+ * @param featureFlagId - ID of the feature flag that has received the impression.
2359
+ *
2360
+ * @returns - Whether or not the impression was successfully logged. Returns undefined if the SDK has not been initialized.
2361
+ */
2362
+ export function logFeatureFlagImpression(
2363
+ featureFlagId: string,
2364
+ ): boolean | undefined;
2365
+
2366
+ /**
2367
+ * Supported initialization options
2368
+ *
2369
+ */
2370
+ export type InitializationOptions = {
2371
+ /**
2372
+ * By default, the Braze Web SDK ignores activity from known spiders or web crawlers, such as Google, based
2373
+ * on the user agent string. This saves data points, makes analytics more accurate, and may improve page rank.
2374
+ * However, if you want Braze to log activity from these crawlers instead, you may set this option to true.
2375
+ */
2376
+ allowCrawlerActivity?: boolean;
2377
+ /**
2378
+ * By default, the Braze Web SDK does not allow user-supplied Javascript click actions or enable HTML in-app messages,
2379
+ * as they allow Braze dashboard users to run Javascript on your site.
2380
+ * To indicate that you trust the Braze dashboard users to write non-malicious
2381
+ * Javascript click actions, set this property to true.
2382
+ */
2383
+ allowUserSuppliedJavascript?: boolean;
2384
+ /**
2385
+ * If you provide a value for this option, user events sent to Braze will be associated with the given version, which can be
2386
+ * used for user segmentation.
2387
+ */
2388
+ appVersion?: string;
2389
+ /**
2390
+ * A numerical app version value which can be used for user segmentation. This value must be sent with four fields, such as
2391
+ * "1.2.3.4", otherwise it will be ignored.
2392
+ */
2393
+ appVersionNumber?: string;
2394
+ /**
2395
+ * This option is required to configure the Braze Web SDK to use the appropriate endpoint for your integration - for example:
2396
+ * ```
2397
+ * braze.initialize('YOUR-API-KEY-HERE', { baseUrl: 'sdk.iad-03.braze.com' })
2398
+ * ```
2399
+ */
2400
+ baseUrl: string;
2401
+ /**
2402
+ * If you provide a value for this option, the Braze SDK will add the nonce to any `<script>` and `<style>` elements created by
2403
+ * the SDK. This can be used to permit the Braze SDK to work with your website's [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP).
2404
+ * Note that in addition to setting this nonce, you may also need to allow FontAwesome to load, which you can do by either adding
2405
+ * `use.fontawesome.com` to your Content Security Policy allowlist or by using the `doNotLoadFontAwesome` option and loading it manually.
2406
+ */
2407
+ contentSecurityNonce?: string;
2408
+ /**
2409
+ * By default, the Braze SDK automatically detects and collects all device properties in `DeviceProperties`. To override
2410
+ * this behavior, provide an array of `DeviceProperties`. To disable all properties being sent to Braze servers, provide
2411
+ * an empty array. Note that without some properties, not all features will function properly. For instance, without the time
2412
+ * zone, local timezone delivery will not function.
2413
+ */
2414
+ devicePropertyAllowlist?: string[];
2227
2415
  /**
2228
- * Adds SDK Metadata. This method is automatically called based on the integration method.
2229
- *
2230
- * @param sdkMetadata - An array of metadata values from `BrazeSdkMetadata`.
2231
- *
2232
- * @returns Whether or not the array of metadata is valid.
2416
+ * By default, users who have already granted web push permission (e.g. through `requestPushPermission` or from
2417
+ * a prior push provider) will sync their push token with the Braze backend automatically on new session to ensure deliverability.
2418
+ * To disable this behavior, set this option to true.
2233
2419
  */
2234
- export function addSdkMetadata(sdkMetadata: string[]): boolean;
2235
-
2420
+ disablePushTokenMaintenance?: boolean;
2236
2421
  /**
2237
- * Sets a cookie that causes all subsequent calls to the Braze Web SDK to be ignored
2238
- * and all subsequent analytics to cease being sent to the Braze backend.
2239
- * If you have multiple subdomains, this method MUST be called from the same subdomain that push was registered from to work properly.
2240
- * This is useful for customer opt-outs. If the customer clears website data, tracking will resume.
2422
+ * Braze uses [Font Awesome](http://fontawesome.io) for in-app message icons. By default, Braze will automatically load
2423
+ * FontAwesome 4.7.0 from the FontAwesome CDN. To disable this behavior (e.g. because your site uses a customized version
2424
+ * of FontAwesome), set this option to `true`. Note that if you do this, you are responsible for ensuring that FontAwesome
2425
+ * is loaded on your site - otherwise in-app messages may not render correctly.
2241
2426
  */
2242
- export function disableSDK(): void;
2243
-
2427
+ doNotLoadFontAwesome?: boolean;
2244
2428
  /**
2245
- * Subscribe to content cards updates. The subscriber callback will be called whenever content cards are updated. This method
2246
- * should be called before calling `openSession`.
2247
- *
2248
- * @param subscriber - The callback function to handle new cards. This function will be called with a `ContentCards`
2249
- * object which includes all currently available `Card` objects. If you want to be notified when a refresh has completed
2250
- * regardless of whether new cards are available, you should use the `successCallback` of `requestContentCardsRefresh`.
2251
- *
2252
- * @returns The identifier of the subscription created. This can be passed to `removeSubscription` to cancel the subscription.
2253
- * Returns undefined if the SDK has not been initialized.
2429
+ * Set to true to enable logging by default. Note that this will cause Braze to log to the javascript console, which is visible
2430
+ * to all users! You should probably remove this or provide an alternate logger with `setLogger` before you release
2431
+ * your page to production.
2254
2432
  */
2255
- export function subscribeToContentCardsUpdates(
2256
- subscriber: (cards: ContentCards) => void
2257
- ): string | undefined;
2258
-
2433
+ enableLogging?: boolean;
2259
2434
  /**
2260
- * Subscribe to news feed updates. The subscriber callback will be called whenever the news feed is updated.
2261
- *
2262
- * @param subscriber - The callback function to handle new cards. This function will be
2263
- * called with a `Feed`object which includes all `Card` objects currently in the feed.
2264
- *
2265
- * @returns The identifier of the subscription created. This can be passed to `removeSubscription` to cancel
2266
- * the subscription. Returns undefined if the SDK has not been initialized.
2435
+ * Set to true to enable the SDK Authentication feature. For more information about SDK Authentication, see our
2436
+ * [Product Documentation](https://www.braze.com/docs/developer_guide/platform_wide/sdk_authentication/).
2267
2437
  */
2268
- export function subscribeToFeedUpdates(
2269
- subscriber: (feed: Feed) => void
2270
- ): string | undefined;
2271
-
2438
+ enableSdkAuthentication?: boolean;
2272
2439
  /**
2273
- * Subscribe to receive in-app messages. The subscriber callback will be called whenever a new in-app message is
2274
- * triggered. This method should be called before calling `openSession`. If you are using the build of Braze's
2275
- * library with UI, the most basic usage of this would be
2276
- *
2277
- * ```
2278
- * braze.subscribeToInAppMessage(function(inAppMessage) {
2279
- * braze.showInAppMessage(inAppMessage);
2280
- * });
2281
- * ```
2282
- * @param callback - The callback function to handle the in-app message. This function will be
2283
- * called with an `InAppMessage` or a `ControlMessage` object. If you are using the build
2284
- * of Braze's library with UI, you may wish to call `showInAppMessage`
2285
- * with the provided message.
2286
- *
2287
- * @returns The identifier of the subscription created. This can be passed to 'removeSubscription` to cancel
2288
- * the subscription. Returns undefined if the SDK has not been initialized.
2440
+ * By default, the Braze SDK will show In-App Messages with a z-index of 9001 for the screen overlay, 9011 for the actual in-app message,
2441
+ * and 9021 for the message's close button. Provide a value for this option to override these default z-indexes. The value provided
2442
+ * will be used for the backdrop, `value + 1` will be used for the in-app message, and `value + 2` will be used for the close button.
2289
2443
  */
2290
- export function subscribeToInAppMessage(
2291
- callback: (
2292
- inAppMessage: InAppMessage | ControlMessage
2293
- ) => void
2294
- ): string | undefined;
2295
-
2444
+ inAppMessageZIndex?: number;
2296
2445
  /**
2297
- * Subscribe to be notified of network request failures that occured due to an SDK Authentication error. This
2298
- * method can be used to determine when to call `setSdkAuthenticationSignature` to provide the SDK with a new signature.
2299
- * If you do not have SDK Authentication enabled on the Braze dashboard, this subscription will never be invoked.
2300
- *
2301
- * @param subscriber - The subscriber function that is invoked whenever an SDK Authentication error occurs. It is
2302
- * invoked with an object containing the `errorCode`, `reason` for the error, the `userId` of the request (if the
2303
- * user is not anonymous), and the authentication `signature` that caused the error.
2304
- *
2305
- * @returns The identifier of the subscription created. This can be passed to 'removeSubscription` to cancel
2306
- * the subscription. Returns undefined if the SDK has not been initialized.
2446
+ * By default, any SDK-generated user-visible messages will be displayed in the user's browser language. Provide a value for this
2447
+ * option to override that behavior and force a specific language. The value for this option should be a
2448
+ * [ISO 639-1 Language Code](https://www.w3schools.com/tags/ref_language_codes.asp). If a desired localization is not available,
2449
+ * the SDK will default to English. See also `User.setLanguage` for setting the language you use within the Braze dashboard to
2450
+ * localize your own messaging content.
2307
2451
  */
2308
- export function subscribeToSdkAuthenticationFailures(subscriber: (
2309
- error: {
2310
- errorCode: number,
2311
- reason?: string,
2312
- userId?: string,
2313
- signature?: string
2314
- }
2315
- ) => void): string | undefined;
2316
-
2452
+ localization?: string;
2317
2453
  /**
2318
- * By default, Braze silences its logging to prevent spamming production js consoles. Call this method to
2319
- * toggle logging.
2454
+ * By default, `requestPushPermission`/`unregisterPush` assume that they control and can
2455
+ * register and unregister the site's service worker. If you have your own service worker that you register and control the
2456
+ * lifecycle of, set this option to true and the Braze SDK will not register or unregister a service worker. If you set this
2457
+ * option to true, in order for push to function correctly you must register the service worker yourself BEFORE calling
2458
+ * `requestPushPermission`, and ensure that it contains Braze's service worker code, either with
2459
+ * `self.importScripts('https://js.appboycdn.com/web-sdk-develop/5.0/service-worker.js');` or by including the content
2460
+ * of that file directly. When this option is true, the `serviceWorkerLocation` option is irrelevant and is ignored.
2320
2461
  */
2321
- export function toggleLogging(): void;
2322
-
2462
+ manageServiceWorkerExternally?: boolean;
2323
2463
  /**
2324
- * Unregisters push notifications on this browser.
2325
- * Note that for Safari, Apple does not offer any unsubscribe mechanism, so on Safari this method leaves the user
2326
- * with push permission granted and simply sets their subscription status to unsubscribed.
2327
- *
2328
- * @param successCallback - When the unsubscribe is successfully recorded and processed by Braze, this
2329
- * callback will be invoked.
2330
- * @param errorCallback - If the unsubscribe fails for unknown reasons, this callback will be invoked.
2464
+ * By default, a trigger action will only fire if at least 30 seconds have elapsed since the last trigger action. Provide a
2465
+ * value for this configuration option to override that default with a value of your own. We do not recommend making this
2466
+ * value any smaller than 10 to avoid spamming the user with notifications.
2331
2467
  */
2332
- export function unregisterPush(
2333
- successCallback?: () => void,
2334
- errorCallback?: () => void
2335
- ): void;
2336
-
2468
+ minimumIntervalBetweenTriggerActionsInSeconds?: number;
2337
2469
  /**
2338
- * Removes all locally stored SDK data, causing the user to be seen in subsequent calls as a new anonymous user on a new device.
2470
+ * By default, the Braze SDK will store small amounts of data (user ids, session ids), in cookies. This is done to allow Braze
2471
+ * to recognize users and sessions across different subdomains of your site. If this presents a problem for you, pass `true`
2472
+ * for this option to disable cookie storage and rely entirely on HTML 5 localStorage to identify users and sessions. The downside
2473
+ * of this configuration is that you will be unable to recognize users across subdomains of your site.
2339
2474
  */
2340
- export function wipeData(): void;
2341
-
2475
+ noCookies?: boolean;
2342
2476
  /**
2343
- * Handle links from within a message. This method will redirect valid links, or will parse and handle valid Braze Click Actions (brazeActions://).
2344
- * @param url - a valid URL, or a valid brazeActions URL with scheme brazeActions://v{versionInt}/{base64string}
2345
- * @param openLinkInNewTab - Whether the URL should be opened in a new tab. Defaults to false.
2477
+ * By default, links from in-app message clicks load in the current tab or a new tab as specified in the dashboard on a
2478
+ * message-by-message basis. Set this option to `true` to force all links from in-app message clicks open in a new tab or window.
2346
2479
  */
2347
- export function handleBrazeAction(url: string, openLinkInNewTab?: boolean): void;
2348
-
2480
+ openInAppMessagesInNewTab?: boolean;
2349
2481
  /**
2350
- * Gets a feature flag by its ID.
2351
- *
2352
- * @param id - The ID of the feature flag.
2353
- * @returns - An object of type `FeatureFlag`.
2482
+ * By default, links from `Card` objects load in the current tab or window. Set this option to `true` to make links from
2483
+ * cards open in a new tab or window.
2354
2484
  */
2355
- export function getFeatureFlag(id: string): FeatureFlag;
2356
-
2485
+ openCardsInNewTab?: boolean;
2357
2486
  /**
2358
- * Subscribe to feature flag updates. The subscriber callback will be called whenever feature flags are updated. This method
2359
- * should be called before calling `openSession`.
2360
- *
2361
- * @param subscriber - The callback function to handle new feature flags. This function is always called first with the
2362
- * available cached list of `FeatureFlag` objects, and will also be called when feature flag updates are available.
2363
- * If you want to be notified when a refresh has completed
2364
- * regardless of whether new feature flags are available, you should use the `successCallback` of `refreshFeatureFlags`.
2365
- *
2366
- * @returns The identifier of the subscription created. This can be passed to `removeSubscription` to cancel the subscription.
2367
- * Returns undefined if the SDK has not been initialized.
2487
+ * By default, when an in-app message is showing, pressing the escape button or a click on the greyed-out background of the
2488
+ * page will dismiss the message. Set this option to `true` to prevent this behavior and require an explicit button click
2489
+ * to dismiss messages.
2368
2490
  */
2369
- export function subscribeToFeatureFlagsUpdates(
2370
- subscriber: (featureFlags: FeatureFlag[]) => void
2371
- ): string | undefined;
2372
-
2491
+ requireExplicitInAppMessageDismissal?: boolean;
2373
2492
  /**
2374
- * Gets all available feature flags.
2375
- *
2376
- * @returns - A list of `FeatureFlag` objects.
2493
+ * If you support Safari push, you must specify this option with the website push ID that you provided to Apple when creating
2494
+ * your Safari push certificate (starts with "web", e.g. "web.com.example.domain").
2377
2495
  */
2378
- export function getAllFeatureFlags(): FeatureFlag[];
2379
-
2496
+ safariWebsitePushId?: string;
2380
2497
  /**
2381
- * Logs impression for a given feature flag.
2382
- *
2383
- * @param featureFlagId - ID of the feature flag that has received the impression.
2384
- *
2385
- * @returns - Whether or not the impression was successfully logged. Returns undefined if the SDK has not been initialized.
2498
+ * By default, when registering users for web push notifications Braze will look for the required service worker file in the
2499
+ * root directory of your web server at `/service-worker.js`. If you want to host your service worker at a different path
2500
+ * on that server, provide a value for this option that is the absolute path to the file, e.g. `/mycustompath/my-worker.js`.
2501
+ * VERY IMPORTANT: setting a value here limits the scope of push notifications on your site. For instance, in the above
2502
+ * example, because the service worker file is located within the `/mycustompath/` directory, `requestPushPermission`
2503
+ * MAY ONLY BE CALLED from web pages that start with `http://yoursite.com/mycustompath/`.
2386
2504
  */
2387
- export function logFeatureFlagImpression(featureFlagId: string): boolean | undefined;
2388
-
2505
+ serviceWorkerLocation?: string;
2389
2506
  /**
2390
- * Supported initialization options
2391
- *
2507
+ * By default, sessions time out after 30 minutes of inactivity. Provide a value for this configuration option to override that
2508
+ * default with a value of your own.
2392
2509
  */
2393
- export type InitializationOptions = {
2394
- /**
2395
- * By default, the Braze Web SDK ignores activity from known spiders or web crawlers, such as Google, based
2396
- * on the user agent string. This saves data points, makes analytics more accurate, and may improve page rank.
2397
- * However, if you want Braze to log activity from these crawlers instead, you may set this option to true.
2398
- */
2399
- allowCrawlerActivity?: boolean;
2400
- /**
2401
- * By default, the Braze Web SDK does not allow user-supplied Javascript click actions, as it allows Braze dashboard
2402
- * users to run Javascript on your site. To indicate that you trust the Braze dashboard users to write non-malicious
2403
- * Javascript click actions, set this property to true. If `enableHtmlInAppMessages` is true, this option will also be
2404
- * set to true.
2405
- */
2406
- allowUserSuppliedJavascript?: boolean;
2407
- /**
2408
- * If you provide a value for this option, user events sent to Braze will be associated with the given version, which can be
2409
- * used for user segmentation.
2410
- */
2411
- appVersion?: string;
2412
- /**
2413
- * This option is required to configure the Braze Web SDK to use the appropriate endpoint for your integration - for example:
2414
- * ```
2415
- * braze.initialize('YOUR-API-KEY-HERE', { baseUrl: 'sdk.iad-03.braze.com' })
2416
- * ```
2417
- */
2418
- baseUrl: string;
2419
- /**
2420
- * If you provide a value for this option, the Braze SDK will add the nonce to any `<script>` and `<style>` elements created by
2421
- * the SDK. This can be used to permit the Braze SDK to work with your website's [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP).
2422
- * Note that in addition to setting this nonce, you may also need to allow FontAwesome to load, which you can do by either adding
2423
- * `use.fontawesome.com` to your Content Security Policy allowlist or by using the `doNotLoadFontAwesome` option and loading it manually.
2424
- */
2425
- contentSecurityNonce?: string;
2426
- /**
2427
- * By default, the Braze SDK automatically detects and collects all device properties in `DeviceProperties`. To override
2428
- * this behavior, provide an array of `DeviceProperties`. To disable all properties being sent to Braze servers, provide
2429
- * an empty array. Note that without some properties, not all features will function properly. For instance, without the time
2430
- * zone, local timezone delivery will not function.
2431
- */
2432
- devicePropertyAllowlist?: string[];
2433
- /**
2434
- * By default, users who have already granted web push permission (e.g. through `requestPushPermission` or from
2435
- * a prior push provider) will sync their push token with the Braze backend automatically on new session to ensure deliverability.
2436
- * To disable this behavior, set this option to true.
2437
- */
2438
- disablePushTokenMaintenance?: boolean;
2439
- /**
2440
- * Braze uses [Font Awesome](http://fontawesome.io) for in-app message icons. By default, Braze will automatically load
2441
- * FontAwesome 4.7.0 from the FontAwesome CDN. To disable this behavior (e.g. because your site uses a customized version
2442
- * of FontAwesome), set this option to `true`. Note that if you do this, you are responsible for ensuring that FontAwesome
2443
- * is loaded on your site - otherwise in-app messages may not render correctly.
2444
- */
2445
- doNotLoadFontAwesome?: boolean;
2446
- /**
2447
- * By default, the Braze Web SDK does not enable HTML in-app messages, as they allow Braze dashboard users to run Javascript
2448
- * on your site. To indicate that you trust the Braze dashboard users to write non-malicious HTML in-app messages, set this
2449
- * property to true. If `allowUserSuppliedJavascript` is set to true, this option will also be set to true.
2450
- *
2451
- * @deprecated This initialization option is deprecated in favor of `allowUserSuppliedJavascript`.
2452
- */
2453
- enableHtmlInAppMessages?: boolean;
2454
- /**
2455
- * Set to true to enable logging by default. Note that this will cause Braze to log to the javascript console, which is visible
2456
- * to all users! You should probably remove this or provide an alternate logger with `setLogger` before you release
2457
- * your page to production.
2458
- */
2459
- enableLogging?: boolean;
2460
- /**
2461
- * Set to true to enable the SDK Authentication feature. For more information about SDK Authentication, see our
2462
- * [Product Documentation](https://www.braze.com/docs/developer_guide/platform_wide/sdk_authentication/).
2463
- */
2464
- enableSdkAuthentication?: boolean
2465
- /**
2466
- * By default, the Braze SDK will show In-App Messages with a z-index of 9001 for the screen overlay, 9011 for the actual in-app message,
2467
- * and 9021 for the message's close button. Provide a value for this option to override these default z-indexes. The value provided
2468
- * will be used for the backdrop, `value + 1` will be used for the in-app message, and `value + 2` will be used for the close button.
2469
- */
2470
- inAppMessageZIndex?: number
2471
- /**
2472
- * By default, any SDK-generated user-visible messages will be displayed in the user's browser language. Provide a value for this
2473
- * option to override that behavior and force a specific language. The value for this option should be a
2474
- * [ISO 639-1 Language Code](https://www.w3schools.com/tags/ref_language_codes.asp). If a desired localization is not available,
2475
- * the SDK will default to English. See also `User.setLanguage` for setting the language you use within the Braze dashboard to
2476
- * localize your own messaging content.
2477
- */
2478
- localization?: string;
2479
- /**
2480
- * By default, `requestPushPermission`/`unregisterPush` assume that they control and can
2481
- * register and unregister the site's service worker. If you have your own service worker that you register and control the
2482
- * lifecycle of, set this option to true and the Braze SDK will not register or unregister a service worker. If you set this
2483
- * option to true, in order for push to function correctly you must register the service worker yourself BEFORE calling
2484
- * `requestPushPermission`, and ensure that it contains Braze's service worker code, either with
2485
- * `self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.9/service-worker.js');` or by including the content
2486
- * of that file directly. When this option is true, the `serviceWorkerLocation` option is irrelevant and is ignored.
2487
- */
2488
- manageServiceWorkerExternally?: boolean;
2489
- /**
2490
- * By default, a trigger action will only fire if at least 30 seconds have elapsed since the last trigger action. Provide a
2491
- * value for this configuration option to override that default with a value of your own. We do not recommend making this
2492
- * value any smaller than 10 to avoid spamming the user with notifications.
2493
- */
2494
- minimumIntervalBetweenTriggerActionsInSeconds?: number;
2495
- /**
2496
- * By default, the Braze SDK will store small amounts of data (user ids, session ids), in cookies. This is done to allow Braze
2497
- * to recognize users and sessions across different subdomains of your site. If this presents a problem for you, pass `true`
2498
- * for this option to disable cookie storage and rely entirely on HTML 5 localStorage to identify users and sessions. The downside
2499
- * of this configuration is that you will be unable to recognize users across subdomains of your site.
2500
- */
2501
- noCookies?: boolean;
2502
- /**
2503
- * By default, links from in-app message clicks load in the current tab or a new tab as specified in the dashboard on a
2504
- * message-by-message basis. Set this option to `true` to force all links from in-app message clicks open in a new tab or window.
2505
- */
2506
- openInAppMessagesInNewTab?: boolean;
2507
- /**
2508
- * By default, links from `Card` objects load in the current tab or window. Set this option to `true` to make links from
2509
- * cards open in a new tab or window.
2510
- */
2511
- openCardsInNewTab?: boolean;
2512
- /**
2513
- * By default, when an in-app message is showing, pressing the escape button or a click on the greyed-out background of the
2514
- * page will dismiss the message. Set this option to `true` to prevent this behavior and require an explicit button click
2515
- * to dismiss messages.
2516
- */
2517
- requireExplicitInAppMessageDismissal?: boolean;
2518
- /**
2519
- * If you support Safari push, you must specify this option with the website push ID that you provided to Apple when creating
2520
- * your Safari push certificate (starts with "web", e.g. "web.com.example.domain").
2521
- */
2522
- safariWebsitePushId?: string;
2523
- /**
2524
- * By default, when registering users for web push notifications Braze will look for the required service worker file in the
2525
- * root directory of your web server at `/service-worker.js`. If you want to host your service worker at a different path
2526
- * on that server, provide a value for this option that is the absolute path to the file, e.g. `/mycustompath/my-worker.js`.
2527
- * VERY IMPORTANT: setting a value here limits the scope of push notifications on your site. For instance, in the above
2528
- * example, because the service worker file is located within the `/mycustompath/` directory, `requestPushPermission`
2529
- * MAY ONLY BE CALLED from web pages that start with `http://yoursite.com/mycustompath/`.
2530
- */
2531
- serviceWorkerLocation?: string;
2532
- /**
2533
- * By default, sessions time out after 30 minutes of inactivity. Provide a value for this configuration option to override that
2534
- * default with a value of your own.
2535
- */
2536
- sessionTimeoutInSeconds?: number;
2537
- };
2510
+ sessionTimeoutInSeconds?: number;
2511
+ };
2538
2512
 
2539
2513
 
2540
2514