@ht-sdks/events-sdk-js-browser 1.0.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +22 -22
  2. package/dist/cjs/browser/index.js +36 -28
  3. package/dist/cjs/browser/index.js.map +1 -1
  4. package/dist/cjs/browser/standalone-analytics.js +1 -1
  5. package/dist/cjs/browser/standalone-analytics.js.map +1 -1
  6. package/dist/cjs/core/analytics/index.js +1 -1
  7. package/dist/cjs/core/analytics/index.js.map +1 -1
  8. package/dist/cjs/core/arguments-resolver/index.js.map +1 -1
  9. package/dist/cjs/core/buffer/index.js.map +1 -1
  10. package/dist/cjs/core/context/index.js.map +1 -1
  11. package/dist/cjs/core/events/index.js.map +1 -1
  12. package/dist/cjs/core/http-cookies/index.js +166 -0
  13. package/dist/cjs/core/http-cookies/index.js.map +1 -0
  14. package/dist/cjs/core/page/add-page-context.js.map +1 -1
  15. package/dist/cjs/core/user/index.js +25 -5
  16. package/dist/cjs/core/user/index.js.map +1 -1
  17. package/dist/cjs/generated/version.js +1 -1
  18. package/dist/cjs/lib/global-analytics-helper.js +1 -1
  19. package/dist/cjs/lib/global-analytics-helper.js.map +1 -1
  20. package/dist/cjs/lib/merged-options.js +1 -1
  21. package/dist/cjs/lib/parse-cdn.js +1 -1
  22. package/dist/cjs/lib/parse-cdn.js.map +1 -1
  23. package/dist/cjs/lib/to-facade.js.map +1 -1
  24. package/dist/cjs/node/index.js +1 -1
  25. package/dist/cjs/node/index.js.map +1 -1
  26. package/dist/cjs/plugins/ajs-destination/utils.js +1 -1
  27. package/dist/cjs/plugins/ajs-destination/utils.js.map +1 -1
  28. package/dist/cjs/plugins/analytics-node/index.js +2 -2
  29. package/dist/cjs/plugins/analytics-node/index.js.map +1 -1
  30. package/dist/cjs/plugins/env-enrichment/index.js.map +1 -1
  31. package/dist/cjs/plugins/hightouchio/batched-dispatcher.js.map +1 -1
  32. package/dist/cjs/plugins/legacy-video-plugins/index.js +4 -4
  33. package/dist/cjs/plugins/legacy-video-plugins/index.js.map +1 -1
  34. package/dist/cjs/plugins/middleware/index.js.map +1 -1
  35. package/dist/pkg/browser/index.js +35 -27
  36. package/dist/pkg/browser/index.js.map +1 -1
  37. package/dist/pkg/browser/standalone-analytics.js +2 -2
  38. package/dist/pkg/browser/standalone-analytics.js.map +1 -1
  39. package/dist/pkg/core/analytics/index.js +1 -1
  40. package/dist/pkg/core/analytics/index.js.map +1 -1
  41. package/dist/pkg/core/arguments-resolver/index.js.map +1 -1
  42. package/dist/pkg/core/buffer/index.js.map +1 -1
  43. package/dist/pkg/core/context/index.js.map +1 -1
  44. package/dist/pkg/core/events/index.js.map +1 -1
  45. package/dist/pkg/core/http-cookies/index.js +163 -0
  46. package/dist/pkg/core/http-cookies/index.js.map +1 -0
  47. package/dist/pkg/core/page/add-page-context.js.map +1 -1
  48. package/dist/pkg/core/user/index.js +25 -5
  49. package/dist/pkg/core/user/index.js.map +1 -1
  50. package/dist/pkg/generated/version.js +1 -1
  51. package/dist/pkg/lib/global-analytics-helper.js +1 -1
  52. package/dist/pkg/lib/global-analytics-helper.js.map +1 -1
  53. package/dist/pkg/lib/merged-options.js +1 -1
  54. package/dist/pkg/lib/parse-cdn.js +1 -1
  55. package/dist/pkg/lib/parse-cdn.js.map +1 -1
  56. package/dist/pkg/lib/to-facade.js.map +1 -1
  57. package/dist/pkg/node/index.js +1 -1
  58. package/dist/pkg/node/index.js.map +1 -1
  59. package/dist/pkg/plugins/ajs-destination/utils.js +1 -1
  60. package/dist/pkg/plugins/ajs-destination/utils.js.map +1 -1
  61. package/dist/pkg/plugins/analytics-node/index.js +2 -2
  62. package/dist/pkg/plugins/analytics-node/index.js.map +1 -1
  63. package/dist/pkg/plugins/env-enrichment/index.js.map +1 -1
  64. package/dist/pkg/plugins/hightouchio/batched-dispatcher.js.map +1 -1
  65. package/dist/pkg/plugins/legacy-video-plugins/index.js +6 -6
  66. package/dist/pkg/plugins/legacy-video-plugins/index.js.map +1 -1
  67. package/dist/pkg/plugins/middleware/index.js.map +1 -1
  68. package/dist/types/browser/index.d.ts +12 -12
  69. package/dist/types/browser/index.d.ts.map +1 -1
  70. package/dist/types/browser/standalone-interface.d.ts +1 -1
  71. package/dist/types/browser/standalone-interface.d.ts.map +1 -1
  72. package/dist/types/core/analytics/index.d.ts +12 -3
  73. package/dist/types/core/analytics/index.d.ts.map +1 -1
  74. package/dist/types/core/analytics/interfaces.d.ts +5 -5
  75. package/dist/types/core/analytics/interfaces.d.ts.map +1 -1
  76. package/dist/types/core/arguments-resolver/index.d.ts +2 -2
  77. package/dist/types/core/arguments-resolver/index.d.ts.map +1 -1
  78. package/dist/types/core/buffer/index.d.ts +10 -10
  79. package/dist/types/core/buffer/index.d.ts.map +1 -1
  80. package/dist/types/core/context/index.d.ts +3 -3
  81. package/dist/types/core/context/index.d.ts.map +1 -1
  82. package/dist/types/core/events/index.d.ts +8 -8
  83. package/dist/types/core/events/index.d.ts.map +1 -1
  84. package/dist/types/core/events/interfaces.d.ts +2 -2
  85. package/dist/types/core/events/interfaces.d.ts.map +1 -1
  86. package/dist/types/core/http-cookies/index.d.ts +53 -0
  87. package/dist/types/core/http-cookies/index.d.ts.map +1 -0
  88. package/dist/types/core/page/add-page-context.d.ts +2 -2
  89. package/dist/types/core/page/add-page-context.d.ts.map +1 -1
  90. package/dist/types/core/page/get-page-context.d.ts +1 -1
  91. package/dist/types/core/stats/remote-metrics.d.ts +1 -1
  92. package/dist/types/core/user/index.d.ts +5 -0
  93. package/dist/types/core/user/index.d.ts.map +1 -1
  94. package/dist/types/generated/version.d.ts +1 -1
  95. package/dist/types/index.d.ts +1 -1
  96. package/dist/types/index.d.ts.map +1 -1
  97. package/dist/types/lib/global-analytics-helper.d.ts +4 -4
  98. package/dist/types/lib/global-analytics-helper.d.ts.map +1 -1
  99. package/dist/types/lib/merged-options.d.ts +1 -1
  100. package/dist/types/lib/to-facade.d.ts +4 -4
  101. package/dist/types/lib/to-facade.d.ts.map +1 -1
  102. package/dist/types/plugins/analytics-node/index.d.ts +2 -2
  103. package/dist/types/plugins/analytics-node/index.d.ts.map +1 -1
  104. package/dist/types/plugins/legacy-video-plugins/index.d.ts +1 -1
  105. package/dist/types/plugins/legacy-video-plugins/index.d.ts.map +1 -1
  106. package/dist/types/plugins/middleware/index.d.ts +4 -4
  107. package/dist/types/plugins/middleware/index.d.ts.map +1 -1
  108. package/dist/umd/{ajs-destination.bundle.5a985a542b0de08e3e49.js → ajs-destination.bundle.48266e86bbbc2531ac42.js} +2 -2
  109. package/dist/umd/{ajs-destination.bundle.5a985a542b0de08e3e49.js.map → ajs-destination.bundle.48266e86bbbc2531ac42.js.map} +1 -1
  110. package/dist/umd/events.min.js +1 -1
  111. package/dist/umd/events.min.js.map +1 -1
  112. package/dist/umd/index.js +1 -1
  113. package/dist/umd/index.js.map +1 -1
  114. package/dist/umd/legacyVideos.bundle.6250709892bb05b68333.js.map +1 -1
  115. package/package.json +3 -3
  116. package/src/browser/index.ts +27 -20
  117. package/src/browser/standalone-analytics.ts +3 -3
  118. package/src/browser/standalone-interface.ts +1 -1
  119. package/src/core/analytics/index.ts +18 -4
  120. package/src/core/analytics/interfaces.ts +5 -5
  121. package/src/core/arguments-resolver/index.ts +2 -2
  122. package/src/core/buffer/index.ts +4 -4
  123. package/src/core/context/index.ts +3 -3
  124. package/src/core/events/index.ts +22 -19
  125. package/src/core/events/interfaces.ts +2 -2
  126. package/src/core/http-cookies/README.md +194 -0
  127. package/src/core/http-cookies/index.ts +152 -0
  128. package/src/core/page/add-page-context.ts +2 -2
  129. package/src/core/page/get-page-context.ts +1 -1
  130. package/src/core/stats/remote-metrics.ts +1 -1
  131. package/src/core/user/index.ts +34 -4
  132. package/src/generated/version.ts +1 -1
  133. package/src/index.ts +1 -1
  134. package/src/lib/global-analytics-helper.ts +4 -4
  135. package/src/lib/merged-options.ts +1 -1
  136. package/src/lib/parse-cdn.ts +1 -1
  137. package/src/lib/to-facade.ts +7 -4
  138. package/src/node/index.ts +1 -1
  139. package/src/plugins/ajs-destination/types.ts +1 -1
  140. package/src/plugins/ajs-destination/utils.ts +1 -1
  141. package/src/plugins/analytics-node/index.ts +5 -5
  142. package/src/plugins/env-enrichment/index.ts +2 -2
  143. package/src/plugins/hightouchio/batched-dispatcher.ts +3 -3
  144. package/src/plugins/legacy-video-plugins/index.ts +4 -4
  145. package/src/plugins/middleware/index.ts +10 -10
  146. package/src/test-helpers/fixtures/cdn-settings.ts +2 -2
  147. package/src/test-helpers/test-writekeys.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"legacyVideos.bundle.6250709892bb05b68333.js","mappings":"+NAEO,SAAeA,EACpBC,G,2BACCC,SAAO,W,8DACQ,SAAM,oC,cAAhBC,EAAU,SAShBF,EAAUG,SAAWD,E","sources":["webpack://@ht-sdks/events-sdk-js-browser/./src/plugins/legacy-video-plugins/index.ts"],"sourcesContent":["import { Analytics } from '../../core/analytics'\n\nexport async function loadLegacyVideoPlugins(\n analytics: Analytics\n): Promise<void> {\n const plugins = await import(\n // @ts-expect-error\n '@segment/analytics.js-video-plugins/dist/index.umd.js'\n )\n\n // This is super gross, but we need to support the `window.analytics.plugins` namespace\n // that is linked in the segment docs in order to be backwards compatible with ajs-classic\n\n // @ts-expect-error\n analytics._plugins = plugins\n}\n"],"names":["loadLegacyVideoPlugins","analytics","Promise","plugins","_plugins"],"sourceRoot":""}
