forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.ts
More file actions
71 lines (69 loc) · 2.66 KB
/
plugins.ts
File metadata and controls
71 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { BrowserPluginConfiguration, BrowserTracker, ParsedIdCookie } from '@snowplow/browser-tracker-core';
import { TrackerCore } from '@snowplow/tracker-core';
/**
* Creates a fake BrowserTracker from a TrackerCore instance in order to use in browser plugins.
* Most of the methods are not implemented and will throw an error if called.
* However, our plugins mostly only call the `core` methods.
*/
function toBrowserTracker(namespace: string, core: TrackerCore): BrowserTracker {
const notImplemented = () => {
throw new Error('Not implemented in React Native');
};
return {
id: namespace,
namespace,
core,
sharedState: {
bufferFlushers: [],
hasLoaded: true,
registeredOnLoadHandlers: [],
},
getDomainSessionIndex: () => 0,
getPageViewId: () => '',
getTabId: () => null,
getCookieName: () => '',
getUserId: () => undefined,
getDomainUserId: () => '',
getDomainUserInfo: (): ParsedIdCookie => ['', '', 0, 0, 0, undefined, '', '', '', undefined, 0],
setReferrerUrl: () => notImplemented,
setCustomUrl: () => notImplemented,
setDocumentTitle: () => notImplemented,
discardHashTag: () => notImplemented,
discardBrace: () => notImplemented,
setCookiePath: () => notImplemented,
setVisitorCookieTimeout: () => notImplemented,
newSession: () => notImplemented,
crossDomainLinker: () => notImplemented,
enableActivityTracking: () => notImplemented,
enableActivityTrackingCallback: () => notImplemented,
disableActivityTracking: () => notImplemented,
disableActivityTrackingCallback: () => notImplemented,
updatePageActivity: () => notImplemented,
setOptOutCookie: () => notImplemented,
setUserId: () => notImplemented,
setUserIdFromLocation: () => notImplemented,
setUserIdFromReferrer: () => notImplemented,
setUserIdFromCookie: () => notImplemented,
setCollectorUrl: () => notImplemented,
setBufferSize: () => notImplemented,
flushBuffer: () => notImplemented,
preservePageViewId: () => notImplemented,
preservePageViewIdForUrl: () => notImplemented,
trackPageView: () => notImplemented,
disableAnonymousTracking: () => notImplemented,
enableAnonymousTracking: () => notImplemented,
clearUserData: () => notImplemented,
addPlugin: () => notImplemented,
};
}
export function newPlugins(namespace: string, core: TrackerCore) {
return {
addPlugin: (plugin: BrowserPluginConfiguration) => {
core.addPlugin(plugin);
if (plugin.plugin.activateBrowserPlugin) {
const browserTracker = toBrowserTracker(namespace, core);
plugin.plugin.activateBrowserPlugin?.(browserTracker);
}
},
};
}