@ht-sdks/events-sdk-js-browser 1.0.4 → 1.1.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 +16 -16
- 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.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/page/add-page-context.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/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.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 +15 -15
- 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.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/page/add-page-context.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/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.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 +3 -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/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/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 +2 -2
- package/src/browser/index.ts +20 -20
- package/src/browser/standalone-analytics.ts +3 -3
- package/src/browser/standalone-interface.ts +1 -1
- package/src/core/analytics/index.ts +4 -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/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/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/plugins/ajs-destination/types.ts +1 -1
- package/src/plugins/ajs-destination/utils.ts +1 -1
- package/src/plugins/analytics-node/index.ts +3 -3
- 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.1.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",
|
package/src/browser/index.ts
CHANGED
|
@@ -53,7 +53,7 @@ export interface LegacyIntegrationConfiguration {
|
|
|
53
53
|
categories: string[]
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// Hightouch.io specific
|
|
57
57
|
retryQueue?: boolean
|
|
58
58
|
|
|
59
59
|
// any extra unknown settings
|
|
@@ -92,15 +92,15 @@ export interface LegacySettings {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export interface
|
|
95
|
+
export interface HtEventsBrowserSettings extends AnalyticsSettings {
|
|
96
96
|
/**
|
|
97
|
-
* The settings for the
|
|
98
|
-
* If provided, `
|
|
97
|
+
* The settings for the Hightouch Source.
|
|
98
|
+
* If provided, `HtEventsBrowser` will not fetch remote settings
|
|
99
99
|
* for the source.
|
|
100
100
|
*/
|
|
101
101
|
cdnSettings?: LegacySettings & Record<string, unknown>
|
|
102
102
|
/**
|
|
103
|
-
* If provided, will override the default
|
|
103
|
+
* If provided, will override the default Hightouch CDN (https://cdn.hightouch-events.com) for this application.
|
|
104
104
|
*/
|
|
105
105
|
cdnURL?: string
|
|
106
106
|
}
|
|
@@ -321,7 +321,7 @@ const defaultSettings: LegacySettings = {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
async function loadAnalytics(
|
|
324
|
-
settings:
|
|
324
|
+
settings: HtEventsBrowserSettings,
|
|
325
325
|
options: InitOptions = {},
|
|
326
326
|
preInitBuffer: PreInitMethodCallBuffer
|
|
327
327
|
): Promise<[Analytics, Context]> {
|
|
@@ -406,24 +406,24 @@ async function loadAnalytics(
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
/**
|
|
409
|
-
* The public browser interface for
|
|
409
|
+
* The public browser interface for Hightouch Events
|
|
410
410
|
*
|
|
411
411
|
* @example
|
|
412
412
|
* ```ts
|
|
413
|
-
* export const
|
|
414
|
-
*
|
|
413
|
+
* export const htevents = new HtEventsBrowser()
|
|
414
|
+
* htevents.load({ writeKey: 'foo' })
|
|
415
415
|
* ```
|
|
416
416
|
* @link https://github.com/ht-sdks/events-sdk-js-mono/tree/master/packages/browser#readme
|
|
417
417
|
*/
|
|
418
|
-
export class
|
|
418
|
+
export class HtEventsBrowser extends AnalyticsBuffered {
|
|
419
419
|
private _resolveLoadStart: (
|
|
420
|
-
settings:
|
|
420
|
+
settings: HtEventsBrowserSettings,
|
|
421
421
|
options: InitOptions
|
|
422
422
|
) => void
|
|
423
423
|
|
|
424
424
|
constructor() {
|
|
425
425
|
const { promise: loadStart, resolve: resolveLoadStart } =
|
|
426
|
-
createDeferred<Parameters<
|
|
426
|
+
createDeferred<Parameters<HtEventsBrowser['load']>>()
|
|
427
427
|
|
|
428
428
|
super((buffer) =>
|
|
429
429
|
loadStart.then(([settings, options]) =>
|
|
@@ -447,14 +447,14 @@ export class AnalyticsBrowser extends AnalyticsBuffered {
|
|
|
447
447
|
*
|
|
448
448
|
* @example
|
|
449
449
|
* ```ts
|
|
450
|
-
* export const analytics = new
|
|
450
|
+
* export const analytics = new HtEventsBrowser()
|
|
451
451
|
* analytics.load({ writeKey: 'foo' })
|
|
452
452
|
* ```
|
|
453
453
|
*/
|
|
454
454
|
load(
|
|
455
|
-
settings:
|
|
455
|
+
settings: HtEventsBrowserSettings,
|
|
456
456
|
options: InitOptions = {}
|
|
457
|
-
):
|
|
457
|
+
): HtEventsBrowser {
|
|
458
458
|
this._resolveLoadStart(settings, options)
|
|
459
459
|
return this
|
|
460
460
|
}
|
|
@@ -464,23 +464,23 @@ export class AnalyticsBrowser extends AnalyticsBuffered {
|
|
|
464
464
|
*
|
|
465
465
|
* @example
|
|
466
466
|
* ```ts
|
|
467
|
-
* const ajs =
|
|
467
|
+
* const ajs = HtEventsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' })
|
|
468
468
|
*
|
|
469
469
|
* ajs.track("foo")
|
|
470
470
|
* ...
|
|
471
471
|
* ```
|
|
472
472
|
*/
|
|
473
473
|
static load(
|
|
474
|
-
settings:
|
|
474
|
+
settings: HtEventsBrowserSettings,
|
|
475
475
|
options: InitOptions = {}
|
|
476
|
-
):
|
|
477
|
-
return new
|
|
476
|
+
): HtEventsBrowser {
|
|
477
|
+
return new HtEventsBrowser().load(settings, options)
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
static standalone(
|
|
481
481
|
writeKey: string,
|
|
482
482
|
options?: InitOptions
|
|
483
483
|
): Promise<Analytics> {
|
|
484
|
-
return
|
|
484
|
+
return HtEventsBrowser.load({ writeKey }, options).then((res) => res[0])
|
|
485
485
|
}
|
|
486
486
|
}
|
|
@@ -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'
|
|
@@ -124,7 +124,7 @@ export interface InitOptions {
|
|
|
124
124
|
*/
|
|
125
125
|
highEntropyValuesClientHints?: HighEntropyHint[]
|
|
126
126
|
/**
|
|
127
|
-
* When using the snippet, this is the key that points to the global analytics instance (e.g. window.
|
|
127
|
+
* When using the snippet, this is the key that points to the global analytics instance (e.g. window.htevents).
|
|
128
128
|
* default: analytics
|
|
129
129
|
*/
|
|
130
130
|
globalAnalyticsKey?: string
|
|
@@ -481,7 +481,7 @@ export class Analytics
|
|
|
481
481
|
}
|
|
482
482
|
|
|
483
483
|
private async _dispatch(
|
|
484
|
-
event:
|
|
484
|
+
event: HightouchEvent,
|
|
485
485
|
callback?: Callback
|
|
486
486
|
): Promise<DispatchedEvent> {
|
|
487
487
|
const ctx = new Context(event)
|
|
@@ -577,7 +577,7 @@ export class Analytics
|
|
|
577
577
|
return this
|
|
578
578
|
}
|
|
579
579
|
|
|
580
|
-
normalize(msg:
|
|
580
|
+
normalize(msg: HightouchEvent): HightouchEvent {
|
|
581
581
|
console.warn(deprecationWarning)
|
|
582
582
|
return this.eventFactory.normalize(msg)
|
|
583
583
|
}
|
|
@@ -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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pick } from '../../lib/pick'
|
|
2
|
-
import { EventProperties,
|
|
2
|
+
import { EventProperties, HightouchEvent } from '../events'
|
|
3
3
|
import { getDefaultPageContext } from './get-page-context'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -9,7 +9,7 @@ import { getDefaultPageContext } from './get-page-context'
|
|
|
9
9
|
* We prefer not to add this information to this function, as it increases the main bundle size.
|
|
10
10
|
*/
|
|
11
11
|
export const addPageContext = (
|
|
12
|
-
event:
|
|
12
|
+
event: HightouchEvent,
|
|
13
13
|
pageCtx = getDefaultPageContext()
|
|
14
14
|
): void => {
|
|
15
15
|
const evtCtx = event.context! // Context should be set earlier in the flow
|
package/src/generated/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated.
|
|
2
|
-
export const version = '1.0
|
|
2
|
+
export const version = '1.1.0'
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './core/events'
|
|
|
7
7
|
export * from './core/plugin'
|
|
8
8
|
export * from './core/user'
|
|
9
9
|
|
|
10
|
-
export type {
|
|
10
|
+
export type { HtEventsSnippet } from './browser/standalone-interface'
|
|
11
11
|
export type { MiddlewareFunction } from './plugins/middleware'
|
|
12
12
|
export { getGlobalAnalytics } from './lib/global-analytics-helper'
|
|
13
13
|
export { UniversalStorage, Store, StorageObject } from './core/storage'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HtEventsSnippet } from '../browser/standalone-interface'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Stores the global window analytics key
|
|
@@ -8,9 +8,9 @@ let _globalAnalyticsKey = 'htevents'
|
|
|
8
8
|
/**
|
|
9
9
|
* Gets the global analytics/buffer
|
|
10
10
|
* @param key name of the window property where the buffer is stored (default: analytics)
|
|
11
|
-
* @returns
|
|
11
|
+
* @returns HtEventsSnippet
|
|
12
12
|
*/
|
|
13
|
-
export function getGlobalAnalytics():
|
|
13
|
+
export function getGlobalAnalytics(): HtEventsSnippet | undefined {
|
|
14
14
|
return (window as any)[_globalAnalyticsKey]
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -26,6 +26,6 @@ export function setGlobalAnalyticsKey(key: string) {
|
|
|
26
26
|
* Sets the global analytics object
|
|
27
27
|
* @param analytics analytics snippet
|
|
28
28
|
*/
|
|
29
|
-
export function setGlobalAnalytics(analytics:
|
|
29
|
+
export function setGlobalAnalytics(analytics: HtEventsSnippet): void {
|
|
30
30
|
;(window as any)[_globalAnalyticsKey] = analytics
|
|
31
31
|
}
|
|
@@ -5,7 +5,7 @@ import { LegacySettings } from '../browser'
|
|
|
5
5
|
* Merge legacy settings and initialized Integration option overrides.
|
|
6
6
|
*
|
|
7
7
|
* This will merge any options that were passed from initialization into
|
|
8
|
-
* overrides for settings that are returned by the
|
|
8
|
+
* overrides for settings that are returned by the Hightouch CDN.
|
|
9
9
|
*
|
|
10
10
|
* i.e. this allows for passing options directly into destinations from
|
|
11
11
|
* the Analytics constructor.
|
package/src/lib/parse-cdn.ts
CHANGED
|
@@ -45,7 +45,7 @@ export const getCDN = (): string => {
|
|
|
45
45
|
// it's possible that the CDN is not found in the page because:
|
|
46
46
|
// - the script is loaded through a proxy
|
|
47
47
|
// - the script is removed after execution
|
|
48
|
-
// in this case, we fall back to the default
|
|
48
|
+
// in this case, we fall back to the default Hightouch CDN
|
|
49
49
|
return `https://cdn.hightouch-events.com`
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/lib/to-facade.ts
CHANGED
|
@@ -8,13 +8,16 @@ import {
|
|
|
8
8
|
Screen,
|
|
9
9
|
Track,
|
|
10
10
|
} from '@segment/facade'
|
|
11
|
-
import {
|
|
11
|
+
import { HightouchEvent } from '../core/events'
|
|
12
12
|
|
|
13
|
-
export type SegmentFacade = Facade<
|
|
14
|
-
obj:
|
|
13
|
+
export type SegmentFacade = Facade<HightouchEvent> & {
|
|
14
|
+
obj: HightouchEvent
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function toFacade(
|
|
17
|
+
export function toFacade(
|
|
18
|
+
evt: HightouchEvent,
|
|
19
|
+
options?: Options
|
|
20
|
+
): SegmentFacade {
|
|
18
21
|
let fcd = new Facade(evt, options)
|
|
19
22
|
|
|
20
23
|
if (evt.type === 'track') {
|
|
@@ -18,7 +18,7 @@ export interface LegacyIntegration extends Emitter {
|
|
|
18
18
|
alias?: (event: Alias) => void | Promise<void>
|
|
19
19
|
group?: (event: Group) => void | Promise<void>
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// Hightouch.io specific
|
|
22
22
|
ontrack?: (event: Track) => void | Promise<void>
|
|
23
23
|
onidentify?: (event: Identify) => void | Promise<void>
|
|
24
24
|
onpage?: (event: Page) => void | Promise<void>
|
|
@@ -15,7 +15,7 @@ export const isInstallableIntegration = (
|
|
|
15
15
|
// checking for iterable is a quick fix we need in place to prevent
|
|
16
16
|
// errors showing Iterable as a failed destiantion. Ideally, we should
|
|
17
17
|
// fix the Iterable metadata instead, but that's a longer process.
|
|
18
|
-
return !name.startsWith('
|
|
18
|
+
return !name.startsWith('Hightouch') && name !== 'Iterable' && deviceMode
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const isDisabledIntegration = (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from '../../core/plugin'
|
|
2
2
|
import { Context } from '../../core/context'
|
|
3
|
-
import {
|
|
3
|
+
import { HightouchEvent } from '../../core/events'
|
|
4
4
|
import fetch from 'node-fetch'
|
|
5
5
|
import { version } from '../../generated/version'
|
|
6
6
|
|
|
@@ -14,9 +14,9 @@ interface AnalyticsNodeSettings {
|
|
|
14
14
|
const btoa = (val: string): string => Buffer.from(val).toString('base64')
|
|
15
15
|
|
|
16
16
|
export async function post(
|
|
17
|
-
event:
|
|
17
|
+
event: HightouchEvent,
|
|
18
18
|
writeKey: string
|
|
19
|
-
): Promise<
|
|
19
|
+
): Promise<HightouchEvent> {
|
|
20
20
|
const res = await fetch(
|
|
21
21
|
`https://us-east-1.hightouch-events.com/v1/${event.type}`,
|
|
22
22
|
{
|
|
@@ -2,7 +2,7 @@ import jar from 'js-cookie'
|
|
|
2
2
|
import type { Context } from '../../core/context'
|
|
3
3
|
import type { Plugin } from '../../core/plugin'
|
|
4
4
|
import { version } from '../../generated/version'
|
|
5
|
-
import {
|
|
5
|
+
import { HightouchEvent } from '../../core/events'
|
|
6
6
|
import { Campaign, PluginType } from '@ht-sdks/events-sdk-js-core'
|
|
7
7
|
import { getVersionType } from '../../lib/version-type'
|
|
8
8
|
import { tld } from '../../core/user/tld'
|
|
@@ -84,7 +84,7 @@ export function ampId(): string | undefined {
|
|
|
84
84
|
|
|
85
85
|
function referrerId(
|
|
86
86
|
query: string,
|
|
87
|
-
ctx:
|
|
87
|
+
ctx: HightouchEvent['context'],
|
|
88
88
|
disablePersistance: boolean
|
|
89
89
|
): void {
|
|
90
90
|
const storage = new UniversalStorage<{
|