1
+ {"version":3,"file":"legacyVideos.bundle.6250709892bb05b68333.js","mappings":"+NAEO,SAAeA,EACpBC,G,2BACCC,SAAO,W,8DACQ,SAAM,oC,cAAhBC,EAAU,SAShBF,EAASG,SAAWD,E","sources":["webpack://@ht-sdks/events-sdk-js-browser/./src/plugins/legacy-video-plugins/index.ts"],"sourcesContent":["import { Analytics } from '../../core/analytics'\n\nexport async function loadLegacyVideoPlugins(\n htevents: Analytics\n): Promise<void> {\n const plugins = await import(\n // @ts-expect-error\n '@segment/analytics.js-video-plugins/dist/index.umd.js'\n )\n\n // This is super gross, but we need to support the `window.htevents.plugins` namespace\n // that is linked in the hightouch docs in order to be backwards compatible with ajs-classic\n\n // @ts-expect-error\n htevents._plugins = plugins\n}\n"],"names":["loadLegacyVideoPlugins","htevents","Promise","plugins","_plugins"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ht-sdks/events-sdk-js-browser",
3
- "version": "1.0.4",
3
+ "version": "1.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ht-sdks/events-sdk-js-mono",
@@ -49,7 +49,7 @@
49
49
  }
50
50
  ],
