@segment/analytics-browser-actions-heap 1.0.0 → 1.3.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/.eslintcache +1 -0
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +5 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/generated-types.d.ts +8 -0
- package/dist/cjs/generated-types.js +3 -0
- package/dist/cjs/generated-types.js.map +1 -0
- package/dist/cjs/identifyUser/generated-types.d.ts +6 -0
- package/dist/cjs/identifyUser/generated-types.js +3 -0
- package/dist/cjs/identifyUser/generated-types.js.map +1 -0
- package/dist/cjs/identifyUser/index.d.ts +6 -0
- package/dist/cjs/identifyUser/index.js +38 -0
- package/dist/cjs/identifyUser/index.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +95 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/test-utilities.d.ts +7 -0
- package/dist/cjs/test-utilities.js +65 -0
- package/dist/cjs/test-utilities.js.map +1 -0
- package/dist/cjs/trackEvent/generated-types.d.ts +11 -0
- package/dist/cjs/trackEvent/generated-types.js +3 -0
- package/dist/cjs/trackEvent/generated-types.js.map +1 -0
- package/dist/cjs/trackEvent/index.d.ts +6 -0
- package/dist/cjs/trackEvent/index.js +100 -0
- package/dist/cjs/trackEvent/index.js.map +1 -0
- package/dist/cjs/types.d.ts +20 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +10 -0
- package/dist/cjs/utils.js +51 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/generated-types.d.ts +8 -0
- package/dist/esm/generated-types.js +2 -0
- package/dist/esm/generated-types.js.map +1 -0
- package/dist/esm/identifyUser/generated-types.d.ts +6 -0
- package/dist/esm/identifyUser/generated-types.js +2 -0
- package/dist/esm/identifyUser/generated-types.js.map +1 -0
- package/dist/esm/identifyUser/index.d.ts +6 -0
- package/dist/esm/identifyUser/index.js +36 -0
- package/dist/esm/identifyUser/index.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +91 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/test-utilities.d.ts +7 -0
- package/dist/esm/test-utilities.js +59 -0
- package/dist/esm/test-utilities.js.map +1 -0
- package/dist/esm/trackEvent/generated-types.d.ts +11 -0
- package/dist/esm/trackEvent/generated-types.js +2 -0
- package/dist/esm/trackEvent/generated-types.js.map +1 -0
- package/dist/esm/trackEvent/index.d.ts +6 -0
- package/dist/esm/trackEvent/index.js +98 -0
- package/dist/esm/trackEvent/index.js.map +1 -0
- package/dist/esm/types.d.ts +20 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +10 -0
- package/dist/esm/utils.js +45 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Settings } from './generated-types';
|
|
2
|
+
import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types';
|
|
3
|
+
import { HeapApi } from './types';
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
heap: HeapApi;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const destination: BrowserDestinationDefinition<Settings, HeapApi>;
|
|
10
|
+
declare const _default: import("@segment/browser-destination-runtime/types").PluginFactory;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { browserDestination } from '@segment/browser-destination-runtime/shim';
|
|
2
|
+
import { defaultValues } from '@segment/actions-core';
|
|
3
|
+
import trackEvent from './trackEvent';
|
|
4
|
+
import identifyUser from './identifyUser';
|
|
5
|
+
import { isDefined } from './utils';
|
|
6
|
+
export const destination = {
|
|
7
|
+
name: 'Heap Web (Actions)',
|
|
8
|
+
slug: 'actions-heap-web',
|
|
9
|
+
mode: 'device',
|
|
10
|
+
presets: [
|
|
11
|
+
{
|
|
12
|
+
name: 'Track Event',
|
|
13
|
+
subscribe: 'type = "track"',
|
|
14
|
+
partnerAction: 'trackEvent',
|
|
15
|
+
mapping: defaultValues(trackEvent.fields)
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'Identify User',
|
|
19
|
+
subscribe: 'type = "identify"',
|
|
20
|
+
partnerAction: 'identifyUser',
|
|
21
|
+
mapping: defaultValues(identifyUser.fields)
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
settings: {
|
|
25
|
+
appId: {
|
|
26
|
+
label: 'Heap app ID',
|
|
27
|
+
description: 'The app ID of the environment to which you want to send data. You can find this ID on the [Projects](https://heapanalytics.com/app/manage/projects) page.',
|
|
28
|
+
type: 'string',
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
disableTextCapture: {
|
|
32
|
+
label: 'Global data redaction via Disabling Text Capture',
|
|
33
|
+
description: 'Setting to true will redact all target text on your website. For more information visit the heap [docs page](https://developers.heap.io/docs/web#global-data-redaction-via-disabling-text-capture).',
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
required: false
|
|
36
|
+
},
|
|
37
|
+
secureCookie: {
|
|
38
|
+
label: 'Secure Cookie',
|
|
39
|
+
description: 'This option is turned off by default to accommodate websites not served over HTTPS. If your application uses HTTPS, we recommend enabling secure cookies to prevent Heap cookies from being observed by unauthorized parties. For more information visit the heap [docs page](https://developers.heap.io/docs/web#securecookie).',
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
required: false
|
|
42
|
+
},
|
|
43
|
+
trackingServer: {
|
|
44
|
+
label: 'Tracking Server',
|
|
45
|
+
description: 'This is an optional setting. This is used to set up first-party data collection. For most cased this should not be set. For more information visit the heap [docs page](https://developers.heap.io/docs/set-up-first-party-data-collection-in-heap).',
|
|
46
|
+
type: 'string',
|
|
47
|
+
required: false
|
|
48
|
+
},
|
|
49
|
+
hostname: {
|
|
50
|
+
label: 'Hostname',
|
|
51
|
+
description: 'This is an optional setting used to set the host that loads heap-js. This setting is used when heapJS is self-hosted. In most cased this should be left unset. The hostname should not contain https or app id it will be populated like so: https://${hostname}/js/heap-${appId}.js. For more information visit the heap [docs page](https://developers.heap.io/docs/self-hosting-heapjs).',
|
|
52
|
+
type: 'string',
|
|
53
|
+
required: false
|
|
54
|
+
},
|
|
55
|
+
browserArrayLimit: {
|
|
56
|
+
label: 'Browser Array Limit',
|
|
57
|
+
description: 'This is an optional setting. When set, nested array items will be sent in as new Heap events. Defaults to 0.',
|
|
58
|
+
type: 'number',
|
|
59
|
+
required: false
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
initialize: async ({ settings }, deps) => {
|
|
63
|
+
if (window.heap) {
|
|
64
|
+
return window.heap;
|
|
65
|
+
}
|
|
66
|
+
const config = {
|
|
67
|
+
disableTextCapture: settings.disableTextCapture || false,
|
|
68
|
+
secureCookie: settings.secureCookie || false
|
|
69
|
+
};
|
|
70
|
+
if (settings.trackingServer) {
|
|
71
|
+
config.trackingServer = settings.trackingServer;
|
|
72
|
+
}
|
|
73
|
+
window.heap = window.heap || [];
|
|
74
|
+
window.heap.appid = settings.appId;
|
|
75
|
+
window.heap.config = config;
|
|
76
|
+
if (isDefined(settings.hostname)) {
|
|
77
|
+
await deps.loadScript(`https://${settings.hostname}/js/heap-${settings.appId}.js`);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await deps.loadScript(`https://cdn.heapanalytics.com/js/heap-${settings.appId}.js`);
|
|
81
|
+
}
|
|
82
|
+
await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'heap'), 100);
|
|
83
|
+
return window.heap;
|
|
84
|
+
},
|
|
85
|
+
actions: {
|
|
86
|
+
trackEvent,
|
|
87
|
+
identifyUser
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
export default browserDestination(destination);
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,UAAU,MAAM,cAAc,CAAA;AACrC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AASnC,MAAM,CAAC,MAAM,WAAW,GAAoD;IAC1E,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE;QACP;YACE,IAAI,EAAE,aAAa;YACnB,SAAS,EAAE,gBAAgB;YAC3B,aAAa,EAAE,YAAY;YAC3B,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC;SAC1C;QACD;YACE,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,mBAAmB;YAC9B,aAAa,EAAE,cAAc;YAC7B,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC;SAC5C;KACF;IACD,QAAQ,EAAE;QAER,KAAK,EAAE;YACL,KAAK,EAAE,aAAa;YACpB,WAAW,EACT,2JAA2J;YAC7J,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf;QACD,kBAAkB,EAAE;YAClB,KAAK,EAAE,kDAAkD;YACzD,WAAW,EACT,qMAAqM;YACvM,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,KAAK;SAChB;QACD,YAAY,EAAE;YACZ,KAAK,EAAE,eAAe;YACtB,WAAW,EACT,kUAAkU;YACpU,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,KAAK;SAChB;QACD,cAAc,EAAE;YACd,KAAK,EAAE,i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AC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;QAEvF,OAAO,MAAM,CAAC,IAAI,CAAA;IACpB,CAAC;IAED,OAAO,EAAE;QACP,UAAU;QACV,YAAY;KACb;CACF,CAAA;AAED,eAAe,kBAAkB,CAAC,WAAW,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HeapApi } from './types';
|
|
2
|
+
import { Subscription } from '@segment/browser-destination-runtime/types';
|
|
3
|
+
export declare const HEAP_TEST_ENV_ID = "1";
|
|
4
|
+
export declare const createMockedHeapJsSdk: () => HeapApi;
|
|
5
|
+
export declare const trackEventSubscription: Subscription;
|
|
6
|
+
export declare const identifyUserSubscription: Subscription;
|
|
7
|
+
export declare const mockHeapJsHttpRequest: () => void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import nock from 'nock';
|
|
2
|
+
export const HEAP_TEST_ENV_ID = '1';
|
|
3
|
+
export const createMockedHeapJsSdk = () => {
|
|
4
|
+
return {
|
|
5
|
+
appid: HEAP_TEST_ENV_ID,
|
|
6
|
+
config: {
|
|
7
|
+
disableTextCapture: true,
|
|
8
|
+
secureCookie: true
|
|
9
|
+
},
|
|
10
|
+
load: jest.fn(),
|
|
11
|
+
track: jest.fn(),
|
|
12
|
+
identify: jest.fn(),
|
|
13
|
+
addUserProperties: jest.fn()
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export const trackEventSubscription = {
|
|
17
|
+
partnerAction: 'trackEvent',
|
|
18
|
+
name: 'Track Event',
|
|
19
|
+
enabled: true,
|
|
20
|
+
subscribe: 'type = "track"',
|
|
21
|
+
mapping: {
|
|
22
|
+
name: {
|
|
23
|
+
'@path': '$.name'
|
|
24
|
+
},
|
|
25
|
+
properties: {
|
|
26
|
+
'@path': '$.properties'
|
|
27
|
+
},
|
|
28
|
+
identity: {
|
|
29
|
+
'@path': '$.userId'
|
|
30
|
+
},
|
|
31
|
+
anonymousId: {
|
|
32
|
+
'@path': '$.anonymousId'
|
|
33
|
+
},
|
|
34
|
+
traits: {
|
|
35
|
+
'@path': '$.context.traits'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const identifyUserSubscription = {
|
|
40
|
+
partnerAction: 'identifyUser',
|
|
41
|
+
name: 'Identify User',
|
|
42
|
+
enabled: true,
|
|
43
|
+
subscribe: 'type = "identify"',
|
|
44
|
+
mapping: {
|
|
45
|
+
anonymousId: {
|
|
46
|
+
'@path': '$.anonymousId'
|
|
47
|
+
},
|
|
48
|
+
userId: {
|
|
49
|
+
'@path': '$.userId'
|
|
50
|
+
},
|
|
51
|
+
traits: {
|
|
52
|
+
'@path': '$.traits'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export const mockHeapJsHttpRequest = () => {
|
|
57
|
+
nock('https://cdn.heapanalytics.com').get(`/js/heap-${HEAP_TEST_ENV_ID}.js`).reply(200, {});
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=test-utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utilities.js","sourceRoot":"","sources":["../../src/test-utilities.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAEnC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAY,EAAE;IACjD,OAAO;QACL,KAAK,EAAE,gBAAgB;QACvB,MAAM,EAAE;YACN,kBAAkB,EAAE,IAAI;YACxB,YAAY,EAAE,IAAI;SACnB;QACD,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACnB,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;KAC7B,CAAA;AACH,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,sBAAsB,GAAiB;IAClD,aAAa,EAAE,YAAY;IAC3B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,gBAAgB;IAC3B,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,OAAO,EAAE,QAAQ;SAClB;QACD,UAAU,EAAE;YACV,OAAO,EAAE,cAAc;SACxB;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,UAAU;SACpB;QACD,WAAW,EAAE;YACX,OAAO,EAAE,eAAe;SACzB;QACD,MAAM,EAAE;YACN,OAAO,EAAE,kBAAkB;SAC5B;KACF;CACF,CAAA;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAiB;IACpD,aAAa,EAAE,cAAc;IAC7B,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,mBAAmB;IAC9B,OAAO,EAAE;QACP,WAAW,EAAE;YACX,OAAO,EAAE,eAAe;SACzB;QACD,MAAM,EAAE;YACN,OAAO,EAAE,UAAU;SACpB;QACD,MAAM,EAAE;YACN,OAAO,EAAE,UAAU;SACpB;KACF;CACF,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAS,EAAE;IAC9C,IAAI,CAAC,+BAA+B,CAAC,CAAC,GAAG,CAAC,YAAY,gBAAgB,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAC7F,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/trackEvent/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
|
|
2
|
+
import type { Settings } from '../generated-types';
|
|
3
|
+
import type { Payload } from './generated-types';
|
|
4
|
+
import { HeapApi } from '../types';
|
|
5
|
+
declare const action: BrowserActionDefinition<Settings, HeapApi, Payload>;
|
|
6
|
+
export default action;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { HEAP_SEGMENT_BROWSER_LIBRARY_NAME } from '../constants';
|
|
2
|
+
import { isDefined, flat, flattenProperties } from '../utils';
|
|
3
|
+
const action = {
|
|
4
|
+
title: 'Track Event',
|
|
5
|
+
description: 'Track events',
|
|
6
|
+
platform: 'web',
|
|
7
|
+
defaultSubscription: 'type = "track"',
|
|
8
|
+
fields: {
|
|
9
|
+
name: {
|
|
10
|
+
description: 'The name of the event.',
|
|
11
|
+
label: 'Name',
|
|
12
|
+
required: true,
|
|
13
|
+
type: 'string',
|
|
14
|
+
default: {
|
|
15
|
+
'@path': '$.event'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
properties: {
|
|
19
|
+
description: 'A JSON object containing additional information about the event that will be indexed by Heap.',
|
|
20
|
+
label: 'Properties',
|
|
21
|
+
required: false,
|
|
22
|
+
type: 'object',
|
|
23
|
+
default: {
|
|
24
|
+
'@path': '$.properties'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
identity: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
required: false,
|
|
30
|
+
label: 'Identity',
|
|
31
|
+
description: 'a string that uniquely identifies a user, such as an email, handle, or username. This means no two users in one environment may share the same identity. More on identify: https://developers.heap.io/docs/using-identify'
|
|
32
|
+
},
|
|
33
|
+
anonymousId: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
required: false,
|
|
36
|
+
description: 'The segment anonymous identifier for the user',
|
|
37
|
+
label: 'Anonymous ID',
|
|
38
|
+
default: {
|
|
39
|
+
'@path': '$.anonymousId'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
traits: {
|
|
43
|
+
label: 'User Properties',
|
|
44
|
+
type: 'object',
|
|
45
|
+
description: 'An object with key-value properties you want associated with the user. Each property must either be a number or string with fewer than 1024 characters.',
|
|
46
|
+
default: {
|
|
47
|
+
'@path': '$.context.traits'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
perform: (heap, event) => {
|
|
52
|
+
if (event.payload.anonymousId || isDefined(event.payload?.traits)) {
|
|
53
|
+
const traits = flat(event.payload?.traits);
|
|
54
|
+
heap.addUserProperties({
|
|
55
|
+
...(isDefined(event.payload.anonymousId) && { anonymous_id: event.payload.anonymousId }),
|
|
56
|
+
...(isDefined(traits) && traits)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (event.payload?.identity && isDefined(event.payload?.identity)) {
|
|
60
|
+
heap.identify(event.payload.identity);
|
|
61
|
+
}
|
|
62
|
+
let eventProperties = Object.assign({}, event.payload.properties);
|
|
63
|
+
const eventName = event.payload.name;
|
|
64
|
+
const browserArrayLimit = event.settings.browserArrayLimit || 0;
|
|
65
|
+
const browserArrayLimitSet = !!browserArrayLimit;
|
|
66
|
+
let arrayEventsCount = 0;
|
|
67
|
+
for (const [key, value] of Object.entries(eventProperties)) {
|
|
68
|
+
if (browserArrayLimitSet && arrayEventsCount >= browserArrayLimit) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (!Array.isArray(value)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
delete eventProperties[key];
|
|
75
|
+
eventProperties = { ...eventProperties, ...flat({ [key]: value }) };
|
|
76
|
+
const arrayLength = value.length;
|
|
77
|
+
let arrayPropertyValues;
|
|
78
|
+
if (browserArrayLimitSet && arrayLength + arrayEventsCount > browserArrayLimit) {
|
|
79
|
+
arrayPropertyValues = value.splice(0, browserArrayLimit - arrayEventsCount);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
arrayPropertyValues = value;
|
|
83
|
+
}
|
|
84
|
+
arrayEventsCount += arrayLength;
|
|
85
|
+
arrayPropertyValues.forEach((arrayPropertyValue) => {
|
|
86
|
+
const arrayProperties = flattenProperties(arrayPropertyValue);
|
|
87
|
+
heapTrack(heap, `${eventName} ${key} item`, arrayProperties);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
heapTrack(heap, eventName, eventProperties);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const heapTrack = (heap, eventName, properties) => {
|
|
94
|
+
properties.segment_library = HEAP_SEGMENT_BROWSER_LIBRARY_NAME;
|
|
95
|
+
heap.track(eventName, properties);
|
|
96
|
+
};
|
|
97
|
+
export default action;
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trackEvent/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE7D,MAAM,MAAM,GAAwD;IAClE,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,cAAc;IAC3B,QAAQ,EAAE,KAAK;IACf,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,WAAW,EAAE,wBAAwB;YACrC,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,SAAS;aACnB;SACF;QACD,UAAU,EAAE;YACV,WAAW,EAAE,+FAA+F;YAC5G,KAAK,EAAE,YAAY;YACnB,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,cAAc;aACxB;SACF;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,UAAU;YACjB,WAAW,EACT,2NAA2N;SAC9N;QACD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,+CAA+C;YAC5D,KAAK,EA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CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare type UserConfig = {
|
|
2
|
+
trackingServer?: string;
|
|
3
|
+
disableTextCapture: boolean;
|
|
4
|
+
secureCookie: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare type UserProperties = {
|
|
7
|
+
[k: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
declare type EventProperties = {
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
export declare type HeapApi = {
|
|
13
|
+
appid: string;
|
|
14
|
+
track: (eventName: string, eventProperties: EventProperties, library?: string) => void;
|
|
15
|
+
load: () => void;
|
|
16
|
+
config: UserConfig;
|
|
17
|
+
identify: (identity: string) => void;
|
|
18
|
+
addUserProperties: (properties: UserProperties) => void;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function isDefined(value: string | undefined | null | number | object): boolean;
|
|
2
|
+
export declare type Properties = {
|
|
3
|
+
[k: string]: unknown;
|
|
4
|
+
};
|
|
5
|
+
declare type FlattenProperties = object & {
|
|
6
|
+
[k: string]: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function flat(data?: Properties, prefix?: string): FlattenProperties | undefined;
|
|
9
|
+
export declare const flattenProperties: (arrayPropertyValue: any) => {};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function isDefined(value) {
|
|
2
|
+
if (typeof value === 'object') {
|
|
3
|
+
return !!value && Object.keys(value).length !== 0;
|
|
4
|
+
}
|
|
5
|
+
return !(value === undefined || value === null || value === '' || value === 0 || value === '0');
|
|
6
|
+
}
|
|
7
|
+
export function flat(data, prefix = '') {
|
|
8
|
+
if (!isDefined(data)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
let result = {};
|
|
12
|
+
for (const key in data) {
|
|
13
|
+
if (typeof data[key] == 'object' && data[key] !== null) {
|
|
14
|
+
const flatten = flat(data[key], prefix + '.' + key);
|
|
15
|
+
result = { ...result, ...flatten };
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const stringifiedValue = stringify(data[key]);
|
|
19
|
+
result[(prefix + '.' + key).replace(/^\./, '')] = stringifiedValue;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
export const flattenProperties = (arrayPropertyValue) => {
|
|
25
|
+
let arrayProperties = {};
|
|
26
|
+
for (const [key, value] of Object.entries(arrayPropertyValue)) {
|
|
27
|
+
if (typeof value == 'object' && value !== null) {
|
|
28
|
+
arrayProperties = { ...arrayProperties, ...flat({ [key]: value }) };
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
arrayProperties = Object.assign(arrayProperties, { [key]: value });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return arrayProperties;
|
|
35
|
+
};
|
|
36
|
+
function stringify(value) {
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
41
|
+
return value.toString();
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify(value);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,KAAkD;IAC1E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAA;KAClD;IACD,OAAO,CAAC,CAAC,KAAK,KAAK,S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