@amplitude/analytics-browser 2.0.0-beta.3 → 2.0.0-beta.5
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 +1 -1
- package/lib/cjs/browser-client.d.ts +1 -1
- package/lib/cjs/browser-client.d.ts.map +1 -1
- package/lib/cjs/browser-client.js +17 -1
- package/lib/cjs/browser-client.js.map +1 -1
- package/lib/cjs/index.d.ts +4 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/plugins/default-page-view-event-enrichment.d.ts +3 -0
- package/lib/cjs/plugins/default-page-view-event-enrichment.d.ts.map +1 -0
- package/lib/cjs/plugins/default-page-view-event-enrichment.js +47 -0
- package/lib/cjs/plugins/default-page-view-event-enrichment.js.map +1 -0
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/browser-client.d.ts +1 -1
- package/lib/esm/browser-client.d.ts.map +1 -1
- package/lib/esm/browser-client.js +17 -1
- package/lib/esm/browser-client.js.map +1 -1
- package/lib/esm/index.d.ts +4 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/plugins/default-page-view-event-enrichment.d.ts +3 -0
- package/lib/esm/plugins/default-page-view-event-enrichment.d.ts.map +1 -0
- package/lib/esm/plugins/default-page-view-event-enrichment.js +43 -0
- package/lib/esm/plugins/default-page-view-event-enrichment.js.map +1 -0
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/amplitude-snippet-instructions.html +1 -1
- package/lib/scripts/amplitude-snippet-min.js +1 -1
- package/lib/scripts/browser-client.d.ts +1 -1
- package/lib/scripts/browser-client.d.ts.map +1 -1
- package/lib/scripts/index.d.ts +4 -1
- package/lib/scripts/index.d.ts.map +1 -1
- package/lib/scripts/plugins/default-page-view-event-enrichment.d.ts +3 -0
- package/lib/scripts/plugins/default-page-view-event-enrichment.d.ts.map +1 -0
- package/lib/scripts/version.d.ts +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Alternatively, the package is also distributed through a CDN. Copy and paste the
|
|
|
40
40
|
<!-- README_SNIPPET_BLOCK -->
|
|
41
41
|
```html
|
|
42
42
|
<script type="text/javascript">
|
|
43
|
-
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))}}},i=function(e){for(var t=0;t<g.length;t++)o(e,g[t],!1);for(var r=0;r<m.length;r++)o(e,m[r],!0)};r.invoked=!0;var a=t.createElement("script");a.type="text/javascript",a.integrity="sha384-
|
|
43
|
+
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))}}},i=function(e){for(var t=0;t<g.length;t++)o(e,g[t],!1);for(var r=0;r<m.length;r++)o(e,m[r],!0)};r.invoked=!0;var a=t.createElement("script");a.type="text/javascript",a.integrity="sha384-Q7BpoNgh9vSl0jANHiGzOS9exch95VkMc1CsfqaZ/l0NdtBjTblyhmBrye8inB88",a.crossOrigin="anonymous",a.async=!0,a.src="https://cdn.amplitude.com/libs/analytics-browser-2.0.0-beta.5-min.js.gz",a.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var c=t.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c);for(var u=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],p=0;p<l.length;p++)n(u,l[p]);r.Identify=u;for(var d=function(){return this._q=[],this},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],v=0;v<f.length;v++)n(d,f[v]);r.Revenue=d;var g=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(r),r.createInstance=function(e){return r._iq[e]={_q:[]},i(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
|
|
44
44
|
|
|
45
45
|
amplitude.init("YOUR_API_KEY_HERE");
|
|
46
46
|
</script>
|
|
@@ -4,7 +4,7 @@ export declare class AmplitudeBrowser extends AmplitudeCore implements BrowserCl
|
|
|
4
4
|
config: BrowserConfig;
|
|
5
5
|
previousSessionDeviceId: string | undefined;
|
|
6
6
|
previousSessionUserId: string | undefined;
|
|
7
|
-
init(apiKey?: string,
|
|
7
|
+
init(apiKey?: string, userIdOrOptions?: string | BrowserOptions, maybeOptions?: BrowserOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>;
|
|
8
8
|
protected _init(options: BrowserOptions & {
|
|
9
9
|
apiKey: string;
|
|
10
10
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuD,MAAM,2BAA2B,CAAC;AAa/G,OAAO,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Y,CAAC,EAAE,YAAY;IAezD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,YAAY;IAS/G,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;CAQvD"}
|
|
@@ -17,8 +17,24 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
17
17
|
function AmplitudeBrowser() {
|
|
18
18
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
19
19
|
}
|
|
20
|
-
AmplitudeBrowser.prototype.init = function (apiKey,
|
|
20
|
+
AmplitudeBrowser.prototype.init = function (apiKey, userIdOrOptions, maybeOptions) {
|
|
21
21
|
if (apiKey === void 0) { apiKey = ''; }
|
|
22
|
+
var userId;
|
|
23
|
+
var options;
|
|
24
|
+
if (arguments.length > 2) {
|
|
25
|
+
userId = userIdOrOptions;
|
|
26
|
+
options = maybeOptions;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (typeof userIdOrOptions === 'string') {
|
|
30
|
+
userId = userIdOrOptions;
|
|
31
|
+
options = undefined;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
userId = userIdOrOptions === null || userIdOrOptions === void 0 ? void 0 : userIdOrOptions.userId;
|
|
35
|
+
options = userIdOrOptions;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
22
38
|
return (0, analytics_core_1.returnWrapper)(this._init(tslib_1.__assign(tslib_1.__assign({}, options), { userId: userId, apiKey: apiKey })));
|
|
23
39
|
};
|
|
24
40
|
AmplitudeBrowser.prototype._init = function (options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":";;;AAAA,4DAA+G;AAC/G,8EAW4C;AAU5C,yDAAyF;AACzF,6CAA4C;AAC5C,mCAA6D;AAC7D,4F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BAAM,QAAQ,YAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC;IAED,wCAAa,GAAb,UAAc,SAAiB,EAAE,SAA4B,EAAE,QAAmB,EAAE,YAA2B;QAC7G,IAAI,IAAA,gCAAe,EAAC,QAAQ,CAAC,EAAE;YAC7B,IAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;YACjB,QAAQ,GAAG,IAAA,+CAA8B,EAAC,IAAI,yBAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;SAClE;QACD,OAAO,iBAAM,aAAa,YAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3E,CAAC;IAED,kCAAO,GAAP,UAAQ,OAAiB,EAAE,YAA2B;QACpD,IAAI,IAAA,gCAAe,EAAC,OAAO,CAAC,EAAE;YAC5B,IAAM,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;YAChB,OAAO,GAAG,IAAA,+CAA8B,EAAC,IAAI,wBAAO,EAAE,EAAE,KAAK,CAAC,CAAC;SAChE;QACD,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IACH,uBAAC;AAAD,CAAC,AA1LD,CAAsC,8BAAa,GA0LlD;AA1LY,4CAAgB","sourcesContent":["import { AmplitudeCore, Destination, Identify, returnWrapper, Revenue, UUID } from '@amplitude/analytics-core';\nimport {\n getAnalyticsConnector,\n getAttributionTrackingConfig,\n getPageViewTrackingConfig,\n IdentityEventSender,\n isAttributionTrackingEnabled,\n isSessionTrackingEnabled,\n isFileDownloadTrackingEnabled,\n isFormInteractionTrackingEnabled,\n setConnectorDeviceId,\n setConnectorUserId,\n} from '@amplitude/analytics-client-common';\nimport {\n BrowserClient,\n BrowserConfig,\n BrowserOptions,\n EventOptions,\n Identify as IIdentify,\n Revenue as IRevenue,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { useBrowserConfig, createTransport } from './config';\nimport { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser';\nimport { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';\nimport { sessionHandlerPlugin } from './plugins/session-handler';\nimport { formInteractionTracking } from './plugins/form-interaction-tracking';\nimport { fileDownloadTracking } from './plugins/file-download-tracking';\nimport { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_START_EVENT } from './constants';\n\nexport class AmplitudeBrowser extends AmplitudeCore implements BrowserClient {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n previousSessionDeviceId: string | undefined;\n previousSessionUserId: string | undefined;\n\n init(apiKey = '', userId?: string, options?: BrowserOptions) {\n return returnWrapper(this._init({ ...options, userId, apiKey }));\n }\n protected async _init(options: BrowserOptions & { apiKey: string }) {\n // Step 1: Block concurrent initialization\n if (this.initializing) {\n return;\n }\n this.initializing = true;\n\n // Step 2: Create browser config\n const browserOptions = await useBrowserConfig(options.apiKey, options, this);\n await super._init(browserOptions);\n\n // Step 3: Manage session\n if (\n !this.config.sessionId ||\n (this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)\n ) {\n // Either\n // 1) No previous session; or\n // 2) Previous session expired\n this.setSessionId(Date.now());\n }\n\n // Set up the analytics connector to integrate with the experiment SDK.\n // Send events from the experiment SDK and forward identifies to the\n // identity store.\n const connector = getAnalyticsConnector();\n connector.identityStore.setIdentity({\n userId: this.config.userId,\n deviceId: this.config.deviceId,\n });\n\n // Step 4: Install plugins\n // Do not track any events before this\n await this.add(new Destination()).promise;\n await this.add(new Context()).promise;\n await this.add(sessionHandlerPlugin()).promise;\n await this.add(new IdentityEventSender()).promise;\n\n if (isFileDownloadTrackingEnabled(this.config.defaultTracking)) {\n await this.add(fileDownloadTracking()).promise;\n }\n\n if (isFormInteractionTrackingEnabled(this.config.defaultTracking)) {\n await this.add(formInteractionTracking()).promise;\n }\n\n // Add web attribution plugin\n if (isAttributionTrackingEnabled(this.config.defaultTracking)) {\n const attributionTrackingOptions = getAttributionTrackingConfig(this.config);\n const webAttribution = webAttributionPlugin(attributionTrackingOptions);\n await this.add(webAttribution).promise;\n }\n\n // Add page view plugin\n await this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise;\n\n this.initializing = false;\n\n // Step 6: Run queued dispatch functions\n await this.runQueuedFunctions('dispatchQ');\n\n // Step 7: Add the event receiver after running remaining queued functions.\n connector.eventBridge.setEventReceiver((event) => {\n void this.track(event.eventType, event.eventProperties);\n });\n }\n\n getUserId() {\n return this.config?.userId;\n }\n\n setUserId(userId: string | undefined) {\n if (!this.config) {\n this.q.push(this.setUserId.bind(this, userId));\n return;\n }\n if (userId !== this.config.userId || userId === undefined) {\n this.config.userId = userId;\n this.setSessionId(Date.now());\n setConnectorUserId(userId);\n }\n }\n\n getDeviceId() {\n return this.config?.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n if (!this.config) {\n this.q.push(this.setDeviceId.bind(this, deviceId));\n return;\n }\n this.config.deviceId = deviceId;\n setConnectorDeviceId(deviceId);\n }\n\n reset() {\n this.setDeviceId(UUID());\n this.setUserId(undefined);\n }\n\n getSessionId() {\n return this.config?.sessionId;\n }\n\n setSessionId(sessionId: number) {\n if (!this.config) {\n this.q.push(this.setSessionId.bind(this, sessionId));\n return;\n }\n const previousSessionId = this.getSessionId();\n const previousLastEventTime = this.config.lastEventTime;\n\n this.config.sessionId = sessionId;\n this.config.lastEventTime = undefined;\n\n if (isSessionTrackingEnabled(this.config.defaultTracking)) {\n if (previousSessionId && previousLastEventTime) {\n const eventOptions: EventOptions = {\n session_id: previousSessionId,\n time: previousLastEventTime + 1,\n };\n eventOptions.device_id = this.previousSessionDeviceId;\n eventOptions.user_id = this.previousSessionUserId;\n this.track(DEFAULT_SESSION_END_EVENT, undefined, eventOptions);\n }\n\n this.track(DEFAULT_SESSION_START_EVENT, undefined, {\n session_id: sessionId,\n time: sessionId - 1,\n });\n this.previousSessionDeviceId = this.config.deviceId;\n this.previousSessionUserId = this.config.userId;\n }\n }\n\n setTransport(transport: TransportType) {\n if (!this.config) {\n this.q.push(this.setTransport.bind(this, transport));\n return;\n }\n this.config.transportProvider = createTransport(transport);\n }\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n if (eventOptions?.user_id) {\n this.setUserId(eventOptions.user_id);\n }\n if (eventOptions?.device_id) {\n this.setDeviceId(eventOptions.device_id);\n }\n return super.identify(identify, eventOptions);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.groupIdentify(groupType, groupName, identify, eventOptions);\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return super.revenue(revenue, eventOptions);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":";;;AAAA,4DAA+G;AAC/G,8EAW4C;AAU5C,yDAAyF;AACzF,6CAA4C;AAC5C,mCAA6D;AAC7D,4FAAiF;AACjF,kGAAsF;AACtF,6DAAiE;AACjE,iFAA8E;AAC9E,2EAAwE;AACxE,yCAAqF;AAErF;IAAsC,4CAAa;IAAnD;;IAyMA,CAAC;IAlMC,+BAAI,GAAJ,UAAK,MAAW,EAAE,eAAyC,EAAE,YAA6B;QAArF,uBAAA,EAAA,WAAW;QACd,IAAI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CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;SACtC;QACD,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,SAAS,EAAE;YAC3B,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;SAC1C;QACD,OAAO,iBAAM,QAAQ,YAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC;IAED,wCAAa,GAAb,UAAc,SAAiB,EAAE,SAA4B,EAAE,QAAmB,EAAE,YAA2B;QAC7G,IAAI,IAAA,gCAAe,EAAC,QAAQ,CAAC,EAAE;YAC7B,IAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;YACjB,QAAQ,GAAG,IAAA,+CAA8B,EAAC,IAAI,yBAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;SAClE;QACD,OAAO,iBAAM,aAAa,YAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3E,CAAC;IAED,kCAAO,GAAP,UAAQ,OAAiB,EAAE,YAA2B;QACpD,IAAI,IAAA,gCAAe,EAAC,OAAO,CAAC,EAAE;YAC5B,IAAM,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;YAChB,OAAO,GAAG,IAAA,+CAA8B,EAAC,IAAI,wBAAO,EAAE,EAAE,KAAK,CAAC,CAAC;SAChE;QACD,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IACH,uBAAC;AAAD,CAAC,AAzMD,CAAsC,8BAAa,GAyMlD;AAzMY,4CAAgB","sourcesContent":["import { AmplitudeCore, Destination, Identify, returnWrapper, Revenue, UUID } from '@amplitude/analytics-core';\nimport {\n getAnalyticsConnector,\n getAttributionTrackingConfig,\n getPageViewTrackingConfig,\n IdentityEventSender,\n isAttributionTrackingEnabled,\n isSessionTrackingEnabled,\n isFileDownloadTrackingEnabled,\n isFormInteractionTrackingEnabled,\n setConnectorDeviceId,\n setConnectorUserId,\n} from '@amplitude/analytics-client-common';\nimport {\n BrowserClient,\n BrowserConfig,\n BrowserOptions,\n EventOptions,\n Identify as IIdentify,\n Revenue as IRevenue,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { useBrowserConfig, createTransport } from './config';\nimport { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser';\nimport { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';\nimport { sessionHandlerPlugin } from './plugins/session-handler';\nimport { formInteractionTracking } from './plugins/form-interaction-tracking';\nimport { fileDownloadTracking } from './plugins/file-download-tracking';\nimport { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_START_EVENT } from './constants';\n\nexport class AmplitudeBrowser extends AmplitudeCore implements BrowserClient {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n previousSessionDeviceId: string | undefined;\n previousSessionUserId: string | undefined;\n\n init(apiKey = '', userIdOrOptions?: string | BrowserOptions, maybeOptions?: BrowserOptions) {\n let userId: string | undefined;\n let options: BrowserOptions | undefined;\n\n if (arguments.length > 2) {\n userId = userIdOrOptions as string | undefined;\n options = maybeOptions;\n } else {\n if (typeof userIdOrOptions === 'string') {\n userId = userIdOrOptions;\n options = undefined;\n } else {\n userId = userIdOrOptions?.userId;\n options = userIdOrOptions;\n }\n }\n return returnWrapper(this._init({ ...options, userId, apiKey }));\n }\n protected async _init(options: BrowserOptions & { apiKey: string }) {\n // Step 1: Block concurrent initialization\n if (this.initializing) {\n return;\n }\n this.initializing = true;\n\n // Step 2: Create browser config\n const browserOptions = await useBrowserConfig(options.apiKey, options, this);\n await super._init(browserOptions);\n\n // Step 3: Manage session\n if (\n !this.config.sessionId ||\n (this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)\n ) {\n // Either\n // 1) No previous session; or\n // 2) Previous session expired\n this.setSessionId(Date.now());\n }\n\n // Set up the analytics connector to integrate with the experiment SDK.\n // Send events from the experiment SDK and forward identifies to the\n // identity store.\n const connector = getAnalyticsConnector();\n connector.identityStore.setIdentity({\n userId: this.config.userId,\n deviceId: this.config.deviceId,\n });\n\n // Step 4: Install plugins\n // Do not track any events before this\n await this.add(new Destination()).promise;\n await this.add(new Context()).promise;\n await this.add(sessionHandlerPlugin()).promise;\n await this.add(new IdentityEventSender()).promise;\n\n if (isFileDownloadTrackingEnabled(this.config.defaultTracking)) {\n await this.add(fileDownloadTracking()).promise;\n }\n\n if (isFormInteractionTrackingEnabled(this.config.defaultTracking)) {\n await this.add(formInteractionTracking()).promise;\n }\n\n // Add web attribution plugin\n if (isAttributionTrackingEnabled(this.config.defaultTracking)) {\n const attributionTrackingOptions = getAttributionTrackingConfig(this.config);\n const webAttribution = webAttributionPlugin(attributionTrackingOptions);\n await this.add(webAttribution).promise;\n }\n\n // Add page view plugin\n await this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise;\n\n this.initializing = false;\n\n // Step 6: Run queued dispatch functions\n await this.runQueuedFunctions('dispatchQ');\n\n // Step 7: Add the event receiver after running remaining queued functions.\n connector.eventBridge.setEventReceiver((event) => {\n void this.track(event.eventType, event.eventProperties);\n });\n }\n\n getUserId() {\n return this.config?.userId;\n }\n\n setUserId(userId: string | undefined) {\n if (!this.config) {\n this.q.push(this.setUserId.bind(this, userId));\n return;\n }\n if (userId !== this.config.userId || userId === undefined) {\n this.config.userId = userId;\n this.setSessionId(Date.now());\n setConnectorUserId(userId);\n }\n }\n\n getDeviceId() {\n return this.config?.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n if (!this.config) {\n this.q.push(this.setDeviceId.bind(this, deviceId));\n return;\n }\n this.config.deviceId = deviceId;\n setConnectorDeviceId(deviceId);\n }\n\n reset() {\n this.setDeviceId(UUID());\n this.setUserId(undefined);\n }\n\n getSessionId() {\n return this.config?.sessionId;\n }\n\n setSessionId(sessionId: number) {\n if (!this.config) {\n this.q.push(this.setSessionId.bind(this, sessionId));\n return;\n }\n const previousSessionId = this.getSessionId();\n const previousLastEventTime = this.config.lastEventTime;\n\n this.config.sessionId = sessionId;\n this.config.lastEventTime = undefined;\n\n if (isSessionTrackingEnabled(this.config.defaultTracking)) {\n if (previousSessionId && previousLastEventTime) {\n const eventOptions: EventOptions = {\n session_id: previousSessionId,\n time: previousLastEventTime + 1,\n };\n eventOptions.device_id = this.previousSessionDeviceId;\n eventOptions.user_id = this.previousSessionUserId;\n this.track(DEFAULT_SESSION_END_EVENT, undefined, eventOptions);\n }\n\n this.track(DEFAULT_SESSION_START_EVENT, undefined, {\n session_id: sessionId,\n time: sessionId - 1,\n });\n this.previousSessionDeviceId = this.config.deviceId;\n this.previousSessionUserId = this.config.userId;\n }\n }\n\n setTransport(transport: TransportType) {\n if (!this.config) {\n this.q.push(this.setTransport.bind(this, transport));\n return;\n }\n this.config.transportProvider = createTransport(transport);\n }\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n if (eventOptions?.user_id) {\n this.setUserId(eventOptions.user_id);\n }\n if (eventOptions?.device_id) {\n this.setDeviceId(eventOptions.device_id);\n }\n return super.identify(identify, eventOptions);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.groupIdentify(groupType, groupName, identify, eventOptions);\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return super.revenue(revenue, eventOptions);\n }\n}\n"]}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { createInstance } from './browser-client-factory';
|
|
2
|
-
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<void>, flush: () => import("@amplitude/analytics-types").AmplitudeReturn<void>, getDeviceId: () => string | undefined, getSessionId: () => number | undefined, getUserId: () => string | undefined, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, identify: (identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, init:
|
|
2
|
+
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<void>, flush: () => import("@amplitude/analytics-types").AmplitudeReturn<void>, getDeviceId: () => string | undefined, getSessionId: () => number | undefined, getUserId: () => string | undefined, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, identify: (identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, init: {
|
|
3
|
+
(apiKey: string, options?: import("@amplitude/analytics-types").BrowserOptions | undefined): import("@amplitude/analytics-types").AmplitudeReturn<void>;
|
|
4
|
+
(apiKey: string, userId?: string | undefined, options?: import("@amplitude/analytics-types").BrowserOptions | undefined): import("@amplitude/analytics-types").AmplitudeReturn<void>;
|
|
5
|
+
}, logEvent: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, remove: (pluginName: string) => import("@amplitude/analytics-types").AmplitudeReturn<void>, reset: () => void, revenue: (revenue: import("@amplitude/analytics-types").Revenue, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, setDeviceId: (deviceId: string) => void, setGroup: (groupType: string, groupName: string | string[], eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, setOptOut: (optOut: boolean) => void, setSessionId: (sessionId: number) => void, setTransport: (transport: import("@amplitude/analytics-types").TransportType) => void, setUserId: (userId: string | undefined) => void, track: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>;
|
|
3
6
|
export { runQueuedFunctions } from './utils/snippet-helper';
|
|
4
7
|
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
5
8
|
export * as Types from '@amplitude/analytics-types';
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,eAAO,MACL,GAAG,uHACH,KAAK,oEACL,WAAW,4BACX,YAAY,4BACZ,SAAS,4BACT,aAAa,iSACb,QAAQ,gPACR,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,eAAO,MACL,GAAG,uHACH,KAAK,oEACL,WAAW,4BACX,YAAY,4BACZ,SAAS,4BACT,aAAa,iSACb,QAAQ,gPACR,IAAI;;;GACJ,QAAQ,+SACR,MAAM,sFACN,KAAK,cACL,OAAO,8OACP,WAAW,8BACX,QAAQ,wOACR,SAAS,6BACT,YAAY,+BACZ,YAAY,2EACZ,SAAS,wCACT,KAAK,6SACG,CAAC;AACX,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-page-view-event-enrichment.d.ts","sourceRoot":"","sources":["../../../src/plugins/default-page-view-event-enrichment.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,gBAAgB,EAAc,MAAM,4BAA4B,CAAC;AAmBrF,eAAO,MAAM,8BAA8B,QAAO,gBA2BjD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var _this = this;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultPageViewEventEnrichment = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
6
|
+
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
7
|
+
var constants_1 = require("../constants");
|
|
8
|
+
var eventPropertyMap = {
|
|
9
|
+
page_domain: "".concat(constants_1.DEFAULT_EVENT_PREFIX, " Page Domain"),
|
|
10
|
+
page_location: "".concat(constants_1.DEFAULT_EVENT_PREFIX, " Page Location"),
|
|
11
|
+
page_path: "".concat(constants_1.DEFAULT_EVENT_PREFIX, " Page Path"),
|
|
12
|
+
page_title: "".concat(constants_1.DEFAULT_EVENT_PREFIX, " Page Title"),
|
|
13
|
+
page_url: "".concat(constants_1.DEFAULT_EVENT_PREFIX, " Page URL"),
|
|
14
|
+
};
|
|
15
|
+
var defaultPageViewEventEnrichment = function () {
|
|
16
|
+
var name = '@amplitude/plugin-default-page-view-event-enrichment-browser';
|
|
17
|
+
var type = analytics_types_1.PluginType.ENRICHMENT;
|
|
18
|
+
var setup = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
19
|
+
return [2 /*return*/, undefined];
|
|
20
|
+
}); }); };
|
|
21
|
+
var execute = function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
22
|
+
return tslib_1.__generator(this, function (_a) {
|
|
23
|
+
if (event.event_type === constants_1.DEFAULT_PAGE_VIEW_EVENT && event.event_properties) {
|
|
24
|
+
event.event_properties = Object.entries(event.event_properties).reduce(function (acc, _a) {
|
|
25
|
+
var _b = tslib_1.__read(_a, 2), key = _b[0], value = _b[1];
|
|
26
|
+
var transformedPropertyName = eventPropertyMap[key];
|
|
27
|
+
if (transformedPropertyName) {
|
|
28
|
+
acc[transformedPropertyName] = value;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
acc[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
return [2 /*return*/, event];
|
|
37
|
+
});
|
|
38
|
+
}); };
|
|
39
|
+
return {
|
|
40
|
+
name: name,
|
|
41
|
+
type: type,
|
|
42
|
+
setup: setup,
|
|
43
|
+
execute: execute,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.defaultPageViewEventEnrichment = defaultPageViewEventEnrichment;
|
|
47
|
+
//# sourceMappingURL=default-page-view-event-enrichment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-page-view-event-enrichment.js","sourceRoot":"","sources":["../../../src/plugins/default-page-view-event-enrichment.ts"],"names":[],"mappings":"AACA,iBA+CA;;;;AAhDA,4DAA4D;AAC5D,8DAAqF;AACrF,0CAA6E;AAU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richmentPlugin, PluginType } from '@amplitude/analytics-types';\nimport { DEFAULT_EVENT_PREFIX, DEFAULT_PAGE_VIEW_EVENT } from '../constants';\n\ninterface PageViewEventProperties extends Record<string, string | undefined> {\n page_domain: string;\n page_location: string;\n page_path: string;\n page_title: string;\n page_url: string;\n}\n\nconst eventPropertyMap: PageViewEventProperties = {\n page_domain: `${DEFAULT_EVENT_PREFIX} Page Domain`,\n page_location: `${DEFAULT_EVENT_PREFIX} Page Location`,\n page_path: `${DEFAULT_EVENT_PREFIX} Page Path`,\n page_title: `${DEFAULT_EVENT_PREFIX} Page Title`,\n page_url: `${DEFAULT_EVENT_PREFIX} Page URL`,\n};\n\nexport const defaultPageViewEventEnrichment = (): EnrichmentPlugin => {\n const name = '@amplitude/plugin-default-page-view-event-enrichment-browser';\n const type = PluginType.ENRICHMENT;\n const setup = async () => undefined;\n const execute = async (event: BaseEvent) => {\n if (event.event_type === DEFAULT_PAGE_VIEW_EVENT && event.event_properties) {\n event.event_properties = Object.entries(event.event_properties).reduce<{\n [key: string]: any;\n }>((acc, [key, value]) => {\n const transformedPropertyName = eventPropertyMap[key];\n if (transformedPropertyName) {\n acc[transformedPropertyName] = value;\n } else {\n acc[key] = value;\n }\n return acc;\n }, {});\n }\n return event;\n };\n\n return {\n name,\n type,\n setup,\n execute,\n };\n};\n"]}
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;AAAa,QAAA,OAAO,GAAG,cAAc,CAAC","sourcesContent":["export const VERSION = '2.0.0-beta.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;AAAa,QAAA,OAAO,GAAG,cAAc,CAAC","sourcesContent":["export const VERSION = '2.0.0-beta.5';\n"]}
|
|
@@ -4,7 +4,7 @@ export declare class AmplitudeBrowser extends AmplitudeCore implements BrowserCl
|
|
|
4
4
|
config: BrowserConfig;
|
|
5
5
|
previousSessionDeviceId: string | undefined;
|
|
6
6
|
previousSessionUserId: string | undefined;
|
|
7
|
-
init(apiKey?: string,
|
|
7
|
+
init(apiKey?: string, userIdOrOptions?: string | BrowserOptions, maybeOptions?: BrowserOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>;
|
|
8
8
|
protected _init(options: BrowserOptions & {
|
|
9
9
|
apiKey: string;
|
|
10
10
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuD,MAAM,2BAA2B,CAAC;AAa/G,OAAO,EACL,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,IAAI,SAAS,EACrB,OAAO,IAAI,QAAQ,EACnB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAWpC,qBAAa,gBAAiB,SAAQ,aAAc,YAAW,aAAa;IAG1E,MAAM,EAAE,aAAa,CAAC;IACtB,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1C,IAAI,CAAC,MAAM,SAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuD,MAAM,2BAA2B,CAAC;AAa/G,OAAO,EACL,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,IAAI,SAAS,EACrB,OAAO,IAAI,QAAQ,EACnB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAWpC,qBAAa,gBAAiB,SAAQ,aAAc,YAAW,aAAa;IAG1E,MAAM,EAAE,aAAa,CAAC;IACtB,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1C,IAAI,CAAC,MAAM,SAAK,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE,YAAY,CAAC,EAAE,cAAc;cAkB1E,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE;IAmElE,SAAS;IAIT,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAYpC,WAAW;IAIX,WAAW,CAAC,QAAQ,EAAE,MAAM;IAS5B,KAAK;IAKL,YAAY;IAIZ,YAAY,CAAC,SAAS,EAAE,MAAM;IA+B9B,YAAY,CAAC,SAAS,EAAE,aAAa;IAQrC,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,YAAY;IAezD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,YAAY;IAS/G,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;CAQvD"}
|
|
@@ -15,8 +15,24 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
15
15
|
function AmplitudeBrowser() {
|
|
16
16
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
17
17
|
}
|
|
18
|
-
AmplitudeBrowser.prototype.init = function (apiKey,
|
|
18
|
+
AmplitudeBrowser.prototype.init = function (apiKey, userIdOrOptions, maybeOptions) {
|
|
19
19
|
if (apiKey === void 0) { apiKey = ''; }
|
|
20
|
+
var userId;
|
|
21
|
+
var options;
|
|
22
|
+
if (arguments.length > 2) {
|
|
23
|
+
userId = userIdOrOptions;
|
|
24
|
+
options = maybeOptions;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (typeof userIdOrOptions === 'string') {
|
|
28
|
+
userId = userIdOrOptions;
|
|
29
|
+
options = undefined;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
userId = userIdOrOptions === null || userIdOrOptions === void 0 ? void 0 : userIdOrOptions.userId;
|
|
33
|
+
options = userIdOrOptions;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
20
36
|
return returnWrapper(this._init(__assign(__assign({}, options), { userId: userId, apiKey: apiKey })));
|
|
21
37
|
};
|
|
22
38
|
AmplitudeBrowser.prototype._init = function (options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAC/G,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,yBAAyB,EACzB,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,6BAA6B,EAC7B,gCAAgC,EAChC,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oCAAoC,CAAC;AAU5C,OAAO,EAAE,8BAA8B,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EA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B,EAAE,QAAmB,EAAE,YAA2B;QAC7G,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE;YAC7B,IAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;YACjB,QAAQ,GAAG,8BAA8B,CAAC,IAAI,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;SAClE;QACD,OAAO,iBAAM,aAAa,YAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3E,CAAC;IAED,kCAAO,GAAP,UAAQ,OAAiB,EAAE,YAA2B;QACpD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;YAC5B,IAAM,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;YAChB,OAAO,GAAG,8BAA8B,CAAC,IAAI,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;SAChE;QACD,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IACH,uBAAC;AAAD,CAAC,AA1LD,CAAsC,aAAa,GA0LlD","sourcesContent":["import { AmplitudeCore, Destination, Identify, returnWrapper, Revenue, UUID } from '@amplitude/analytics-core';\nimport {\n getAnalyticsConnector,\n getAttributionTrackingConfig,\n getPageViewTrackingConfig,\n IdentityEventSender,\n isAttributionTrackingEnabled,\n isSessionTrackingEnabled,\n isFileDownloadTrackingEnabled,\n isFormInteractionTrackingEnabled,\n setConnectorDeviceId,\n setConnectorUserId,\n} from '@amplitude/analytics-client-common';\nimport {\n BrowserClient,\n BrowserConfig,\n BrowserOptions,\n EventOptions,\n Identify as IIdentify,\n Revenue as IRevenue,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { useBrowserConfig, createTransport } from './config';\nimport { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser';\nimport { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';\nimport { sessionHandlerPlugin } from './plugins/session-handler';\nimport { formInteractionTracking } from './plugins/form-interaction-tracking';\nimport { fileDownloadTracking } from './plugins/file-download-tracking';\nimport { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_START_EVENT } from './constants';\n\nexport class AmplitudeBrowser extends AmplitudeCore implements BrowserClient {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n previousSessionDeviceId: string | undefined;\n previousSessionUserId: string | undefined;\n\n init(apiKey = '', userId?: string, options?: BrowserOptions) {\n return returnWrapper(this._init({ ...options, userId, apiKey }));\n }\n protected async _init(options: BrowserOptions & { apiKey: string }) {\n // Step 1: Block concurrent initialization\n if (this.initializing) {\n return;\n }\n this.initializing = true;\n\n // Step 2: Create browser config\n const browserOptions = await useBrowserConfig(options.apiKey, options, this);\n await super._init(browserOptions);\n\n // Step 3: Manage session\n if (\n !this.config.sessionId ||\n (this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)\n ) {\n // Either\n // 1) No previous session; or\n // 2) Previous session expired\n this.setSessionId(Date.now());\n }\n\n // Set up the analytics connector to integrate with the experiment SDK.\n // Send events from the experiment SDK and forward identifies to the\n // identity store.\n const connector = getAnalyticsConnector();\n connector.identityStore.setIdentity({\n userId: this.config.userId,\n deviceId: this.config.deviceId,\n });\n\n // Step 4: Install plugins\n // Do not track any events before this\n await this.add(new Destination()).promise;\n await this.add(new Context()).promise;\n await this.add(sessionHandlerPlugin()).promise;\n await this.add(new IdentityEventSender()).promise;\n\n if (isFileDownloadTrackingEnabled(this.config.defaultTracking)) {\n await this.add(fileDownloadTracking()).promise;\n }\n\n if (isFormInteractionTrackingEnabled(this.config.defaultTracking)) {\n await this.add(formInteractionTracking()).promise;\n }\n\n // Add web attribution plugin\n if (isAttributionTrackingEnabled(this.config.defaultTracking)) {\n const attributionTrackingOptions = getAttributionTrackingConfig(this.config);\n const webAttribution = webAttributionPlugin(attributionTrackingOptions);\n await this.add(webAttribution).promise;\n }\n\n // Add page view plugin\n await this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise;\n\n this.initializing = false;\n\n // Step 6: Run queued dispatch functions\n await this.runQueuedFunctions('dispatchQ');\n\n // Step 7: Add the event receiver after running remaining queued functions.\n connector.eventBridge.setEventReceiver((event) => {\n void this.track(event.eventType, event.eventProperties);\n });\n }\n\n getUserId() {\n return this.config?.userId;\n }\n\n setUserId(userId: string | undefined) {\n if (!this.config) {\n this.q.push(this.setUserId.bind(this, userId));\n return;\n }\n if (userId !== this.config.userId || userId === undefined) {\n this.config.userId = userId;\n this.setSessionId(Date.now());\n setConnectorUserId(userId);\n }\n }\n\n getDeviceId() {\n return this.config?.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n if (!this.config) {\n this.q.push(this.setDeviceId.bind(this, deviceId));\n return;\n }\n this.config.deviceId = deviceId;\n setConnectorDeviceId(deviceId);\n }\n\n reset() {\n this.setDeviceId(UUID());\n this.setUserId(undefined);\n }\n\n getSessionId() {\n return this.config?.sessionId;\n }\n\n setSessionId(sessionId: number) {\n if (!this.config) {\n this.q.push(this.setSessionId.bind(this, sessionId));\n return;\n }\n const previousSessionId = this.getSessionId();\n const previousLastEventTime = this.config.lastEventTime;\n\n this.config.sessionId = sessionId;\n this.config.lastEventTime = undefined;\n\n if (isSessionTrackingEnabled(this.config.defaultTracking)) {\n if (previousSessionId && previousLastEventTime) {\n const eventOptions: EventOptions = {\n session_id: previousSessionId,\n time: previousLastEventTime + 1,\n };\n eventOptions.device_id = this.previousSessionDeviceId;\n eventOptions.user_id = this.previousSessionUserId;\n this.track(DEFAULT_SESSION_END_EVENT, undefined, eventOptions);\n }\n\n this.track(DEFAULT_SESSION_START_EVENT, undefined, {\n session_id: sessionId,\n time: sessionId - 1,\n });\n this.previousSessionDeviceId = this.config.deviceId;\n this.previousSessionUserId = this.config.userId;\n }\n }\n\n setTransport(transport: TransportType) {\n if (!this.config) {\n this.q.push(this.setTransport.bind(this, transport));\n return;\n }\n this.config.transportProvider = createTransport(transport);\n }\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n if (eventOptions?.user_id) {\n this.setUserId(eventOptions.user_id);\n }\n if (eventOptions?.device_id) {\n this.setDeviceId(eventOptions.device_id);\n }\n return super.identify(identify, eventOptions);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.groupIdentify(groupType, groupName, identify, eventOptions);\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return super.revenue(revenue, eventOptions);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAC/G,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,yBAAyB,EACzB,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,6BAA6B,EAC7B,gCAAgC,EAChC,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oCAAoC,CAAC;AAU5C,OAAO,EAAE,8BAA8B,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,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E,EAAE,KAAK,CAAC,CAAC;SAChE;QACD,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IACH,uBAAC;AAAD,CAAC,AAzMD,CAAsC,aAAa,GAyMlD","sourcesContent":["import { AmplitudeCore, Destination, Identify, returnWrapper, Revenue, UUID } from '@amplitude/analytics-core';\nimport {\n getAnalyticsConnector,\n getAttributionTrackingConfig,\n getPageViewTrackingConfig,\n IdentityEventSender,\n isAttributionTrackingEnabled,\n isSessionTrackingEnabled,\n isFileDownloadTrackingEnabled,\n isFormInteractionTrackingEnabled,\n setConnectorDeviceId,\n setConnectorUserId,\n} from '@amplitude/analytics-client-common';\nimport {\n BrowserClient,\n BrowserConfig,\n BrowserOptions,\n EventOptions,\n Identify as IIdentify,\n Revenue as IRevenue,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { useBrowserConfig, createTransport } from './config';\nimport { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser';\nimport { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';\nimport { sessionHandlerPlugin } from './plugins/session-handler';\nimport { formInteractionTracking } from './plugins/form-interaction-tracking';\nimport { fileDownloadTracking } from './plugins/file-download-tracking';\nimport { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_START_EVENT } from './constants';\n\nexport class AmplitudeBrowser extends AmplitudeCore implements BrowserClient {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n previousSessionDeviceId: string | undefined;\n previousSessionUserId: string | undefined;\n\n init(apiKey = '', userIdOrOptions?: string | BrowserOptions, maybeOptions?: BrowserOptions) {\n let userId: string | undefined;\n let options: BrowserOptions | undefined;\n\n if (arguments.length > 2) {\n userId = userIdOrOptions as string | undefined;\n options = maybeOptions;\n } else {\n if (typeof userIdOrOptions === 'string') {\n userId = userIdOrOptions;\n options = undefined;\n } else {\n userId = userIdOrOptions?.userId;\n options = userIdOrOptions;\n }\n }\n return returnWrapper(this._init({ ...options, userId, apiKey }));\n }\n protected async _init(options: BrowserOptions & { apiKey: string }) {\n // Step 1: Block concurrent initialization\n if (this.initializing) {\n return;\n }\n this.initializing = true;\n\n // Step 2: Create browser config\n const browserOptions = await useBrowserConfig(options.apiKey, options, this);\n await super._init(browserOptions);\n\n // Step 3: Manage session\n if (\n !this.config.sessionId ||\n (this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)\n ) {\n // Either\n // 1) No previous session; or\n // 2) Previous session expired\n this.setSessionId(Date.now());\n }\n\n // Set up the analytics connector to integrate with the experiment SDK.\n // Send events from the experiment SDK and forward identifies to the\n // identity store.\n const connector = getAnalyticsConnector();\n connector.identityStore.setIdentity({\n userId: this.config.userId,\n deviceId: this.config.deviceId,\n });\n\n // Step 4: Install plugins\n // Do not track any events before this\n await this.add(new Destination()).promise;\n await this.add(new Context()).promise;\n await this.add(sessionHandlerPlugin()).promise;\n await this.add(new IdentityEventSender()).promise;\n\n if (isFileDownloadTrackingEnabled(this.config.defaultTracking)) {\n await this.add(fileDownloadTracking()).promise;\n }\n\n if (isFormInteractionTrackingEnabled(this.config.defaultTracking)) {\n await this.add(formInteractionTracking()).promise;\n }\n\n // Add web attribution plugin\n if (isAttributionTrackingEnabled(this.config.defaultTracking)) {\n const attributionTrackingOptions = getAttributionTrackingConfig(this.config);\n const webAttribution = webAttributionPlugin(attributionTrackingOptions);\n await this.add(webAttribution).promise;\n }\n\n // Add page view plugin\n await this.add(pageViewTrackingPlugin(getPageViewTrackingConfig(this.config))).promise;\n\n this.initializing = false;\n\n // Step 6: Run queued dispatch functions\n await this.runQueuedFunctions('dispatchQ');\n\n // Step 7: Add the event receiver after running remaining queued functions.\n connector.eventBridge.setEventReceiver((event) => {\n void this.track(event.eventType, event.eventProperties);\n });\n }\n\n getUserId() {\n return this.config?.userId;\n }\n\n setUserId(userId: string | undefined) {\n if (!this.config) {\n this.q.push(this.setUserId.bind(this, userId));\n return;\n }\n if (userId !== this.config.userId || userId === undefined) {\n this.config.userId = userId;\n this.setSessionId(Date.now());\n setConnectorUserId(userId);\n }\n }\n\n getDeviceId() {\n return this.config?.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n if (!this.config) {\n this.q.push(this.setDeviceId.bind(this, deviceId));\n return;\n }\n this.config.deviceId = deviceId;\n setConnectorDeviceId(deviceId);\n }\n\n reset() {\n this.setDeviceId(UUID());\n this.setUserId(undefined);\n }\n\n getSessionId() {\n return this.config?.sessionId;\n }\n\n setSessionId(sessionId: number) {\n if (!this.config) {\n this.q.push(this.setSessionId.bind(this, sessionId));\n return;\n }\n const previousSessionId = this.getSessionId();\n const previousLastEventTime = this.config.lastEventTime;\n\n this.config.sessionId = sessionId;\n this.config.lastEventTime = undefined;\n\n if (isSessionTrackingEnabled(this.config.defaultTracking)) {\n if (previousSessionId && previousLastEventTime) {\n const eventOptions: EventOptions = {\n session_id: previousSessionId,\n time: previousLastEventTime + 1,\n };\n eventOptions.device_id = this.previousSessionDeviceId;\n eventOptions.user_id = this.previousSessionUserId;\n this.track(DEFAULT_SESSION_END_EVENT, undefined, eventOptions);\n }\n\n this.track(DEFAULT_SESSION_START_EVENT, undefined, {\n session_id: sessionId,\n time: sessionId - 1,\n });\n this.previousSessionDeviceId = this.config.deviceId;\n this.previousSessionUserId = this.config.userId;\n }\n }\n\n setTransport(transport: TransportType) {\n if (!this.config) {\n this.q.push(this.setTransport.bind(this, transport));\n return;\n }\n this.config.transportProvider = createTransport(transport);\n }\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n if (eventOptions?.user_id) {\n this.setUserId(eventOptions.user_id);\n }\n if (eventOptions?.device_id) {\n this.setDeviceId(eventOptions.device_id);\n }\n return super.identify(identify, eventOptions);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.groupIdentify(groupType, groupName, identify, eventOptions);\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return super.revenue(revenue, eventOptions);\n }\n}\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { createInstance } from './browser-client-factory';
|
|
2
|
-
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<void>, flush: () => import("@amplitude/analytics-types").AmplitudeReturn<void>, getDeviceId: () => string | undefined, getSessionId: () => number | undefined, getUserId: () => string | undefined, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, identify: (identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, init:
|
|
2
|
+
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<void>, flush: () => import("@amplitude/analytics-types").AmplitudeReturn<void>, getDeviceId: () => string | undefined, getSessionId: () => number | undefined, getUserId: () => string | undefined, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, identify: (identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, init: {
|
|
3
|
+
(apiKey: string, options?: import("@amplitude/analytics-types").BrowserOptions | undefined): import("@amplitude/analytics-types").AmplitudeReturn<void>;
|
|
4
|
+
(apiKey: string, userId?: string | undefined, options?: import("@amplitude/analytics-types").BrowserOptions | undefined): import("@amplitude/analytics-types").AmplitudeReturn<void>;
|
|
5
|
+
}, logEvent: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, remove: (pluginName: string) => import("@amplitude/analytics-types").AmplitudeReturn<void>, reset: () => void, revenue: (revenue: import("@amplitude/analytics-types").Revenue, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, setDeviceId: (deviceId: string) => void, setGroup: (groupType: string, groupName: string | string[], eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>, setOptOut: (optOut: boolean) => void, setSessionId: (sessionId: number) => void, setTransport: (transport: import("@amplitude/analytics-types").TransportType) => void, setUserId: (userId: string | undefined) => void, track: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<import("@amplitude/analytics-types").Result>;
|
|
3
6
|
export { runQueuedFunctions } from './utils/snippet-helper';
|
|
4
7
|
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
5
8
|
export * as Types from '@amplitude/analytics-types';
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,eAAO,MACL,GAAG,uHACH,KAAK,oEACL,WAAW,4BACX,YAAY,4BACZ,SAAS,4BACT,aAAa,iSACb,QAAQ,gPACR,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,eAAO,MACL,GAAG,uHACH,KAAK,oEACL,WAAW,4BACX,YAAY,4BACZ,SAAS,4BACT,aAAa,iSACb,QAAQ,gPACR,IAAI;;;GACJ,QAAQ,+SACR,MAAM,sFACN,KAAK,cACL,OAAO,8OACP,WAAW,8BACX,QAAQ,wOACR,SAAS,6BACT,YAAY,+BACZ,YAAY,2EACZ,SAAS,wCACT,KAAK,6SACG,CAAC;AACX,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-page-view-event-enrichment.d.ts","sourceRoot":"","sources":["../../../src/plugins/default-page-view-event-enrichment.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,gBAAgB,EAAc,MAAM,4BAA4B,CAAC;AAmBrF,eAAO,MAAM,8BAA8B,QAAO,gBA2BjD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { __awaiter, __generator, __read } from "tslib";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
+
import { PluginType } from '@amplitude/analytics-types';
|
|
4
|
+
import { DEFAULT_EVENT_PREFIX, DEFAULT_PAGE_VIEW_EVENT } from '../constants';
|
|
5
|
+
var eventPropertyMap = {
|
|
6
|
+
page_domain: "".concat(DEFAULT_EVENT_PREFIX, " Page Domain"),
|
|
7
|
+
page_location: "".concat(DEFAULT_EVENT_PREFIX, " Page Location"),
|
|
8
|
+
page_path: "".concat(DEFAULT_EVENT_PREFIX, " Page Path"),
|
|
9
|
+
page_title: "".concat(DEFAULT_EVENT_PREFIX, " Page Title"),
|
|
10
|
+
page_url: "".concat(DEFAULT_EVENT_PREFIX, " Page URL"),
|
|
11
|
+
};
|
|
12
|
+
export var defaultPageViewEventEnrichment = function () {
|
|
13
|
+
var name = '@amplitude/plugin-default-page-view-event-enrichment-browser';
|
|
14
|
+
var type = PluginType.ENRICHMENT;
|
|
15
|
+
var setup = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
16
|
+
return [2 /*return*/, undefined];
|
|
17
|
+
}); }); };
|
|
18
|
+
var execute = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
19
|
+
return __generator(this, function (_a) {
|
|
20
|
+
if (event.event_type === DEFAULT_PAGE_VIEW_EVENT && event.event_properties) {
|
|
21
|
+
event.event_properties = Object.entries(event.event_properties).reduce(function (acc, _a) {
|
|
22
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
23
|
+
var transformedPropertyName = eventPropertyMap[key];
|
|
24
|
+
if (transformedPropertyName) {
|
|
25
|
+
acc[transformedPropertyName] = value;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
acc[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
return [2 /*return*/, event];
|
|
34
|
+
});
|
|
35
|
+
}); };
|
|
36
|
+
return {
|
|
37
|
+
name: name,
|
|
38
|
+
type: type,
|
|
39
|
+
setup: setup,
|
|
40
|
+
execute: execute,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=default-page-view-event-enrichment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-page-view-event-enrich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d,CAAC;IAEF,OAAO;QACL,IAAI,MAAA;QACJ,IAAI,MAAA;QACJ,KAAK,OAAA;QACL,OAAO,SAAA;KACR,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { BaseEvent, EnrichmentPlugin, PluginType } from '@amplitude/analytics-types';\nimport { DEFAULT_EVENT_PREFIX, DEFAULT_PAGE_VIEW_EVENT } from '../constants';\n\ninterface PageViewEventProperties extends Record<string, string | undefined> {\n page_domain: string;\n page_location: string;\n page_path: string;\n page_title: string;\n page_url: string;\n}\n\nconst eventPropertyMap: PageViewEventProperties = {\n page_domain: `${DEFAULT_EVENT_PREFIX} Page Domain`,\n page_location: `${DEFAULT_EVENT_PREFIX} Page Location`,\n page_path: `${DEFAULT_EVENT_PREFIX} Page Path`,\n page_title: `${DEFAULT_EVENT_PREFIX} Page Title`,\n page_url: `${DEFAULT_EVENT_PREFIX} Page URL`,\n};\n\nexport const defaultPageViewEventEnrichment = (): EnrichmentPlugin => {\n const name = '@amplitude/plugin-default-page-view-event-enrichment-browser';\n const type = PluginType.ENRICHMENT;\n const setup = async () => undefined;\n const execute = async (event: BaseEvent) => {\n if (event.event_type === DEFAULT_PAGE_VIEW_EVENT && event.event_properties) {\n event.event_properties = Object.entries(event.event_properties).reduce<{\n [key: string]: any;\n }>((acc, [key, value]) => {\n const transformedPropertyName = eventPropertyMap[key];\n if (transformedPropertyName) {\n acc[transformedPropertyName] = value;\n } else {\n acc[key] = value;\n }\n return acc;\n }, {});\n }\n return event;\n };\n\n return {\n name,\n type,\n setup,\n execute,\n };\n};\n"]}
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var VERSION = '2.0.0-beta.
|
|
1
|
+
export var VERSION = '2.0.0-beta.5';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/lib/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,cAAc,CAAC","sourcesContent":["export const VERSION = '2.0.0-beta.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,cAAc,CAAC","sourcesContent":["export const VERSION = '2.0.0-beta.5';\n"]}
|