@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.
- package/README.md +22 -22
- package/dist/cjs/browser/index.js +36 -28
- package/dist/cjs/browser/index.js.map +1 -1
- package/dist/cjs/browser/standalone-analytics.js +1 -1
- package/dist/cjs/browser/standalone-analytics.js.map +1 -1
- package/dist/cjs/core/analytics/index.js +1 -1
- package/dist/cjs/core/analytics/index.js.map +1 -1
- package/dist/cjs/core/arguments-resolver/index.js.map +1 -1
- package/dist/cjs/core/buffer/index.js.map +1 -1
- package/dist/cjs/core/context/index.js.map +1 -1
- package/dist/cjs/core/events/index.js.map +1 -1
- package/dist/cjs/core/http-cookies/index.js +166 -0
- package/dist/cjs/core/http-cookies/index.js.map +1 -0
- package/dist/cjs/core/page/add-page-context.js.map +1 -1
- package/dist/cjs/core/user/index.js +25 -5
- package/dist/cjs/core/user/index.js.map +1 -1
- package/dist/cjs/generated/version.js +1 -1
- package/dist/cjs/lib/global-analytics-helper.js +1 -1
- package/dist/cjs/lib/global-analytics-helper.js.map +1 -1
- package/dist/cjs/lib/merged-options.js +1 -1
- package/dist/cjs/lib/parse-cdn.js +1 -1
- package/dist/cjs/lib/parse-cdn.js.map +1 -1
- package/dist/cjs/lib/to-facade.js.map +1 -1
- package/dist/cjs/node/index.js +1 -1
- package/dist/cjs/node/index.js.map +1 -1
- package/dist/cjs/plugins/ajs-destination/utils.js +1 -1
- package/dist/cjs/plugins/ajs-destination/utils.js.map +1 -1
- package/dist/cjs/plugins/analytics-node/index.js +2 -2
- package/dist/cjs/plugins/analytics-node/index.js.map +1 -1
- package/dist/cjs/plugins/env-enrichment/index.js.map +1 -1
- package/dist/cjs/plugins/hightouchio/batched-dispatcher.js.map +1 -1
- package/dist/cjs/plugins/legacy-video-plugins/index.js +4 -4
- package/dist/cjs/plugins/legacy-video-plugins/index.js.map +1 -1
- package/dist/cjs/plugins/middleware/index.js.map +1 -1
- package/dist/pkg/browser/index.js +35 -27
- package/dist/pkg/browser/index.js.map +1 -1
- package/dist/pkg/browser/standalone-analytics.js +2 -2
- package/dist/pkg/browser/standalone-analytics.js.map +1 -1
- package/dist/pkg/core/analytics/index.js +1 -1
- package/dist/pkg/core/analytics/index.js.map +1 -1
- package/dist/pkg/core/arguments-resolver/index.js.map +1 -1
- package/dist/pkg/core/buffer/index.js.map +1 -1
- package/dist/pkg/core/context/index.js.map +1 -1
- package/dist/pkg/core/events/index.js.map +1 -1
- package/dist/pkg/core/http-cookies/index.js +163 -0
- package/dist/pkg/core/http-cookies/index.js.map +1 -0
- package/dist/pkg/core/page/add-page-context.js.map +1 -1
- package/dist/pkg/core/user/index.js +25 -5
- package/dist/pkg/core/user/index.js.map +1 -1
- package/dist/pkg/generated/version.js +1 -1
- package/dist/pkg/lib/global-analytics-helper.js +1 -1
- package/dist/pkg/lib/global-analytics-helper.js.map +1 -1
- package/dist/pkg/lib/merged-options.js +1 -1
- package/dist/pkg/lib/parse-cdn.js +1 -1
- package/dist/pkg/lib/parse-cdn.js.map +1 -1
- package/dist/pkg/lib/to-facade.js.map +1 -1
- package/dist/pkg/node/index.js +1 -1
- package/dist/pkg/node/index.js.map +1 -1
- package/dist/pkg/plugins/ajs-destination/utils.js +1 -1
- package/dist/pkg/plugins/ajs-destination/utils.js.map +1 -1
- package/dist/pkg/plugins/analytics-node/index.js +2 -2
- package/dist/pkg/plugins/analytics-node/index.js.map +1 -1
- package/dist/pkg/plugins/env-enrichment/index.js.map +1 -1
- package/dist/pkg/plugins/hightouchio/batched-dispatcher.js.map +1 -1
- package/dist/pkg/plugins/legacy-video-plugins/index.js +6 -6
- package/dist/pkg/plugins/legacy-video-plugins/index.js.map +1 -1
- package/dist/pkg/plugins/middleware/index.js.map +1 -1
- package/dist/types/browser/index.d.ts +12 -12
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/browser/standalone-interface.d.ts +1 -1
- package/dist/types/browser/standalone-interface.d.ts.map +1 -1
- package/dist/types/core/analytics/index.d.ts +12 -3
- package/dist/types/core/analytics/index.d.ts.map +1 -1
- package/dist/types/core/analytics/interfaces.d.ts +5 -5
- package/dist/types/core/analytics/interfaces.d.ts.map +1 -1
- package/dist/types/core/arguments-resolver/index.d.ts +2 -2
- package/dist/types/core/arguments-resolver/index.d.ts.map +1 -1
- package/dist/types/core/buffer/index.d.ts +10 -10
- package/dist/types/core/buffer/index.d.ts.map +1 -1
- package/dist/types/core/context/index.d.ts +3 -3
- package/dist/types/core/context/index.d.ts.map +1 -1
- package/dist/types/core/events/index.d.ts +8 -8
- package/dist/types/core/events/index.d.ts.map +1 -1
- package/dist/types/core/events/interfaces.d.ts +2 -2
- package/dist/types/core/events/interfaces.d.ts.map +1 -1
- package/dist/types/core/http-cookies/index.d.ts +53 -0
- package/dist/types/core/http-cookies/index.d.ts.map +1 -0
- package/dist/types/core/page/add-page-context.d.ts +2 -2
- package/dist/types/core/page/add-page-context.d.ts.map +1 -1
- package/dist/types/core/page/get-page-context.d.ts +1 -1
- package/dist/types/core/stats/remote-metrics.d.ts +1 -1
- package/dist/types/core/user/index.d.ts +5 -0
- package/dist/types/core/user/index.d.ts.map +1 -1
- package/dist/types/generated/version.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/global-analytics-helper.d.ts +4 -4
- package/dist/types/lib/global-analytics-helper.d.ts.map +1 -1
- package/dist/types/lib/merged-options.d.ts +1 -1
- package/dist/types/lib/to-facade.d.ts +4 -4
- package/dist/types/lib/to-facade.d.ts.map +1 -1
- package/dist/types/plugins/analytics-node/index.d.ts +2 -2
- package/dist/types/plugins/analytics-node/index.d.ts.map +1 -1
- package/dist/types/plugins/legacy-video-plugins/index.d.ts +1 -1
- package/dist/types/plugins/legacy-video-plugins/index.d.ts.map +1 -1
- package/dist/types/plugins/middleware/index.d.ts +4 -4
- package/dist/types/plugins/middleware/index.d.ts.map +1 -1
- package/dist/umd/{ajs-destination.bundle.5a985a542b0de08e3e49.js → ajs-destination.bundle.48266e86bbbc2531ac42.js} +2 -2
- package/dist/umd/{ajs-destination.bundle.5a985a542b0de08e3e49.js.map → ajs-destination.bundle.48266e86bbbc2531ac42.js.map} +1 -1
- package/dist/umd/events.min.js +1 -1
- package/dist/umd/events.min.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/legacyVideos.bundle.6250709892bb05b68333.js.map +1 -1
- package/package.json +3 -3
- package/src/browser/index.ts +27 -20
- package/src/browser/standalone-analytics.ts +3 -3
- package/src/browser/standalone-interface.ts +1 -1
- package/src/core/analytics/index.ts +18 -4
- package/src/core/analytics/interfaces.ts +5 -5
- package/src/core/arguments-resolver/index.ts +2 -2
- package/src/core/buffer/index.ts +4 -4
- package/src/core/context/index.ts +3 -3
- package/src/core/events/index.ts +22 -19
- package/src/core/events/interfaces.ts +2 -2
- package/src/core/http-cookies/README.md +194 -0
- package/src/core/http-cookies/index.ts +152 -0
- package/src/core/page/add-page-context.ts +2 -2
- package/src/core/page/get-page-context.ts +1 -1
- package/src/core/stats/remote-metrics.ts +1 -1
- package/src/core/user/index.ts +34 -4
- package/src/generated/version.ts +1 -1
- package/src/index.ts +1 -1
- package/src/lib/global-analytics-helper.ts +4 -4
- package/src/lib/merged-options.ts +1 -1
- package/src/lib/parse-cdn.ts +1 -1
- package/src/lib/to-facade.ts +7 -4
- package/src/node/index.ts +1 -1
- package/src/plugins/ajs-destination/types.ts +1 -1
- package/src/plugins/ajs-destination/utils.ts +1 -1
- package/src/plugins/analytics-node/index.ts +5 -5
- package/src/plugins/env-enrichment/index.ts +2 -2
- package/src/plugins/hightouchio/batched-dispatcher.ts +3 -3
- package/src/plugins/legacy-video-plugins/index.ts +4 -4
- package/src/plugins/middleware/index.ts +10 -10
- package/src/test-helpers/fixtures/cdn-settings.ts +2 -2
- 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,
|
|
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
|
|
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.
|
|
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": "^
|
|
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",
|
package/src/browser/index.ts
CHANGED
|
@@ -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
|
-
//
|
|
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
|
|
96
|
+
export interface HtEventsBrowserSettings extends AnalyticsSettings {
|
|
96
97
|
/**
|
|
97
|
-
* The settings for the
|
|
98
|
-
* If provided, `
|
|
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
|
|
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:
|
|
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
|
|
416
|
+
* The public browser interface for Hightouch Events
|
|
410
417
|
*
|
|
411
418
|
* @example
|
|
412
419
|
* ```ts
|
|
413
|
-
* export const
|
|
414
|
-
*
|
|
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
|
|
425
|
+
export class HtEventsBrowser extends AnalyticsBuffered {
|
|
419
426
|
private _resolveLoadStart: (
|
|
420
|
-
settings:
|
|
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<
|
|
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
|
|
457
|
+
* export const analytics = new HtEventsBrowser()
|
|
451
458
|
* analytics.load({ writeKey: 'foo' })
|
|
452
459
|
* ```
|
|
453
460
|
*/
|
|
454
461
|
load(
|
|
455
|
-
settings:
|
|
462
|
+
settings: HtEventsBrowserSettings,
|
|
456
463
|
options: InitOptions = {}
|
|
457
|
-
):
|
|
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 =
|
|
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:
|
|
481
|
+
settings: HtEventsBrowserSettings,
|
|
475
482
|
options: InitOptions = {}
|
|
476
|
-
):
|
|
477
|
-
return new
|
|
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
|
|
491
|
+
return HtEventsBrowser.load({ writeKey }, options).then((res) => res[0])
|
|
485
492
|
}
|
|
486
493
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HtEventsBrowser } from '.'
|
|
2
2
|
import { embeddedWriteKey } from '../lib/embedded-write-key'
|
|
3
|
-
import {
|
|
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
|
|
60
|
+
(await HtEventsBrowser.standalone(writeKey, options)) as HtEventsSnippet
|
|
61
61
|
)
|
|
62
62
|
}
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
Integrations,
|
|
21
21
|
Plan,
|
|
22
22
|
EventProperties,
|
|
23
|
-
|
|
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.
|
|
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:
|
|
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:
|
|
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 {
|
|
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:
|
|
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
|
|
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
|
|
94
|
+
* Interface implemented by HtEventsBrowser (buffered version of analytics) (commonly accessible through HtEventsBrowser.load())
|
|
95
95
|
*/
|
|
96
|
-
export type
|
|
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
|
-
|
|
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 |
|
|
24
|
+
eventName: string | HightouchEvent,
|
|
25
25
|
properties?: EventProperties | Callback,
|
|
26
26
|
options?: Options | Callback,
|
|
27
27
|
callback?: Callback
|
package/src/core/buffer/index.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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]>,
|
|
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
|
|
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 {
|
|
8
|
+
import { HightouchEvent } from '../events/interfaces'
|
|
9
9
|
import { Stats } from '../stats'
|
|
10
10
|
|
|
11
|
-
export class Context extends CoreContext<
|
|
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:
|
|
15
|
+
constructor(event: HightouchEvent, id?: string) {
|
|
16
16
|
super(event, id, new Stats())
|
|
17
17
|
}
|
|
18
18
|
}
|
package/src/core/events/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
Integrations,
|
|
7
7
|
EventProperties,
|
|
8
8
|
Traits,
|
|
9
|
-
|
|
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
|
-
):
|
|
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
|
-
):
|
|
47
|
-
const event: Partial<
|
|
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
|
|
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
|
-
):
|
|
81
|
-
const event: Partial<
|
|
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
|
|
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
|
-
):
|
|
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
|
-
):
|
|
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
|
-
):
|
|
151
|
-
const base: Partial<
|
|
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
|
|
166
|
+
} as HightouchEvent)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
return this.normalize(
|
|
170
170
|
{
|
|
171
171
|
...this.baseEvent(),
|
|
172
172
|
...base,
|
|
173
|
-
} as
|
|
173
|
+
} as HightouchEvent,
|
|
174
174
|
pageCtx
|
|
175
175
|
)
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
private baseEvent(): Partial<
|
|
179
|
-
const base: Partial<
|
|
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:
|
|
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(
|
|
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:
|
|
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
|
-
|
|
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
|
|
24
|
+
export interface HightouchEvent extends CoreHightouchEvent {}
|
|
25
25
|
|
|
26
26
|
export type {
|
|
27
27
|
Integrations,
|