@amplitude/analytics-browser 0.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 +1 -0
- package/lib/cjs/attribution.d.ts +11 -0
- package/lib/cjs/attribution.d.ts.map +1 -0
- package/lib/cjs/attribution.js +76 -0
- package/lib/cjs/attribution.js.map +1 -0
- package/lib/cjs/browser-client.d.ts +183 -0
- package/lib/cjs/browser-client.d.ts.map +1 -0
- package/lib/cjs/browser-client.js +298 -0
- package/lib/cjs/browser-client.js.map +1 -0
- package/lib/cjs/config.d.ts +83 -0
- package/lib/cjs/config.d.ts.map +1 -0
- package/lib/cjs/config.js +138 -0
- package/lib/cjs/config.js.map +1 -0
- package/lib/cjs/constants.d.ts +13 -0
- package/lib/cjs/constants.d.ts.map +1 -0
- package/lib/cjs/constants.js +15 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +28 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/plugins/context.d.ts +14 -0
- package/lib/cjs/plugins/context.d.ts.map +1 -0
- package/lib/cjs/plugins/context.js +46 -0
- package/lib/cjs/plugins/context.js.map +1 -0
- package/lib/cjs/session-manager.d.ts +6 -0
- package/lib/cjs/session-manager.d.ts.map +1 -0
- package/lib/cjs/session-manager.js +42 -0
- package/lib/cjs/session-manager.js.map +1 -0
- package/lib/cjs/snippet-index.d.ts +2 -0
- package/lib/cjs/snippet-index.d.ts.map +1 -0
- package/lib/cjs/snippet-index.js +11 -0
- package/lib/cjs/snippet-index.js.map +1 -0
- package/lib/cjs/storage/cookie.d.ts +12 -0
- package/lib/cjs/storage/cookie.d.ts.map +1 -0
- package/lib/cjs/storage/cookie.js +86 -0
- package/lib/cjs/storage/cookie.js.map +1 -0
- package/lib/cjs/storage/local-storage.d.ts +9 -0
- package/lib/cjs/storage/local-storage.d.ts.map +1 -0
- package/lib/cjs/storage/local-storage.js +68 -0
- package/lib/cjs/storage/local-storage.js.map +1 -0
- package/lib/cjs/storage/memory.d.ts +10 -0
- package/lib/cjs/storage/memory.d.ts.map +1 -0
- package/lib/cjs/storage/memory.js +25 -0
- package/lib/cjs/storage/memory.js.map +1 -0
- package/lib/cjs/storage/utm-cookie.d.ts +6 -0
- package/lib/cjs/storage/utm-cookie.d.ts.map +1 -0
- package/lib/cjs/storage/utm-cookie.js +36 -0
- package/lib/cjs/storage/utm-cookie.js.map +1 -0
- package/lib/cjs/transports/fetch.d.ts +5 -0
- package/lib/cjs/transports/fetch.d.ts.map +1 -0
- package/lib/cjs/transports/fetch.js +42 -0
- package/lib/cjs/transports/fetch.js.map +1 -0
- package/lib/cjs/transports/send-beacon.d.ts +5 -0
- package/lib/cjs/transports/send-beacon.d.ts.map +1 -0
- package/lib/cjs/transports/send-beacon.js +41 -0
- package/lib/cjs/transports/send-beacon.js.map +1 -0
- package/lib/cjs/transports/xhr.d.ts +6 -0
- package/lib/cjs/transports/xhr.d.ts.map +1 -0
- package/lib/cjs/transports/xhr.js +46 -0
- package/lib/cjs/transports/xhr.js.map +1 -0
- package/lib/cjs/utils/language.d.ts +2 -0
- package/lib/cjs/utils/language.d.ts.map +1 -0
- package/lib/cjs/utils/language.js +12 -0
- package/lib/cjs/utils/language.js.map +1 -0
- package/lib/cjs/utils/query-params.d.ts +2 -0
- package/lib/cjs/utils/query-params.d.ts.map +1 -0
- package/lib/cjs/utils/query-params.js +21 -0
- package/lib/cjs/utils/query-params.js.map +1 -0
- package/lib/cjs/utils/snippet-helper.d.ts +15 -0
- package/lib/cjs/utils/snippet-helper.d.ts.map +1 -0
- package/lib/cjs/utils/snippet-helper.js +34 -0
- package/lib/cjs/utils/snippet-helper.js.map +1 -0
- package/lib/cjs/utils/uuid.d.ts +10 -0
- package/lib/cjs/utils/uuid.d.ts.map +1 -0
- package/lib/cjs/utils/uuid.js +31 -0
- package/lib/cjs/utils/uuid.js.map +1 -0
- package/lib/cjs/version.d.ts +13 -0
- package/lib/cjs/version.d.ts.map +1 -0
- package/lib/cjs/version.js +15 -0
- package/lib/cjs/version.js.map +1 -0
- package/lib/esm/attribution.d.ts +11 -0
- package/lib/esm/attribution.d.ts.map +1 -0
- package/lib/esm/attribution.js +69 -0
- package/lib/esm/attribution.js.map +1 -0
- package/lib/esm/browser-client.d.ts +183 -0
- package/lib/esm/browser-client.d.ts.map +1 -0
- package/lib/esm/browser-client.js +279 -0
- package/lib/esm/browser-client.js.map +1 -0
- package/lib/esm/config.d.ts +83 -0
- package/lib/esm/config.d.ts.map +1 -0
- package/lib/esm/config.js +129 -0
- package/lib/esm/config.js.map +1 -0
- package/lib/esm/constants.d.ts +13 -0
- package/lib/esm/constants.d.ts.map +1 -0
- package/lib/esm/constants.js +13 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +6 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/plugins/context.d.ts +14 -0
- package/lib/esm/plugins/context.d.ts.map +1 -0
- package/lib/esm/plugins/context.js +44 -0
- package/lib/esm/plugins/context.js.map +1 -0
- package/lib/esm/session-manager.d.ts +6 -0
- package/lib/esm/session-manager.d.ts.map +1 -0
- package/lib/esm/session-manager.js +36 -0
- package/lib/esm/session-manager.js.map +1 -0
- package/lib/esm/snippet-index.d.ts +2 -0
- package/lib/esm/snippet-index.d.ts.map +1 -0
- package/lib/esm/snippet-index.js +9 -0
- package/lib/esm/snippet-index.js.map +1 -0
- package/lib/esm/storage/cookie.d.ts +12 -0
- package/lib/esm/storage/cookie.d.ts.map +1 -0
- package/lib/esm/storage/cookie.js +84 -0
- package/lib/esm/storage/cookie.js.map +1 -0
- package/lib/esm/storage/local-storage.d.ts +9 -0
- package/lib/esm/storage/local-storage.d.ts.map +1 -0
- package/lib/esm/storage/local-storage.js +66 -0
- package/lib/esm/storage/local-storage.js.map +1 -0
- package/lib/esm/storage/memory.d.ts +10 -0
- package/lib/esm/storage/memory.d.ts.map +1 -0
- package/lib/esm/storage/memory.js +23 -0
- package/lib/esm/storage/memory.js.map +1 -0
- package/lib/esm/storage/utm-cookie.d.ts +6 -0
- package/lib/esm/storage/utm-cookie.d.ts.map +1 -0
- package/lib/esm/storage/utm-cookie.js +34 -0
- package/lib/esm/storage/utm-cookie.js.map +1 -0
- package/lib/esm/transports/fetch.d.ts +5 -0
- package/lib/esm/transports/fetch.d.ts.map +1 -0
- package/lib/esm/transports/fetch.js +40 -0
- package/lib/esm/transports/fetch.js.map +1 -0
- package/lib/esm/transports/send-beacon.d.ts +5 -0
- package/lib/esm/transports/send-beacon.d.ts.map +1 -0
- package/lib/esm/transports/send-beacon.js +39 -0
- package/lib/esm/transports/send-beacon.js.map +1 -0
- package/lib/esm/transports/xhr.d.ts +6 -0
- package/lib/esm/transports/xhr.d.ts.map +1 -0
- package/lib/esm/transports/xhr.js +44 -0
- package/lib/esm/transports/xhr.js.map +1 -0
- package/lib/esm/utils/language.d.ts +2 -0
- package/lib/esm/utils/language.d.ts.map +1 -0
- package/lib/esm/utils/language.js +9 -0
- package/lib/esm/utils/language.js.map +1 -0
- package/lib/esm/utils/query-params.d.ts +2 -0
- package/lib/esm/utils/query-params.d.ts.map +1 -0
- package/lib/esm/utils/query-params.js +18 -0
- package/lib/esm/utils/query-params.js.map +1 -0
- package/lib/esm/utils/snippet-helper.d.ts +15 -0
- package/lib/esm/utils/snippet-helper.d.ts.map +1 -0
- package/lib/esm/utils/snippet-helper.js +29 -0
- package/lib/esm/utils/snippet-helper.js.map +1 -0
- package/lib/esm/utils/uuid.d.ts +10 -0
- package/lib/esm/utils/uuid.d.ts.map +1 -0
- package/lib/esm/utils/uuid.js +28 -0
- package/lib/esm/utils/uuid.js.map +1 -0
- package/lib/esm/version.d.ts +2 -0
- package/lib/esm/version.d.ts.map +1 -0
- package/lib/esm/version.js +2 -0
- package/lib/esm/version.js.map +1 -0
- package/lib/scripts/amplitude-min.js +15 -0
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.umd.js +15 -0
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @amplitude/analytics-browser
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BrowserConfig, UTMData } from '@amplitude/analytics-types';
|
|
2
|
+
export declare const trackAttributions: (config: BrowserConfig) => void;
|
|
3
|
+
export declare const getUtmParam: () => UTMData;
|
|
4
|
+
export declare const getReferrer: () => Record<string, string | undefined>;
|
|
5
|
+
export declare const getGclid: () => {
|
|
6
|
+
gclid?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const getFbclid: () => {
|
|
9
|
+
fbclid?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=attribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../../src/attribution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAkBpE,eAAO,MAAM,iBAAiB,WAAY,aAAa,SAoBtD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,OAkB9B,CAAC;AAEF,eAAO,MAAM,WAAW,0CAYvB,CAAC;AAEF,eAAO,MAAM,QAAQ;;CAKpB,CAAC;AAEF,eAAO,MAAM,SAAS;;CAKrB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.getFbclid = exports.getGclid = exports.getReferrer = exports.getUtmParam = exports.trackAttributions = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
|
+
var constants_1 = require("./constants");
|
|
6
|
+
var utm_cookie_1 = require("./storage/utm-cookie");
|
|
7
|
+
var query_params_1 = require("./utils/query-params");
|
|
8
|
+
var trackAttributions = function (config) {
|
|
9
|
+
var attribution = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (config.includeUtm && (0, exports.getUtmParam)())), (config.includeReferrer && (0, exports.getReferrer)())), (config.includeGclid && (0, exports.getGclid)())), (config.includeFbclid && (0, exports.getFbclid)()));
|
|
10
|
+
if (Object.keys(attribution).length === 0) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
var id = new analytics_core_1.Identify();
|
|
14
|
+
Object.entries(attribution).forEach(function (_a) {
|
|
15
|
+
var _b = (0, tslib_1.__read)(_a, 2), key = _b[0], value = _b[1];
|
|
16
|
+
if (value) {
|
|
17
|
+
id.setOnce("initial_".concat(key), value);
|
|
18
|
+
id.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
void (0, analytics_core_1.identify)(undefined, undefined, id);
|
|
22
|
+
};
|
|
23
|
+
exports.trackAttributions = trackAttributions;
|
|
24
|
+
var getUtmParam = function () {
|
|
25
|
+
var params = (0, query_params_1.getQueryParams)();
|
|
26
|
+
var utmStorage = new utm_cookie_1.UTMCookie();
|
|
27
|
+
var cookies = (utmStorage.isEnabled() && utmStorage.get('__utmz')) || {};
|
|
28
|
+
var utmSource = params[constants_1.UTM_SOURCE] || cookies[constants_1.UTMZ_SOURCE];
|
|
29
|
+
var utmMedium = params[constants_1.UTM_MEDIUM] || cookies[constants_1.UTMZ_MEDIUM];
|
|
30
|
+
var utmCampaign = params[constants_1.UTM_CAMPAIGN] || cookies[constants_1.UTMZ_CAMPAIGN];
|
|
31
|
+
var utmTerm = params[constants_1.UTM_TERM] || cookies[constants_1.UTMZ_TERM];
|
|
32
|
+
var utmContent = params[constants_1.UTM_CONTENT] || cookies[constants_1.UTMZ_CONTENT];
|
|
33
|
+
var data = {};
|
|
34
|
+
if (utmSource)
|
|
35
|
+
data.utm_source = utmSource;
|
|
36
|
+
if (utmMedium)
|
|
37
|
+
data.utm_medium = utmMedium;
|
|
38
|
+
if (utmCampaign)
|
|
39
|
+
data.utm_campaign = utmCampaign;
|
|
40
|
+
if (utmTerm)
|
|
41
|
+
data.utm_term = utmTerm;
|
|
42
|
+
if (utmContent)
|
|
43
|
+
data.utm_content = utmContent;
|
|
44
|
+
return data;
|
|
45
|
+
};
|
|
46
|
+
exports.getUtmParam = getUtmParam;
|
|
47
|
+
var getReferrer = function () {
|
|
48
|
+
var _a;
|
|
49
|
+
var data = {};
|
|
50
|
+
try {
|
|
51
|
+
var referrer = document.referrer || undefined;
|
|
52
|
+
var referringDomain = (_a = referrer === null || referrer === void 0 ? void 0 : referrer.split('/')[2]) !== null && _a !== void 0 ? _a : undefined;
|
|
53
|
+
if (referrer !== undefined)
|
|
54
|
+
data.referrer = referrer;
|
|
55
|
+
if (referringDomain !== undefined)
|
|
56
|
+
data.referring_domain = referringDomain;
|
|
57
|
+
}
|
|
58
|
+
catch (_b) {
|
|
59
|
+
//
|
|
60
|
+
}
|
|
61
|
+
return data;
|
|
62
|
+
};
|
|
63
|
+
exports.getReferrer = getReferrer;
|
|
64
|
+
var getGclid = function () {
|
|
65
|
+
var _a;
|
|
66
|
+
var params = (0, query_params_1.getQueryParams)();
|
|
67
|
+
return (0, tslib_1.__assign)({}, (params[constants_1.GCLID] && (_a = {}, _a[constants_1.GCLID] = params[constants_1.GCLID], _a)));
|
|
68
|
+
};
|
|
69
|
+
exports.getGclid = getGclid;
|
|
70
|
+
var getFbclid = function () {
|
|
71
|
+
var _a;
|
|
72
|
+
var params = (0, query_params_1.getQueryParams)();
|
|
73
|
+
return (0, tslib_1.__assign)({}, (params[constants_1.FBCLID] && (_a = {}, _a[constants_1.FBCLID] = params[constants_1.FBCLID], _a)));
|
|
74
|
+
};
|
|
75
|
+
exports.getFbclid = getFbclid;
|
|
76
|
+
//# sourceMappingURL=attribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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D,IAAI,eAAe,KAAK,SAAS;YAAE,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;KAC5E;IAAC,WAAM;QACN,EAAE;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAZW,QAAA,WAAW,eAYtB;AAEK,IAAM,QAAQ,GAAG;;IACtB,IAAM,MAAM,GAAG,IAAA,6BAAc,GAAE,CAAC;IAChC,iCACK,CAAC,MAAM,CAAC,iBAAK,CAAC,cAAM,GAAC,iBAAK,IAAG,MAAM,CAAC,iBAAK,CAAC,KAAE,CAAC,EAChD;AACJ,CAAC,CAAC;AALW,QAAA,QAAQ,YAKnB;AAEK,IAAM,SAAS,GAAG;;IACvB,IAAM,MAAM,GAAG,IAAA,6BAAc,GAAE,CAAC;IAChC,iCACK,CAAC,MAAM,CAAC,kBAAM,CAAC,cAAM,GAAC,kBAAM,IAAG,MAAM,CAAC,kBAAM,CAAC,KAAE,CAAC,EACnD;AACJ,CAAC,CAAC;AALW,QAAA,SAAS,aAKpB","sourcesContent":["import { Identify, identify } from '@amplitude/analytics-core';\nimport { BrowserConfig, UTMData } from '@amplitude/analytics-types';\nimport {\n UTM_CAMPAIGN,\n UTM_CONTENT,\n UTM_MEDIUM,\n UTM_SOURCE,\n UTM_TERM,\n UTMZ_SOURCE,\n UTMZ_MEDIUM,\n UTMZ_CAMPAIGN,\n UTMZ_TERM,\n UTMZ_CONTENT,\n GCLID,\n FBCLID,\n} from './constants';\nimport { UTMCookie } from './storage/utm-cookie';\nimport { getQueryParams } from './utils/query-params';\n\nexport const trackAttributions = (config: BrowserConfig) => {\n const attribution = {\n ...(config.includeUtm && getUtmParam()),\n ...(config.includeReferrer && getReferrer()),\n ...(config.includeGclid && getGclid()),\n ...(config.includeFbclid && getFbclid()),\n };\n\n if (Object.keys(attribution).length === 0) {\n return;\n }\n\n const id = new Identify();\n Object.entries(attribution).forEach(([key, value]: [string, string]) => {\n if (value) {\n id.setOnce(`initial_${key}`, value);\n id.set(key, value);\n }\n });\n void identify(undefined, undefined, id);\n};\n\nexport const getUtmParam = (): UTMData => {\n const params = getQueryParams();\n const utmStorage = new UTMCookie();\n const cookies = (utmStorage.isEnabled() && utmStorage.get('__utmz')) || {};\n\n const utmSource = params[UTM_SOURCE] || cookies[UTMZ_SOURCE];\n const utmMedium = params[UTM_MEDIUM] || cookies[UTMZ_MEDIUM];\n const utmCampaign = params[UTM_CAMPAIGN] || cookies[UTMZ_CAMPAIGN];\n const utmTerm = params[UTM_TERM] || cookies[UTMZ_TERM];\n const utmContent = params[UTM_CONTENT] || cookies[UTMZ_CONTENT];\n\n const data: UTMData = {};\n if (utmSource) data.utm_source = utmSource;\n if (utmMedium) data.utm_medium = utmMedium;\n if (utmCampaign) data.utm_campaign = utmCampaign;\n if (utmTerm) data.utm_term = utmTerm;\n if (utmContent) data.utm_content = utmContent;\n return data;\n};\n\nexport const getReferrer = () => {\n const data: Record<string, string | undefined> = {};\n try {\n const referrer = document.referrer || undefined;\n const referringDomain = referrer?.split('/')[2] ?? undefined;\n\n if (referrer !== undefined) data.referrer = referrer;\n if (referringDomain !== undefined) data.referring_domain = referringDomain;\n } catch {\n //\n }\n return data;\n};\n\nexport const getGclid = () => {\n const params = getQueryParams();\n return {\n ...(params[GCLID] && { [GCLID]: params[GCLID] }),\n };\n};\n\nexport const getFbclid = () => {\n const params = getQueryParams();\n return {\n ...(params[FBCLID] && { [FBCLID]: params[FBCLID] }),\n };\n};\n"]}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Identify, Revenue } from '@amplitude/analytics-core';
|
|
2
|
+
import { AmplitudeReturn, BrowserOptions, EventOptions, Plugin, Result, TransportType } from '@amplitude/analytics-types';
|
|
3
|
+
/**
|
|
4
|
+
* Initializes the Amplitude SDK with your apiKey, userId and optional configurations.
|
|
5
|
+
* This method must be called before any other operations.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const init: (apiKey: string, userId?: string | undefined, options?: BrowserOptions | undefined) => AmplitudeReturn<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Adds a new plugin.
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const plugin = {...};
|
|
17
|
+
* amplitude.add(plugin);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const add: (plugin: Plugin) => AmplitudeReturn<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Removes a plugin.
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* amplitude.remove('myPlugin');
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const remove: (pluginName: string) => AmplitudeReturn<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns current user ID.
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const userId = getUserId();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const getUserId: () => string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Sets a new user ID.
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* setUserId('userId');
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const setUserId: (userId: string) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Returns current device ID.
|
|
47
|
+
*
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const deviceId = getDeviceId();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const getDeviceId: () => string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Sets a new device ID.
|
|
55
|
+
* When setting a custom device ID, make sure the value is sufficiently unique.
|
|
56
|
+
* A uuid is recommended.
|
|
57
|
+
*
|
|
58
|
+
* ```typescript
|
|
59
|
+
* setDeviceId('deviceId');
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const setDeviceId: (deviceId: string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Returns current session ID.
|
|
65
|
+
*
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const sessionId = getSessionId();
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const getSessionId: () => number | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Sets a new session ID.
|
|
73
|
+
* When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
|
|
74
|
+
*
|
|
75
|
+
* ```typescript
|
|
76
|
+
* setSessionId(Date.now());
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare const setSessionId: (sessionId: number) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
82
|
+
*
|
|
83
|
+
*```typescript
|
|
84
|
+
* // Stops tracking
|
|
85
|
+
* setOptOut(true);
|
|
86
|
+
*
|
|
87
|
+
* // Starts/resumes tracking
|
|
88
|
+
* setOptOut(false);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const setOptOut: (optOut: boolean) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Sets the network transport type for events.
|
|
94
|
+
*
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Use Fetch API
|
|
97
|
+
* setTransport('fetch');
|
|
98
|
+
*
|
|
99
|
+
* // Use XMLHttpRequest API
|
|
100
|
+
* setTransport('xhr');
|
|
101
|
+
*
|
|
102
|
+
* // Use navigator.sendBeacon API
|
|
103
|
+
* setTransport('beacon');
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare const setTransport: (transport: TransportType) => void;
|
|
107
|
+
/**
|
|
108
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
109
|
+
*
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // event tracking with event type only
|
|
112
|
+
* track('Page Load');
|
|
113
|
+
*
|
|
114
|
+
* // event tracking with event type and additional event properties
|
|
115
|
+
* track('Page Load', { loadTime: 1000 });
|
|
116
|
+
*
|
|
117
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
118
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
119
|
+
*
|
|
120
|
+
* // alternatively, this tracking method is awaitable
|
|
121
|
+
* const result = await track('Page Load').promise;
|
|
122
|
+
* console.log(result.event); // {...}
|
|
123
|
+
* console.log(result.code); // 200
|
|
124
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare const track: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => AmplitudeReturn<Result>;
|
|
128
|
+
/**
|
|
129
|
+
* Alis for track()
|
|
130
|
+
*/
|
|
131
|
+
export declare const logEvent: (eventType: string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => AmplitudeReturn<Result>;
|
|
132
|
+
/**
|
|
133
|
+
* Sends an identify event containing user property operations
|
|
134
|
+
*
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const id = new Identify();
|
|
137
|
+
* id.set('colors', ['rose', 'gold']);
|
|
138
|
+
* identify(id);
|
|
139
|
+
*
|
|
140
|
+
* // alternatively, this tracking method is awaitable
|
|
141
|
+
* const result = await identify(id).promise;
|
|
142
|
+
* console.log(result.event); // {...}
|
|
143
|
+
* console.log(result.code); // 200
|
|
144
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare const identify: (identify: Identify, eventOptions?: EventOptions | undefined) => AmplitudeReturn<Result>;
|
|
148
|
+
/**
|
|
149
|
+
* Sends a group identify event containing group property operations.
|
|
150
|
+
*
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const id = new Identify();
|
|
153
|
+
* id.set('skills', ['js', 'ts']);
|
|
154
|
+
* const groupType = 'org';
|
|
155
|
+
* const groupName = 'engineering';
|
|
156
|
+
* groupIdentify(groupType, groupName, id);
|
|
157
|
+
*
|
|
158
|
+
* // alternatively, this tracking method is awaitable
|
|
159
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
160
|
+
* console.log(result.event); // {...}
|
|
161
|
+
* console.log(result.code); // 200
|
|
162
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare const groupIdentify: (groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions | undefined) => AmplitudeReturn<Result>;
|
|
166
|
+
export declare const setGroup: (groupType: string, groupName: string | string[]) => AmplitudeReturn<Result>;
|
|
167
|
+
/**
|
|
168
|
+
* Sends a revenue event containing revenue property operations.
|
|
169
|
+
*
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const rev = new Revenue();
|
|
172
|
+
* rev.setRevenue(100);
|
|
173
|
+
* revenue(rev);
|
|
174
|
+
*
|
|
175
|
+
* // alternatively, this tracking method is awaitable
|
|
176
|
+
* const result = await revenue(rev).promise;
|
|
177
|
+
* console.log(result.event); // {...}
|
|
178
|
+
* console.log(result.code); // 200
|
|
179
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare const revenue: (revenue: Revenue, eventOptions?: EventOptions | undefined) => AmplitudeReturn<Result>;
|
|
183
|
+
//# sourceMappingURL=browser-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,QAAQ,EACR,OAAO,EAIR,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,eAAe,EAEf,cAAc,EACd,YAAY,EACZ,MAAM,EACN,MAAM,EACN,aAAa,EACd,MAAM,4BAA4B,CAAC;AAOpC;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,WAAY,MAAM,wEAA8C,gBAAgB,IAAI,CAYpG,CAAC;AAEF;;;;;;;G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AACH,eAAO,MAAM,OAAO,YAAa,OAAO,8CAAgC,gBAAgB,MAAM,CAS7F,CAAC"}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
var _this = this;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.revenue = exports.setGroup = exports.groupIdentify = exports.identify = exports.logEvent = exports.track = exports.setTransport = exports.setOptOut = exports.setSessionId = exports.getSessionId = exports.setDeviceId = exports.getDeviceId = exports.setUserId = exports.getUserId = exports.remove = exports.add = exports.init = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
6
|
+
var snippet_helper_1 = require("./utils/snippet-helper");
|
|
7
|
+
var context_1 = require("./plugins/context");
|
|
8
|
+
var config_1 = require("./config");
|
|
9
|
+
var attribution_1 = require("./attribution");
|
|
10
|
+
var session_manager_1 = require("./session-manager");
|
|
11
|
+
/**
|
|
12
|
+
* Initializes the Amplitude SDK with your apiKey, userId and optional configurations.
|
|
13
|
+
* This method must be called before any other operations.
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
var init = function (apiKey, userId, options) {
|
|
20
|
+
return {
|
|
21
|
+
promise: (function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
22
|
+
var browserOptions, config;
|
|
23
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
24
|
+
switch (_a.label) {
|
|
25
|
+
case 0:
|
|
26
|
+
browserOptions = (0, config_1.createConfig)(apiKey, userId, options);
|
|
27
|
+
config = (0, analytics_core_1.init)(browserOptions);
|
|
28
|
+
(0, session_manager_1.updateCookies)(config);
|
|
29
|
+
return [4 /*yield*/, (0, analytics_core_1.add)(new context_1.Context())];
|
|
30
|
+
case 1:
|
|
31
|
+
_a.sent();
|
|
32
|
+
return [4 /*yield*/, (0, analytics_core_1.add)(new analytics_core_1.Destination())];
|
|
33
|
+
case 2:
|
|
34
|
+
_a.sent();
|
|
35
|
+
(0, attribution_1.trackAttributions)(config);
|
|
36
|
+
return [2 /*return*/];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}); })(),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.init = init;
|
|
43
|
+
/**
|
|
44
|
+
* Adds a new plugin.
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const plugin = {...};
|
|
48
|
+
* amplitude.add(plugin);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
var add = function (plugin) {
|
|
52
|
+
return {
|
|
53
|
+
promise: (0, analytics_core_1.add)(plugin),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.add = add;
|
|
57
|
+
/**
|
|
58
|
+
* Removes a plugin.
|
|
59
|
+
*
|
|
60
|
+
* ```typescript
|
|
61
|
+
* amplitude.remove('myPlugin');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
var remove = function (pluginName) {
|
|
65
|
+
return {
|
|
66
|
+
promise: (0, analytics_core_1.remove)(pluginName),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.remove = remove;
|
|
70
|
+
/**
|
|
71
|
+
* Returns current user ID.
|
|
72
|
+
*
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const userId = getUserId();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
var getUserId = function () {
|
|
78
|
+
return (0, config_1.getConfig)().userId;
|
|
79
|
+
};
|
|
80
|
+
exports.getUserId = getUserId;
|
|
81
|
+
/**
|
|
82
|
+
* Sets a new user ID.
|
|
83
|
+
*
|
|
84
|
+
* ```typescript
|
|
85
|
+
* setUserId('userId');
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
var setUserId = function (userId) {
|
|
89
|
+
var config = (0, config_1.getConfig)();
|
|
90
|
+
config.userId = userId;
|
|
91
|
+
(0, session_manager_1.updateCookies)(config);
|
|
92
|
+
};
|
|
93
|
+
exports.setUserId = setUserId;
|
|
94
|
+
/**
|
|
95
|
+
* Returns current device ID.
|
|
96
|
+
*
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const deviceId = getDeviceId();
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
var getDeviceId = function () {
|
|
102
|
+
return (0, config_1.getConfig)().deviceId;
|
|
103
|
+
};
|
|
104
|
+
exports.getDeviceId = getDeviceId;
|
|
105
|
+
/**
|
|
106
|
+
* Sets a new device ID.
|
|
107
|
+
* When setting a custom device ID, make sure the value is sufficiently unique.
|
|
108
|
+
* A uuid is recommended.
|
|
109
|
+
*
|
|
110
|
+
* ```typescript
|
|
111
|
+
* setDeviceId('deviceId');
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
var setDeviceId = function (deviceId) {
|
|
115
|
+
var config = (0, config_1.getConfig)();
|
|
116
|
+
config.deviceId = deviceId;
|
|
117
|
+
(0, session_manager_1.updateCookies)(config);
|
|
118
|
+
};
|
|
119
|
+
exports.setDeviceId = setDeviceId;
|
|
120
|
+
/**
|
|
121
|
+
* Returns current session ID.
|
|
122
|
+
*
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const sessionId = getSessionId();
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
var getSessionId = function () {
|
|
128
|
+
return (0, config_1.getConfig)().sessionId;
|
|
129
|
+
};
|
|
130
|
+
exports.getSessionId = getSessionId;
|
|
131
|
+
/**
|
|
132
|
+
* Sets a new session ID.
|
|
133
|
+
* When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
|
|
134
|
+
*
|
|
135
|
+
* ```typescript
|
|
136
|
+
* setSessionId(Date.now());
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
var setSessionId = function (sessionId) {
|
|
140
|
+
var config = (0, config_1.getConfig)();
|
|
141
|
+
config.sessionId = sessionId;
|
|
142
|
+
(0, session_manager_1.updateCookies)(config);
|
|
143
|
+
};
|
|
144
|
+
exports.setSessionId = setSessionId;
|
|
145
|
+
/**
|
|
146
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
147
|
+
*
|
|
148
|
+
*```typescript
|
|
149
|
+
* // Stops tracking
|
|
150
|
+
* setOptOut(true);
|
|
151
|
+
*
|
|
152
|
+
* // Starts/resumes tracking
|
|
153
|
+
* setOptOut(false);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
var setOptOut = function (optOut) {
|
|
157
|
+
(0, analytics_core_1.setOptOut)(optOut);
|
|
158
|
+
var config = (0, config_1.getConfig)();
|
|
159
|
+
(0, session_manager_1.updateCookies)(config);
|
|
160
|
+
};
|
|
161
|
+
exports.setOptOut = setOptOut;
|
|
162
|
+
/**
|
|
163
|
+
* Sets the network transport type for events.
|
|
164
|
+
*
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Use Fetch API
|
|
167
|
+
* setTransport('fetch');
|
|
168
|
+
*
|
|
169
|
+
* // Use XMLHttpRequest API
|
|
170
|
+
* setTransport('xhr');
|
|
171
|
+
*
|
|
172
|
+
* // Use navigator.sendBeacon API
|
|
173
|
+
* setTransport('beacon');
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
var setTransport = function (transport) {
|
|
177
|
+
var config = (0, config_1.getConfig)();
|
|
178
|
+
var transportProvider = (0, config_1.createTransport)(transport);
|
|
179
|
+
config.transportProvider = transportProvider;
|
|
180
|
+
};
|
|
181
|
+
exports.setTransport = setTransport;
|
|
182
|
+
/**
|
|
183
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
184
|
+
*
|
|
185
|
+
* ```typescript
|
|
186
|
+
* // event tracking with event type only
|
|
187
|
+
* track('Page Load');
|
|
188
|
+
*
|
|
189
|
+
* // event tracking with event type and additional event properties
|
|
190
|
+
* track('Page Load', { loadTime: 1000 });
|
|
191
|
+
*
|
|
192
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
193
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
194
|
+
*
|
|
195
|
+
* // alternatively, this tracking method is awaitable
|
|
196
|
+
* const result = await track('Page Load').promise;
|
|
197
|
+
* console.log(result.event); // {...}
|
|
198
|
+
* console.log(result.code); // 200
|
|
199
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
var track = function (eventType, eventProperties, eventOptions) {
|
|
203
|
+
return {
|
|
204
|
+
promise: (0, analytics_core_1.track)(eventType, eventProperties, eventOptions),
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
exports.track = track;
|
|
208
|
+
/**
|
|
209
|
+
* Alis for track()
|
|
210
|
+
*/
|
|
211
|
+
exports.logEvent = exports.track;
|
|
212
|
+
/**
|
|
213
|
+
* Sends an identify event containing user property operations
|
|
214
|
+
*
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const id = new Identify();
|
|
217
|
+
* id.set('colors', ['rose', 'gold']);
|
|
218
|
+
* identify(id);
|
|
219
|
+
*
|
|
220
|
+
* // alternatively, this tracking method is awaitable
|
|
221
|
+
* const result = await identify(id).promise;
|
|
222
|
+
* console.log(result.event); // {...}
|
|
223
|
+
* console.log(result.code); // 200
|
|
224
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
var identify = function (identify, eventOptions) {
|
|
228
|
+
if ((0, snippet_helper_1.isInstanceProxy)(identify)) {
|
|
229
|
+
var queue = identify._q;
|
|
230
|
+
identify._q = [];
|
|
231
|
+
identify = (0, snippet_helper_1.convertProxyObjectToRealObject)(new analytics_core_1.Identify(), queue);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
promise: (0, analytics_core_1.identify)(undefined, undefined, identify, eventOptions),
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
exports.identify = identify;
|
|
238
|
+
/**
|
|
239
|
+
* Sends a group identify event containing group property operations.
|
|
240
|
+
*
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const id = new Identify();
|
|
243
|
+
* id.set('skills', ['js', 'ts']);
|
|
244
|
+
* const groupType = 'org';
|
|
245
|
+
* const groupName = 'engineering';
|
|
246
|
+
* groupIdentify(groupType, groupName, id);
|
|
247
|
+
*
|
|
248
|
+
* // alternatively, this tracking method is awaitable
|
|
249
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
250
|
+
* console.log(result.event); // {...}
|
|
251
|
+
* console.log(result.code); // 200
|
|
252
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
var groupIdentify = function (groupType, groupName, identify, eventOptions) {
|
|
256
|
+
if ((0, snippet_helper_1.isInstanceProxy)(identify)) {
|
|
257
|
+
var queue = identify._q;
|
|
258
|
+
identify._q = [];
|
|
259
|
+
identify = (0, snippet_helper_1.convertProxyObjectToRealObject)(new analytics_core_1.Identify(), queue);
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
promise: (0, analytics_core_1.groupIdentify)(undefined, undefined, groupType, groupName, identify, eventOptions),
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
exports.groupIdentify = groupIdentify;
|
|
266
|
+
var setGroup = function (groupType, groupName) {
|
|
267
|
+
return {
|
|
268
|
+
promise: (0, analytics_core_1.setGroup)(groupType, groupName),
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
exports.setGroup = setGroup;
|
|
272
|
+
/**
|
|
273
|
+
* Sends a revenue event containing revenue property operations.
|
|
274
|
+
*
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const rev = new Revenue();
|
|
277
|
+
* rev.setRevenue(100);
|
|
278
|
+
* revenue(rev);
|
|
279
|
+
*
|
|
280
|
+
* // alternatively, this tracking method is awaitable
|
|
281
|
+
* const result = await revenue(rev).promise;
|
|
282
|
+
* console.log(result.event); // {...}
|
|
283
|
+
* console.log(result.code); // 200
|
|
284
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
var revenue = function (revenue, eventOptions) {
|
|
288
|
+
if ((0, snippet_helper_1.isInstanceProxy)(revenue)) {
|
|
289
|
+
var queue = revenue._q;
|
|
290
|
+
revenue._q = [];
|
|
291
|
+
revenue = (0, snippet_helper_1.convertProxyObjectToRealObject)(new analytics_core_1.Revenue(), queue);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
promise: (0, analytics_core_1.revenue)(revenue, eventOptions),
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
exports.revenue = revenue;
|
|
298
|
+
//# sourceMappingURL=browser-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,iBA2TA;;;;AA3TA,4DAamC;AAUnC,yDAAyF;AACzF,6CAA4C;AAC5C,mCAAoE;AACpE,6CAAkD;AAClD,qDAAkD;AAElD;;;;;;;GAOG;AACI,IAAM,IAAI,GAAG,UAAC,MAAc,EAAE,MAAe,EAAE,OAAwB;IAC5E,OAAO;QACL,OAAO,EAAE,CAAC;;;;;wBACF,cAAc,GAAG,IAAA,qBAAY,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;wBACvD,MAAM,GAAG,IAAA,qBAAK,EAAC,cAAc,CAAkB,CAAC;wBACtD,IAAA,+BAAa,EAAC,MAAM,CAAC,CAAC;wBAEtB,qBAAM,IAAA,oBAAI,EAAC,IAAI,iBAAO,EAAE,CAAC,EAAA;;wBAAzB,SAAyB,CAAC;wBAC1B,qBAAM,IAAA,oBAAI,EAAC,IAAI,4BAAW,EAAE,CAAC,EAAA;;wBAA7B,SAA6B,CAAC;wBAC9B,IAAA,+BAAiB,EAAC,MAAM,CAAC,CAAC;;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AAG,EAAE,CAAC;QAChB,OAAO,GAAG,IAAA,+CAA8B,EAAC,IAAI,wBAAO,EAAE,EAAE,KAAK,CAAC,CAAC;KAChE;IACD,OAAO;QACL,OAAO,EAAE,IAAA,wBAAQ,EAAC,OAAO,EAAE,YAAY,CAAC;KACzC,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,OAAO,WASlB","sourcesContent":["import {\n add as _add,\n groupIdentify as _groupIdentify,\n Destination,\n identify as _identify,\n revenue as _revenue,\n init as _init,\n setOptOut as _setOptOut,\n Identify,\n Revenue,\n track as _track,\n setGroup as _setGroup,\n remove as _remove,\n} from '@amplitude/analytics-core';\nimport {\n AmplitudeReturn,\n BrowserConfig,\n BrowserOptions,\n EventOptions,\n Plugin,\n Result,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { createConfig, createTransport, getConfig } from './config';\nimport { trackAttributions } from './attribution';\nimport { updateCookies } from './session-manager';\n\n/**\n * Initializes the Amplitude SDK with your apiKey, userId and optional configurations.\n * This method must be called before any other operations.\n *\n * ```typescript\n * await init(API_KEY, USER_ID, options).promise;\n * ```\n */\nexport const init = (apiKey: string, userId?: string, options?: BrowserOptions): AmplitudeReturn<void> => {\n return {\n promise: (async () => {\n const browserOptions = createConfig(apiKey, userId, options);\n const config = _init(browserOptions) as BrowserConfig;\n updateCookies(config);\n\n await _add(new Context());\n await _add(new Destination());\n trackAttributions(config);\n })(),\n };\n};\n\n/**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {...};\n * amplitude.add(plugin);\n * ```\n */\nexport const add = (plugin: Plugin): AmplitudeReturn<void> => {\n return {\n promise: _add(plugin),\n };\n};\n\n/**\n * Removes a plugin.\n *\n * ```typescript\n * amplitude.remove('myPlugin');\n * ```\n */\nexport const remove = (pluginName: string): AmplitudeReturn<void> => {\n return {\n promise: _remove(pluginName),\n };\n};\n\n/**\n * Returns current user ID.\n *\n * ```typescript\n * const userId = getUserId();\n * ```\n */\nexport const getUserId = () => {\n return getConfig().userId;\n};\n\n/**\n * Sets a new user ID.\n *\n * ```typescript\n * setUserId('userId');\n * ```\n */\nexport const setUserId = (userId: string) => {\n const config = getConfig();\n config.userId = userId;\n updateCookies(config);\n};\n\n/**\n * Returns current device ID.\n *\n * ```typescript\n * const deviceId = getDeviceId();\n * ```\n */\nexport const getDeviceId = () => {\n return getConfig().deviceId;\n};\n\n/**\n * Sets a new device ID.\n * When setting a custom device ID, make sure the value is sufficiently unique.\n * A uuid is recommended.\n *\n * ```typescript\n * setDeviceId('deviceId');\n * ```\n */\nexport const setDeviceId = (deviceId: string) => {\n const config = getConfig();\n config.deviceId = deviceId;\n updateCookies(config);\n};\n\n/**\n * Returns current session ID.\n *\n * ```typescript\n * const sessionId = getSessionId();\n * ```\n */\nexport const getSessionId = () => {\n return getConfig().sessionId;\n};\n\n/**\n * Sets a new session ID.\n * When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).\n *\n * ```typescript\n * setSessionId(Date.now());\n * ```\n */\nexport const setSessionId = (sessionId: number) => {\n const config = getConfig();\n config.sessionId = sessionId;\n updateCookies(config);\n};\n\n/**\n * Sets a new optOut config value. This toggles event tracking on/off.\n *\n *```typescript\n * // Stops tracking\n * setOptOut(true);\n *\n * // Starts/resumes tracking\n * setOptOut(false);\n * ```\n */\nexport const setOptOut = (optOut: boolean) => {\n _setOptOut(optOut);\n const config = getConfig();\n updateCookies(config);\n};\n\n/**\n * Sets the network transport type for events.\n *\n * ```typescript\n * // Use Fetch API\n * setTransport('fetch');\n *\n * // Use XMLHttpRequest API\n * setTransport('xhr');\n *\n * // Use navigator.sendBeacon API\n * setTransport('beacon');\n * ```\n */\nexport const setTransport = (transport: TransportType) => {\n const config = getConfig();\n const transportProvider = createTransport(transport);\n config.transportProvider = transportProvider;\n};\n\n/**\n * Tracks user-defined event, with specified type, optional event properties and optional overwrites.\n *\n * ```typescript\n * // event tracking with event type only\n * track('Page Load');\n *\n * // event tracking with event type and additional event properties\n * track('Page Load', { loadTime: 1000 });\n *\n * // event tracking with event type, additional event properties, and overwritten event options\n * track('Page Load', { loadTime: 1000 }, { sessionId: -1 });\n *\n * // alternatively, this tracking method is awaitable\n * const result = await track('Page Load').promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const track = (\n eventType: string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): AmplitudeReturn<Result> => {\n return {\n promise: _track(eventType, eventProperties, eventOptions),\n };\n};\n\n/**\n * Alis for track()\n */\nexport const logEvent = track;\n\n/**\n * Sends an identify event containing user property operations\n *\n * ```typescript\n * const id = new Identify();\n * id.set('colors', ['rose', 'gold']);\n * identify(id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await identify(id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const identify = (identify: Identify, eventOptions?: EventOptions): AmplitudeReturn<Result> => {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return {\n promise: _identify(undefined, undefined, identify, eventOptions),\n };\n};\n\n/**\n * Sends a group identify event containing group property operations.\n *\n * ```typescript\n * const id = new Identify();\n * id.set('skills', ['js', 'ts']);\n * const groupType = 'org';\n * const groupName = 'engineering';\n * groupIdentify(groupType, groupName, id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await groupIdentify(groupType, groupName, id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const groupIdentify = (\n groupType: string,\n groupName: string | string[],\n identify: Identify,\n eventOptions?: EventOptions,\n): AmplitudeReturn<Result> => {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return {\n promise: _groupIdentify(undefined, undefined, groupType, groupName, identify, eventOptions),\n };\n};\n\nexport const setGroup = (groupType: string, groupName: string | string[]): AmplitudeReturn<Result> => {\n return {\n promise: _setGroup(groupType, groupName),\n };\n};\n\n/**\n * Sends a revenue event containing revenue property operations.\n *\n * ```typescript\n * const rev = new Revenue();\n * rev.setRevenue(100);\n * revenue(rev);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await revenue(rev).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const revenue = (revenue: Revenue, eventOptions?: EventOptions): AmplitudeReturn<Result> => {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return {\n promise: _revenue(revenue, eventOptions),\n };\n};\n"]}
|