51
51
  "dependencies": {
52
- "@ht-sdks/events-sdk-js-core": "^1.0.0",
52
+ "@ht-sdks/events-sdk-js-core": "^1.1.0",
53
53
  "@lukeed/uuid": "^2.0.0",
54
54
  "@segment/analytics.js-video-plugins": "^0.2.1",
55
55
  "@segment/facade": "^3.4.9",
@@ -86,7 +86,7 @@
86
86
  "jest-dev-server": "^6.0.3",
87
87
  "jest-environment-jsdom": "^28.1.1",
88
88
  "jquery": "^3.5.1",
89
- "jsdom": "^19.0.0",
89
+ "jsdom": "^20.0.0",
90
90
  "lighthouse": "^9.6.3",
91
91
  "log-update": "^4.0.0",
92
92
  "micro-memoize": "^4.0.9",
@@ -4,6 +4,7 @@ import { getCDN, setGlobalCDNUrl } from '../lib/parse-cdn'
4
4
  import { fetch } from '../lib/fetch'
5
5
  import { Analytics, AnalyticsSettings, InitOptions } from '../core/analytics'
6
6
  import { Context } from '../core/context'
7
+ import { HTTPCookieService } from '../core/http-cookies'
7
8
  import { Plan } from '../core/events'
8
9
  import { Plugin } from '../core/plugin'
9
10
  import { MetricsOptions } from '../core/stats/remote-metrics'
@@ -53,7 +54,7 @@ export interface LegacyIntegrationConfiguration {
53
54
  categories: string[]
54
55
  }
55
56
 
56
- // Segment.io specific
57
+ // Hightouch.io specific
57
58
  retryQueue?: boolean
58
59
 
59
60
  // any extra unknown settings
@@ -92,15 +93,15 @@ export interface LegacySettings {
92
93
  }
93
94
  }
94
95
 
95
- export interface AnalyticsBrowserSettings extends AnalyticsSettings {
96
+ export interface HtEventsBrowserSettings extends AnalyticsSettings {
96
97
  /**
97
- * The settings for the Segment Source.
98
- * If provided, `AnalyticsBrowser` will not fetch remote settings
98
+ * The settings for the Hightouch Source.
99
+ * If provided, `HtEventsBrowser` will not fetch remote settings
99
100
  * for the source.
100
101
  */
101
102
  cdnSettings?: LegacySettings & Record<string, unknown>
102
103
  /**
103
- * If provided, will override the default Segment CDN (https://cdn.hightouch-events.com) for this application.
104
+ * If provided, will override the default Hightouch CDN (https://cdn.hightouch-events.com) for this application.
104
105
  */
105
106
  cdnURL?: string
106
107
  }
@@ -321,7 +322,7 @@ const defaultSettings: LegacySettings = {
321
322
  }
322
323
 
323
324
  async function loadAnalytics(
324
- settings: AnalyticsBrowserSettings,
325
+ settings: HtEventsBrowserSettings,
325
326
  options: InitOptions = {},
326
327
  preInitBuffer: PreInitMethodCallBuffer
327
328
  ): Promise<[Analytics, Context]> {
@@ -359,6 +360,12 @@ async function loadAnalytics(
359
360
  const retryQueue: boolean =
360
361
  legacySettings.integrations['Hightouch.io']?.retryQueue ?? true
361
362
 
363
+ if (!options.disableClientPersistence && options.httpCookieServiceOptions) {
364
+ options.httpCookieService = await HTTPCookieService.load(
365
+ options.httpCookieServiceOptions
366
+ )
367
+ }
368
+
362
369
  const opts: InitOptions = { retryQueue, ...options }
363
370
  const analytics = new Analytics(settings, opts)
364
371
 
@@ -406,24 +413,24 @@ async function loadAnalytics(
406
413
  }
407
414
 
408
415
  /**
409
- * The public browser interface for Segment Analytics
416
+ * The public browser interface for Hightouch Events
410
417
  *
411
418
  * @example
412
419
  * ```ts
413
- * export const analytics = new AnalyticsBrowser()
414
- * analytics.load({ writeKey: 'foo' })
420
+ * export const htevents = new HtEventsBrowser()
421
+ * htevents.load({ writeKey: 'foo' })
415
422
  * ```
416
423
  * @link https://github.com/ht-sdks/events-sdk-js-mono/tree/master/packages/browser#readme
417
424
  */
418
- export class AnalyticsBrowser extends AnalyticsBuffered {
425
+ export class HtEventsBrowser extends AnalyticsBuffered {
419
426
  private _resolveLoadStart: (
420
- settings: AnalyticsBrowserSettings,
427
+ settings: HtEventsBrowserSettings,
421
428
  options: InitOptions
422
429
  ) => void
423
430
 
424
431
  constructor() {
425
432
  const { promise: loadStart, resolve: resolveLoadStart } =
426
- createDeferred<Parameters<AnalyticsBrowser['load']>>()
433
+ createDeferred<Parameters<HtEventsBrowser['load']>>()
427
434
 
428
435
  super((buffer) =>
429
436
  loadStart.then(([settings, options]) =>
@@ -447,14 +454,14 @@ export class AnalyticsBrowser extends AnalyticsBuffered {
447
454
  *
448
455
  * @example
449
456
  * ```ts
450
- * export const analytics = new AnalyticsBrowser()
457
+ * export const analytics = new HtEventsBrowser()
451
458
  * analytics.load({ writeKey: 'foo' })
452
459
  * ```
453
460
  */
454
461
  load(
455
- settings: AnalyticsBrowserSettings,
462
+ settings: HtEventsBrowserSettings,
456
463
  options: InitOptions = {}
457
- ): AnalyticsBrowser {
464
+ ): HtEventsBrowser {
458
465
  this._resolveLoadStart(settings, options)
459
466
  return this
460
467
  }
@@ -464,23 +471,23 @@ export class AnalyticsBrowser extends AnalyticsBuffered {
464
471
  *
465
472
  * @example
466
473
  * ```ts
467
- * const ajs = AnalyticsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' })
474
+ * const ajs = HtEventsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' })
468
475
  *
469
476
  * ajs.track("foo")
470
477
  * ...
471
478
  * ```
472
479
  */
473
480
  static load(
474
- settings: AnalyticsBrowserSettings,
481
+ settings: HtEventsBrowserSettings,
475
482
  options: InitOptions = {}
476
- ): AnalyticsBrowser {
477
- return new AnalyticsBrowser().load(settings, options)
483
+ ): HtEventsBrowser {
484
+ return new HtEventsBrowser().load(settings, options)
478
485
  }
479
486
 
480
487
  static standalone(
481
488
  writeKey: string,
482
489
  options?: InitOptions
483
490
  ): Promise<Analytics> {
484
- return AnalyticsBrowser.load({ writeKey }, options).then((res) => res[0])
491
+ return HtEventsBrowser.load({ writeKey }, options).then((res) => res[0])
485
492
  }
486
493
  }
@@ -1,6 +1,6 @@
1
- import { AnalyticsBrowser } from '.'
1
+ import { HtEventsBrowser } from '.'
2
2
  import { embeddedWriteKey } from '../lib/embedded-write-key'
3
- import { AnalyticsSnippet } from './standalone-interface'
3
+ import { HtEventsSnippet } from './standalone-interface'
4
4
  import {
5
5
  getGlobalAnalytics,
6
6
  setGlobalAnalytics,
@@ -57,6 +57,6 @@ export async function install(): Promise<void> {
57
57
  }
58
58
 
59
59
  setGlobalAnalytics(
60
- (await AnalyticsBrowser.standalone(writeKey, options)) as AnalyticsSnippet
60
+ (await HtEventsBrowser.standalone(writeKey, options)) as HtEventsSnippet
61
61
  )
62
62
  }
@@ -1,6 +1,6 @@
1
1
  import { Analytics, InitOptions } from '../core/analytics'
2
2
 
3
- export interface AnalyticsSnippet extends AnalyticsStandalone {
3
+ export interface HtEventsSnippet extends AnalyticsStandalone {
4
4
  load: (writeKey: string, options?: InitOptions) => void
5
5
  }
6
6
 
@@ -20,7 +20,7 @@ import {
20
20
  Integrations,
21
21
  Plan,
22
22
  EventProperties,
23
- SegmentEvent,
23
+ HightouchEvent,
24
24
  } from '../events'
25
25
  import type { Plugin } from '../plugin'
26
26
  import { EventQueue } from '../queue/event-queue'
@@ -55,6 +55,10 @@ import {
55
55
  import { PluginFactory } from '../../plugins/remote-loader'
56
56
  import { setGlobalAnalytics } from '../../lib/global-analytics-helper'
57
57
  import { popPageContext } from '../buffer'
58
+ import type {
59
+ HTTPCookieService,
60
+ HTTPCookieServiceOptions,
61
+ } from '../http-cookies'
58
62
 
59
63
  const deprecationWarning =
60
64
  'This is being deprecated and will be not be available in future releases of Analytics JS'
@@ -124,11 +128,20 @@ export interface InitOptions {
124
128
  */
125
129
  highEntropyValuesClientHints?: HighEntropyHint[]
126
130
  /**
127
- * When using the snippet, this is the key that points to the global analytics instance (e.g. window.analytics).
131
+ * When using the snippet, this is the key that points to the global analytics instance (e.g. window.htevents).
128
132
  * default: analytics
129
133
  */
130
134
  globalAnalyticsKey?: string
131
135
 
136
+ /**
137
+ * When setting httpCookieServiceOptions, an HTTPCookieService is automatically created
138
+ */
139
+ httpCookieServiceOptions?: HTTPCookieServiceOptions
140
+ /**
141
+ * When not setting httpCookieServiceOptions, you may pass your own instance of HTTPCookieService
142
+ */
143
+ httpCookieService?: HTTPCookieService
144
+
132
145
  /**
133
146
  * Shortcuts for overriding the default Hightouch.io integration settings
134
147
  */
@@ -191,6 +204,7 @@ export class Analytics
191
204
  {
192
205
  persist: !disablePersistance,
193
206
  storage: options?.storage,
207
+ httpCookieService: options?.httpCookieService,
194
208
  // Any User specific options override everything else
195
209
  ...options?.user,
196
210
  },
@@ -481,7 +495,7 @@ export class Analytics
481
495
  }
482
496
 
483
497
  private async _dispatch(
484
- event: SegmentEvent,
498
+ event: HightouchEvent,
485
499
  callback?: Callback
486
500
  ): Promise<DispatchedEvent> {
487
501
  const ctx = new Context(event)
@@ -577,7 +591,7 @@ export class Analytics
577
591
  return this
578
592
  }
579
593
 
580
- normalize(msg: SegmentEvent): SegmentEvent {
594
+ normalize(msg: HightouchEvent): HightouchEvent {
581
595
  console.warn(deprecationWarning)
582
596
  return this.eventFactory.normalize(msg)
583
597
  }
@@ -9,7 +9,7 @@ import type {
9
9
  GroupParams,
10
10
  } from '../arguments-resolver'
11
11
  import type { Context } from '../context'
12
- import type { SegmentEvent } from '../events'
12
+ import type { HightouchEvent } from '../events'
13
13
  import type { Group, User } from '../user'
14
14
  import type { LegacyIntegration } from '../../plugins/ajs-destination/types'
15
15
  import { CoreAnalytics } from '@ht-sdks/events-sdk-js-core'
@@ -58,7 +58,7 @@ export interface AnalyticsClassic extends AnalyticsClassicStubs {
58
58
  noConflict(): Analytics
59
59
 
60
60
  /** @deprecated */
61
- normalize(msg: SegmentEvent): SegmentEvent
61
+ normalize(msg: HightouchEvent): HightouchEvent
62
62
 
63
63
  /** @deprecated */
64
64
  readonly failedInitializations: string[]
@@ -74,7 +74,7 @@ export interface AnalyticsClassic extends AnalyticsClassicStubs {
74
74
  }
75
75
 
76
76
  /**
77
- * Interface implemented by concrete Analytics class (commonly accessible if you use "await" on AnalyticsBrowser.load())
77
+ * Interface implemented by concrete Analytics class (commonly accessible if you use "await" on HtEventsBrowser.load())
78
78
  */
79
79
  export interface AnalyticsCore extends CoreAnalytics {
80
80
  track(...args: EventParams): Promise<DispatchedEvent>
@@ -91,9 +91,9 @@ export interface AnalyticsCore extends CoreAnalytics {
91
91
  }
92
92
 
93
93
  /**
94
- * Interface implemented by AnalyticsBrowser (buffered version of analytics) (commonly accessible through AnalyticsBrowser.load())
94
+ * Interface implemented by HtEventsBrowser (buffered version of analytics) (commonly accessible through HtEventsBrowser.load())
95
95
  */
96
- export type AnalyticsBrowserCore = Omit<AnalyticsCore, 'group' | 'user'> & {
96
+ export type HtEventsBrowserCore = Omit<AnalyticsCore, 'group' | 'user'> & {
97
97
  group(): Promise<Group>
98
98
  group(...args: GroupParams): Promise<DispatchedEvent>
99
99
  user(): Promise<User>
@@ -10,7 +10,7 @@ import {
10
10
  JSONObject,
11
11
  Options,
12
12
  EventProperties,
13
- SegmentEvent,
13
+ HightouchEvent,
14
14
  Traits,
15
15
  GroupTraits,
16
16
  UserTraits,
@@ -21,7 +21,7 @@ import { ID, User } from '../user'
21
21
  * Helper for the track method
22
22
  */
23
23
  export function resolveArguments(
24
- eventName: string | SegmentEvent,
24
+ eventName: string | HightouchEvent,
25
25
  properties?: EventProperties | Callback,
26
26
  options?: Options | Callback,
27
27
  callback?: Callback
@@ -1,7 +1,7 @@
1
1
  import { Analytics } from '../analytics'
2
2
  import { Context } from '../context'
3
3
  import { isThenable } from '../../lib/is-thenable'
4
- import { AnalyticsBrowserCore } from '../analytics/interfaces'
4
+ import { HtEventsBrowserCore } from '../analytics/interfaces'
5
5
  import { version } from '../../generated/version'
6
6
  import { getGlobalAnalytics } from '../../lib/global-analytics-helper'
7
7
  import {
@@ -13,7 +13,7 @@ import {
13
13
  } from '../page'
14
14
 
15
15
  /**
16
- * The names of any AnalyticsBrowser methods that also exist on Analytics
16
+ * The names of any HtEventsBrowser methods that also exist on Analytics
17
17
  */
18
18
  export type PreInitMethodName =
19
19
  | 'screen'
@@ -264,7 +264,7 @@ export type AnalyticsLoader = (
264
264
  ) => Promise<[Analytics, Context]>
265
265
 
266
266
  export class AnalyticsBuffered
267
- implements PromiseLike<[Analytics, Context]>, AnalyticsBrowserCore
267
+ implements PromiseLike<[Analytics, Context]>, HtEventsBrowserCore
268
268
  {
269
269
  instance?: Analytics
270
270
  ctx?: Context
@@ -317,7 +317,7 @@ export class AnalyticsBuffered
317
317
  pageView = this._createMethod('pageview')
318
318
  identify = this._createMethod('identify')
319
319
  reset = this._createMethod('reset')
320
- group = this._createMethod('group') as AnalyticsBrowserCore['group']
320
+ group = this._createMethod('group') as HtEventsBrowserCore['group']
321
321
  track = this._createMethod('track')
322
322
  ready = this._createMethod('ready')
323
323
  alias = this._createMethod('alias')
@@ -5,14 +5,14 @@ import {
5
5
  SerializedContext,
6
6
  CancelationOptions,
7
7
  } from '@ht-sdks/events-sdk-js-core'
8
- import { SegmentEvent } from '../events/interfaces'
8
+ import { HightouchEvent } from '../events/interfaces'
9
9
  import { Stats } from '../stats'
10
10
 
11
- export class Context extends CoreContext<SegmentEvent> {
11
+ export class Context extends CoreContext<HightouchEvent> {
12
12
  static override system() {
13
13
  return new this({ type: 'track', event: 'system' })
14
14
  }
15
- constructor(event: SegmentEvent, id?: string) {
15
+ constructor(event: HightouchEvent, id?: string) {
16
16
  super(event, id, new Stats())
17
17
  }
18
18
  }
@@ -6,7 +6,7 @@ import {
6
6
  Integrations,
7
7
  EventProperties,
8
8
  Traits,
9
- SegmentEvent,
9
+ HightouchEvent,
10
10
  } from './interfaces'
11
11
  import md5 from 'spark-md5'
12
12
  import { addPageContext, PageContext } from '../page'
@@ -22,7 +22,7 @@ export class EventFactory {
22
22
  options?: Options,
23
23
  globalIntegrations?: Integrations,
24
24
  pageCtx?: PageContext
25
- ): SegmentEvent {
25
+ ): HightouchEvent {
26
26
  return this.normalize(
27
27
  {
28
28
  ...this.baseEvent(),
@@ -43,8 +43,8 @@ export class EventFactory {
43
43
  options?: Options,
44
44
  globalIntegrations?: Integrations,
45
45
  pageCtx?: PageContext
46
- ): SegmentEvent {
47
- const event: Partial<SegmentEvent> = {
46
+ ): HightouchEvent {
47
+ const event: Partial<HightouchEvent> = {
48
48
  type: 'page' as const,
49
49
  properties: { ...properties },
50
50
  options: { ...options },
@@ -65,7 +65,7 @@ export class EventFactory {
65
65
  {
66
66
  ...this.baseEvent(),
67
67
  ...event,
68
- } as SegmentEvent,
68
+ } as HightouchEvent,
69
69
  pageCtx
70
70
  )
71
71
  }
@@ -77,8 +77,8 @@ export class EventFactory {
77
77
  options?: Options,
78
78
  globalIntegrations?: Integrations,
79
79
  pageCtx?: PageContext
80
- ): SegmentEvent {
81
- const event: Partial<SegmentEvent> = {
80
+ ): HightouchEvent {
81
+ const event: Partial<HightouchEvent> = {
82
82
  type: 'screen' as const,
83
83
  properties: { ...properties },
84
84
  options: { ...options },
@@ -96,7 +96,7 @@ export class EventFactory {
96
96
  {
97
97
  ...this.baseEvent(),
98
98
  ...event,
99
- } as SegmentEvent,
99
+ } as HightouchEvent,
100
100
  pageCtx
101
101
  )
102
102
  }
@@ -107,7 +107,7 @@ export class EventFactory {
107
107
  options?: Options,
108
108
  globalIntegrations?: Integrations,
109
109
  pageCtx?: PageContext
110
- ): SegmentEvent {
110
+ ): HightouchEvent {
111
111
  return this.normalize(
112
112
  {
113
113
  ...this.baseEvent(),
@@ -127,7 +127,7 @@ export class EventFactory {
127
127
  options?: Options,
128
128
  globalIntegrations?: Integrations,
129
129
  pageCtx?: PageContext
130
- ): SegmentEvent {
130
+ ): HightouchEvent {
131
131
  return this.normalize(
132
132
  {
133
133
  ...this.baseEvent(),
@@ -147,8 +147,8 @@ export class EventFactory {
147
147
  options?: Options,
148
148
  globalIntegrations?: Integrations,
149
149
  pageCtx?: PageContext
150
- ): SegmentEvent {
151
- const base: Partial<SegmentEvent> = {
150
+ ): HightouchEvent {
151
+ const base: Partial<HightouchEvent> = {
152
152
  userId: to,
153
153
  type: 'alias' as const,
154
154
  options: { ...options },
@@ -163,20 +163,20 @@ export class EventFactory {
163
163
  return this.normalize({
164
164
  ...base,
165
165
  ...this.baseEvent(),
166
- } as SegmentEvent)
166
+ } as HightouchEvent)
167
167
  }
168
168
 
169
169
  return this.normalize(
170
170
  {
171
171
  ...this.baseEvent(),
172
172
  ...base,
173
- } as SegmentEvent,
173
+ } as HightouchEvent,
174
174
  pageCtx
175
175
  )
176
176
  }
177
177
 
178
- private baseEvent(): Partial<SegmentEvent> {
179
- const base: Partial<SegmentEvent> = {
178
+ private baseEvent(): Partial<HightouchEvent> {
179
+ const base: Partial<HightouchEvent> = {
180
180
  integrations: {},
181
181
  options: {},
182
182
  }
@@ -198,7 +198,7 @@ export class EventFactory {
198
198
  * Builds the context part of an event based on "foreign" keys that
199
199
  * are provided in the `Options` parameter for an Event
200
200
  */
201
- private context(event: SegmentEvent): [object, object] {
201
+ private context(event: HightouchEvent): [object, object] {
202
202
  const optionsKeys = ['integrations', 'anonymousId', 'timestamp', 'userId']
203
203
 
204
204
  const options = event.options ?? {}
@@ -224,7 +224,10 @@ export class EventFactory {
224
224
  return [context, overrides]
225
225
  }
226
226
 
227
- public normalize(event: SegmentEvent, pageCtx?: PageContext): SegmentEvent {
227
+ public normalize(
228
+ event: HightouchEvent,
229
+ pageCtx?: PageContext
230
+ ): HightouchEvent {
228
231
  // set anonymousId globally if we encounter an override
229
232
  event.options?.anonymousId &&
230
233
  this.user.anonymousId(event.options.anonymousId)
@@ -254,7 +257,7 @@ export class EventFactory {
254
257
  const [context, overrides] = this.context(event)
255
258
  const { options, ...rest } = event
256
259
 
257
- const newEvent: SegmentEvent = {
260
+ const newEvent: HightouchEvent = {
258
261
  timestamp: new Date(),
259
262
  ...rest,
260
263
  context,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CoreOptions,
3
- CoreSegmentEvent,
3
+ CoreHightouchEvent,
4
4
  Callback,
5
5
  Integrations,
6
6
  Plan,
@@ -21,7 +21,7 @@ export type { GroupTraits, UserTraits, Traits }
21
21
 
22
22
  export type EventProperties = Record<string, any>
23
23
 
24
- export interface SegmentEvent extends CoreSegmentEvent {}
24
+ export interface HightouchEvent extends CoreHightouchEvent {}
25
25
 
26
26
  export type {
27
27
  Integrations,