Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@amplitude/analytics-browser

Package Overview
Dependencies
Maintainers
20
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplitude/analytics-browser - npm Package Compare versions

Comparing version 1.9.0-beta.1 to 1.9.0-beta.2

1

lib/cjs/browser-client.d.ts

@@ -5,2 +5,3 @@ import { AmplitudeCore } from '@amplitude/analytics-core';

config: BrowserConfig;
previousSessionDeviceId: string | undefined;
previousSessionUserId: string | undefined;

@@ -7,0 +8,0 @@ init(apiKey?: string, userId?: string, options?: BrowserOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>;

130

lib/cjs/browser-client.js

@@ -26,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });

AmplitudeBrowser.prototype._init = function (options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _r, _s, _t, _u;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var oldCookies, browserOptions, isNewSession, connector, webAttribution, pageViewTrackingOptions;
var _v, _w, _x, legacyCookies, cookieStorage, previousCookies, queryParams, deviceId, sessionId, optOut, lastEventTime, userId, browserOptions, isNewSession, connector, webAttribution, pageViewTrackingOptions;
var _this = this;
return tslib_1.__generator(this, function (_k) {
switch (_k.label) {
return tslib_1.__generator(this, function (_y) {
switch (_y.label) {
case 0:

@@ -39,11 +39,44 @@ // Step 0: Block concurrent initialization

this.initializing = true;
return [4 /*yield*/, (0, cookie_migration_1.parseOldCookies)(options.apiKey, options)];
// Step 1: Read cookies stored by SDK
_v = options;
if (!options.disableCookies) return [3 /*break*/, 1];
_w = '';
return [3 /*break*/, 5];
case 1:
oldCookies = _k.sent();
return [4 /*yield*/, (0, config_1.useBrowserConfig)(options.apiKey, tslib_1.__assign(tslib_1.__assign({}, options), { deviceId: (_a = oldCookies.deviceId) !== null && _a !== void 0 ? _a : options.deviceId, sessionId: (_b = oldCookies.sessionId) !== null && _b !== void 0 ? _b : options.sessionId, optOut: (_c = options.optOut) !== null && _c !== void 0 ? _c : oldCookies.optOut, lastEventTime: oldCookies.lastEventTime, userId: (_d = options.userId) !== null && _d !== void 0 ? _d : oldCookies.userId }))];
case 2:
browserOptions = _k.sent();
if (!((_a = options.domain) !== null && _a !== void 0)) return [3 /*break*/, 2];
_x = _a;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, (0, config_1.getTopLevelDomain)()];
case 3:
_x = (_y.sent());
_y.label = 4;
case 4:
_w = _x;
_y.label = 5;
case 5:
// Step 1: Read cookies stored by SDK
_v.domain = _w;
return [4 /*yield*/, (0, cookie_migration_1.parseLegacyCookies)(options.apiKey, options)];
case 6:
legacyCookies = _y.sent();
return [4 /*yield*/, (0, config_1.createCookieStorage)(options)];
case 7:
cookieStorage = _y.sent();
return [4 /*yield*/, cookieStorage.get((0, analytics_client_common_1.getCookieName)(options.apiKey))];
case 8:
previousCookies = _y.sent();
queryParams = (0, analytics_client_common_1.getQueryParams)();
deviceId = (_d = (_c = (_b = options.deviceId) !== null && _b !== void 0 ? _b : queryParams.deviceId) !== null && _c !== void 0 ? _c : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.deviceId) !== null && _d !== void 0 ? _d : legacyCookies.deviceId;
sessionId = (_f = (_e = options.sessionId) !== null && _e !== void 0 ? _e : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.sessionId) !== null && _f !== void 0 ? _f : legacyCookies.sessionId;
optOut = (_h = (_g = options.optOut) !== null && _g !== void 0 ? _g : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.optOut) !== null && _h !== void 0 ? _h : legacyCookies.optOut;
lastEventTime = (_j = previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.lastEventTime) !== null && _j !== void 0 ? _j : legacyCookies.lastEventTime;
userId = (_l = (_k = options.userId) !== null && _k !== void 0 ? _k : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.userId) !== null && _l !== void 0 ? _l : legacyCookies.userId;
this.previousSessionDeviceId = (_m = previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.deviceId) !== null && _m !== void 0 ? _m : legacyCookies.deviceId;
this.previousSessionUserId = (_o = previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.userId) !== null && _o !== void 0 ? _o : legacyCookies.userId;
return [4 /*yield*/, (0, config_1.useBrowserConfig)(options.apiKey, tslib_1.__assign(tslib_1.__assign({}, options), { deviceId: deviceId, sessionId: sessionId, optOut: optOut, lastEventTime: lastEventTime, userId: userId, cookieStorage: cookieStorage }))];
case 9:
browserOptions = _y.sent();
return [4 /*yield*/, _super.prototype._init.call(this, browserOptions)];
case 3:
_k.sent();
case 10:
_y.sent();
isNewSession = !this.config.lastEventTime;

@@ -69,32 +102,32 @@ if (!this.config.sessionId ||

return [4 /*yield*/, this.add(new analytics_core_1.Destination()).promise];
case 4:
case 11:
// Step 4: Install plugins
// Do not track any events before this
_k.sent();
_y.sent();
return [4 /*yield*/, this.add(new context_1.Context()).promise];
case 5:
_k.sent();
case 12:
_y.sent();
return [4 /*yield*/, this.add((0, session_handler_1.sessionHandlerPlugin)()).promise];
case 6:
_k.sent();
case 13:
_y.sent();
return [4 /*yield*/, this.add(new analytics_client_common_1.IdentityEventSender()).promise];
case 7:
_k.sent();
if (!(0, analytics_client_common_1.isFileDownloadTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 9];
case 14:
_y.sent();
if (!(0, analytics_client_common_1.isFileDownloadTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 16];
return [4 /*yield*/, this.add((0, file_download_tracking_1.fileDownloadTracking)()).promise];
case 8:
_k.sent();
_k.label = 9;
case 9:
if (!(0, analytics_client_common_1.isFormInteractionTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 11];
case 15:
_y.sent();
_y.label = 16;
case 16:
if (!(0, analytics_client_common_1.isFormInteractionTrackingEnabled)(this.config.defaultTracking)) return [3 /*break*/, 18];
return [4 /*yield*/, this.add((0, form_interaction_tracking_1.formInteractionTracking)()).promise];
case 10:
_k.sent();
_k.label = 11;
case 11:
if (!!((_e = this.config.attribution) === null || _e === void 0 ? void 0 : _e.disabled)) return [3 /*break*/, 13];
case 17:
_y.sent();
_y.label = 18;
case 18:
if (!!((_p = this.config.attribution) === null || _p === void 0 ? void 0 : _p.disabled)) return [3 /*break*/, 20];
webAttribution = (0, plugin_web_attribution_browser_1.webAttributionPlugin)({
excludeReferrers: (_f = this.config.attribution) === null || _f === void 0 ? void 0 : _f.excludeReferrers,
initialEmptyValue: (_g = this.config.attribution) === null || _g === void 0 ? void 0 : _g.initialEmptyValue,
resetSessionOnNewCampaign: (_h = this.config.attribution) === null || _h === void 0 ? void 0 : _h.resetSessionOnNewCampaign,
excludeReferrers: (_r = this.config.attribution) === null || _r === void 0 ? void 0 : _r.excludeReferrers,
initialEmptyValue: (_s = this.config.attribution) === null || _s === void 0 ? void 0 : _s.initialEmptyValue,
resetSessionOnNewCampaign: (_t = this.config.attribution) === null || _t === void 0 ? void 0 : _t.resetSessionOnNewCampaign,
});

@@ -107,19 +140,19 @@ // For Amplitude-internal functionality

webAttribution.__pluginEnabledOverride =
isNewSession || ((_j = this.config.attribution) === null || _j === void 0 ? void 0 : _j.trackNewCampaigns) ? undefined : false;
isNewSession || ((_u = this.config.attribution) === null || _u === void 0 ? void 0 : _u.trackNewCampaigns) ? undefined : false;
return [4 /*yield*/, this.add(webAttribution).promise];
case 12:
_k.sent();
_k.label = 13;
case 13:
case 19:
_y.sent();
_y.label = 20;
case 20:
pageViewTrackingOptions = (0, analytics_client_common_1.getPageViewTrackingConfig)(this.config);
pageViewTrackingOptions.eventType = pageViewTrackingOptions.eventType || constants_1.DEFAULT_PAGE_VIEW_EVENT;
return [4 /*yield*/, this.add((0, plugin_page_view_tracking_browser_1.pageViewTrackingPlugin)(pageViewTrackingOptions)).promise];
case 14:
_k.sent();
case 21:
_y.sent();
this.initializing = false;
// Step 6: Run queued dispatch functions
return [4 /*yield*/, this.runQueuedFunctions('dispatchQ')];
case 15:
case 22:
// Step 6: Run queued dispatch functions
_k.sent();
_y.sent();
return [2 /*return*/];

@@ -139,4 +172,3 @@ }

}
if (userId !== this.config.userId) {
this.previousSessionUserId = this.config.userId;
if (userId !== this.config.userId || userId === undefined) {
this.config.userId = userId;

@@ -158,4 +190,4 @@ this.setSessionId(Date.now());

AmplitudeBrowser.prototype.reset = function () {
this.setDeviceId((0, analytics_core_1.UUID)());
this.setUserId(undefined);
this.setDeviceId((0, analytics_core_1.UUID)());
};

@@ -181,7 +213,5 @@ AmplitudeBrowser.prototype.getSessionId = function () {

};
if (this.previousSessionUserId) {
eventOptions.user_id = this.previousSessionUserId;
}
eventOptions.device_id = this.previousSessionDeviceId;
eventOptions.user_id = this.previousSessionUserId;
this.track(constants_1.DEFAULT_SESSION_END_EVENT, undefined, eventOptions);
this.previousSessionUserId = undefined;
}

@@ -192,2 +222,4 @@ this.track(constants_1.DEFAULT_SESSION_START_EVENT, undefined, {

});
this.previousSessionDeviceId = this.config.deviceId;
this.previousSessionUserId = this.config.userId;
}

@@ -194,0 +226,0 @@ };

@@ -147,43 +147,22 @@ var _this = this;

var useBrowserConfig = function (apiKey, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var defaultConfig, domain, _a, _b, cookieStorage, previousCookies, queryParams, deviceId, lastEventTime, optOut, sessionId, userId, _c, _d, _e;
var _f;
var _g, _h, _j, _k, _l, _m, _o, _p, _q;
return tslib_1.__generator(this, function (_r) {
switch (_r.label) {
var defaultConfig, deviceId, lastEventTime, optOut, sessionId, userId, cookieStorage, domain, _a, _b, _c;
var _d;
var _e, _f;
return tslib_1.__generator(this, function (_g) {
switch (_g.label) {
case 0:
defaultConfig = (0, exports.getDefaultConfig)();
if (!(options === null || options === void 0 ? void 0 : options.disableCookies)) return [3 /*break*/, 1];
_a = '';
return [3 /*break*/, 5];
case 1:
if (!((_g = options === null || options === void 0 ? void 0 : options.domain) !== null && _g !== void 0)) return [3 /*break*/, 2];
_b = _g;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, (0, exports.getTopLevelDomain)()];
case 3:
_b = (_r.sent());
_r.label = 4;
case 4:
_a = _b;
_r.label = 5;
case 5:
domain = _a;
return [4 /*yield*/, (0, exports.createCookieStorage)(tslib_1.__assign(tslib_1.__assign({}, options), { domain: domain }))];
case 6:
cookieStorage = _r.sent();
return [4 /*yield*/, cookieStorage.get((0, analytics_client_common_1.getCookieName)(apiKey))];
case 7:
previousCookies = _r.sent();
queryParams = (0, analytics_client_common_1.getQueryParams)();
deviceId = (_k = (_j = (_h = options === null || options === void 0 ? void 0 : options.deviceId) !== null && _h !== void 0 ? _h : queryParams.deviceId) !== null && _j !== void 0 ? _j : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.deviceId) !== null && _k !== void 0 ? _k : (0, analytics_core_1.UUID)();
lastEventTime = (_l = options === null || options === void 0 ? void 0 : options.lastEventTime) !== null && _l !== void 0 ? _l : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.lastEventTime;
optOut = (_m = options === null || options === void 0 ? void 0 : options.optOut) !== null && _m !== void 0 ? _m : Boolean(previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.optOut);
sessionId = (_o = options === null || options === void 0 ? void 0 : options.sessionId) !== null && _o !== void 0 ? _o : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.sessionId;
userId = (_p = options === null || options === void 0 ? void 0 : options.userId) !== null && _p !== void 0 ? _p : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.userId;
_c = BrowserConfig.bind;
_d = [void 0, apiKey];
_e = [tslib_1.__assign({}, options)];
_f = { cookieStorage: cookieStorage, deviceId: deviceId, domain: domain, lastEventTime: lastEventTime, optOut: optOut, sessionId: sessionId };
deviceId = (_e = options === null || options === void 0 ? void 0 : options.deviceId) !== null && _e !== void 0 ? _e : (0, analytics_core_1.UUID)();
lastEventTime = options === null || options === void 0 ? void 0 : options.lastEventTime;
optOut = options === null || options === void 0 ? void 0 : options.optOut;
sessionId = options === null || options === void 0 ? void 0 : options.sessionId;
userId = options === null || options === void 0 ? void 0 : options.userId;
cookieStorage = options === null || options === void 0 ? void 0 : options.cookieStorage;
domain = options === null || options === void 0 ? void 0 : options.domain;
_a = BrowserConfig.bind;
_b = [void 0, apiKey];
_c = [tslib_1.__assign({}, options)];
_d = { cookieStorage: cookieStorage, deviceId: deviceId, domain: domain, lastEventTime: lastEventTime, optOut: optOut, sessionId: sessionId };
return [4 /*yield*/, (0, exports.createEventsStorage)(options)];
case 8: return [2 /*return*/, new (_c.apply(BrowserConfig, _d.concat([tslib_1.__assign.apply(void 0, _e.concat([(_f.storageProvider = _r.sent(), _f.trackingOptions = tslib_1.__assign(tslib_1.__assign({}, defaultConfig.trackingOptions), options === null || options === void 0 ? void 0 : options.trackingOptions), _f.transportProvider = (_q = options === null || options === void 0 ? void 0 : options.transportProvider) !== null && _q !== void 0 ? _q : (0, exports.createTransport)(options === null || options === void 0 ? void 0 : options.transport), _f.userId = userId, _f)]))])))()];
case 1: return [2 /*return*/, new (_a.apply(BrowserConfig, _b.concat([tslib_1.__assign.apply(void 0, _c.concat([(_d.storageProvider = _g.sent(), _d.trackingOptions = tslib_1.__assign(tslib_1.__assign({}, defaultConfig.trackingOptions), options === null || options === void 0 ? void 0 : options.trackingOptions), _d.transportProvider = (_f = options === null || options === void 0 ? void 0 : options.transportProvider) !== null && _f !== void 0 ? _f : (0, exports.createTransport)(options === null || options === void 0 ? void 0 : options.transport), _d.userId = userId, _d)]))])))()];
}

@@ -190,0 +169,0 @@ });

import { BrowserOptions, UserSession } from '@amplitude/analytics-types';
export declare const parseOldCookies: (apiKey: string, options?: BrowserOptions) => Promise<UserSession>;
export declare const parseLegacyCookies: (apiKey: string, options?: BrowserOptions) => Promise<UserSession>;
export declare const parseTime: (num: string) => number | undefined;
export declare const decode: (value?: string) => string | undefined;
//# sourceMappingURL=index.d.ts.map
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
exports.decode = exports.parseTime = exports.parseOldCookies = void 0;
exports.decode = exports.parseTime = exports.parseLegacyCookies = void 0;
var tslib_1 = require("tslib");
var analytics_client_common_1 = require("@amplitude/analytics-client-common");
var config_1 = require("../config");
var parseOldCookies = function (apiKey, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var storage, _a, _b, _c, _d, oldCookieName, cookies, _e, deviceId, userId, optOut, sessionId, lastEventTime;
var _f;
var _g, _h;
return tslib_1.__generator(this, function (_j) {
switch (_j.label) {
case 0:
_a = config_1.createCookieStorage;
_b = [tslib_1.__assign({}, options)];
_f = {};
if (!(options === null || options === void 0 ? void 0 : options.disableCookies)) return [3 /*break*/, 1];
_c = '';
return [3 /*break*/, 5];
var parseLegacyCookies = function (apiKey, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var storage, oldCookieName, cookies, _a, deviceId, userId, optOut, sessionId, lastEventTime;
var _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, (0, config_1.createCookieStorage)(options)];
case 1:
if (!((_g = options === null || options === void 0 ? void 0 : options.domain) !== null && _g !== void 0)) return [3 /*break*/, 2];
_d = _g;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, (0, config_1.getTopLevelDomain)()];
case 3:
_d = (_j.sent());
_j.label = 4;
case 4:
_c = _d;
_j.label = 5;
case 5: return [4 /*yield*/, _a.apply(void 0, [tslib_1.__assign.apply(void 0, _b.concat([(_f.domain = _c, _f)]))])];
case 6:
storage = _j.sent();
storage = _c.sent();
oldCookieName = (0, analytics_client_common_1.getOldCookieName)(apiKey);
return [4 /*yield*/, storage.getRaw(oldCookieName)];
case 7:
cookies = _j.sent();
case 2:
cookies = _c.sent();
if (!cookies) {

@@ -43,9 +24,9 @@ return [2 /*return*/, {

}
if (!((_h = options === null || options === void 0 ? void 0 : options.cookieUpgrade) !== null && _h !== void 0 ? _h : (0, config_1.getDefaultConfig)().cookieUpgrade)) return [3 /*break*/, 9];
if (!((_b = options === null || options === void 0 ? void 0 : options.cookieUpgrade) !== null && _b !== void 0 ? _b : (0, config_1.getDefaultConfig)().cookieUpgrade)) return [3 /*break*/, 4];
return [4 /*yield*/, storage.remove(oldCookieName)];
case 8:
_j.sent();
_j.label = 9;
case 9:
_e = tslib_1.__read(cookies.split('.'), 5), deviceId = _e[0], userId = _e[1], optOut = _e[2], sessionId = _e[3], lastEventTime = _e[4];
case 3:
_c.sent();
_c.label = 4;
case 4:
_a = tslib_1.__read(cookies.split('.'), 5), deviceId = _a[0], userId = _a[1], optOut = _a[2], sessionId = _a[3], lastEventTime = _a[4];
return [2 /*return*/, {

@@ -61,3 +42,3 @@ deviceId: deviceId,

}); };
exports.parseOldCookies = parseOldCookies;
exports.parseLegacyCookies = parseLegacyCookies;
var parseTime = function (num) {

@@ -64,0 +45,0 @@ var integer = parseInt(num, 32);

@@ -1,2 +0,2 @@

export declare const VERSION = "1.9.0-beta.1";
export declare const VERSION = "1.9.0-beta.2";
//# sourceMappingURL=version.d.ts.map
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
exports.VERSION = '1.9.0-beta.1';
exports.VERSION = '1.9.0-beta.2';
//# sourceMappingURL=version.js.map

@@ -5,2 +5,3 @@ import { AmplitudeCore } from '@amplitude/analytics-core';

config: BrowserConfig;
previousSessionDeviceId: string | undefined;
previousSessionUserId: string | undefined;

@@ -7,0 +8,0 @@ init(apiKey?: string, userId?: string, options?: BrowserOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>;

import { __assign, __awaiter, __extends, __generator } from "tslib";
import { AmplitudeCore, Destination, Identify, returnWrapper, Revenue, UUID } from '@amplitude/analytics-core';
import { getAnalyticsConnector, getPageViewTrackingConfig, IdentityEventSender, isSessionTrackingEnabled, isFileDownloadTrackingEnabled, isFormInteractionTrackingEnabled, } from '@amplitude/analytics-client-common';
import { getAnalyticsConnector, getPageViewTrackingConfig, IdentityEventSender, isSessionTrackingEnabled, isFileDownloadTrackingEnabled, isFormInteractionTrackingEnabled, getCookieName, getQueryParams, } from '@amplitude/analytics-client-common';
import { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';
import { Context } from './plugins/context';
import { useBrowserConfig, createTransport } from './config';
import { parseOldCookies } from './cookie-migration';
import { useBrowserConfig, createTransport, getTopLevelDomain, createCookieStorage } from './config';
import { parseLegacyCookies } from './cookie-migration';
import { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser';

@@ -24,8 +24,8 @@ import { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';

AmplitudeBrowser.prototype._init = function (options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _r, _s, _t, _u;
return __awaiter(this, void 0, void 0, function () {
var oldCookies, browserOptions, isNewSession, connector, webAttribution, pageViewTrackingOptions;
var _v, _w, _x, legacyCookies, cookieStorage, previousCookies, queryParams, deviceId, sessionId, optOut, lastEventTime, userId, browserOptions, isNewSession, connector, webAttribution, pageViewTrackingOptions;
var _this = this;
return __generator(this, function (_k) {
switch (_k.label) {
return __generator(this, function (_y) {
switch (_y.label) {
case 0:

@@ -37,11 +37,44 @@ // Step 0: Block concurrent initialization

this.initializing = true;
return [4 /*yield*/, parseOldCookies(options.apiKey, options)];
// Step 1: Read cookies stored by SDK
_v = options;
if (!options.disableCookies) return [3 /*break*/, 1];
_w = '';
return [3 /*break*/, 5];
case 1:
oldCookies = _k.sent();
return [4 /*yield*/, useBrowserConfig(options.apiKey, __assign(__assign({}, options), { deviceId: (_a = oldCookies.deviceId) !== null && _a !== void 0 ? _a : options.deviceId, sessionId: (_b = oldCookies.sessionId) !== null && _b !== void 0 ? _b : options.sessionId, optOut: (_c = options.optOut) !== null && _c !== void 0 ? _c : oldCookies.optOut, lastEventTime: oldCookies.lastEventTime, userId: (_d = options.userId) !== null && _d !== void 0 ? _d : oldCookies.userId }))];
case 2:
browserOptions = _k.sent();
if (!((_a = options.domain) !== null && _a !== void 0)) return [3 /*break*/, 2];
_x = _a;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, getTopLevelDomain()];
case 3:
_x = (_y.sent());
_y.label = 4;
case 4:
_w = _x;
_y.label = 5;
case 5:
// Step 1: Read cookies stored by SDK
_v.domain = _w;
return [4 /*yield*/, parseLegacyCookies(options.apiKey, options)];
case 6:
legacyCookies = _y.sent();
return [4 /*yield*/, createCookieStorage(options)];
case 7:
cookieStorage = _y.sent();
return [4 /*yield*/, cookieStorage.get(getCookieName(options.apiKey))];
case 8:
previousCookies = _y.sent();
queryParams = getQueryParams();
deviceId = (_d = (_c = (_b = options.deviceId) !== null && _b !== void 0 ? _b : queryParams.deviceId) !== null && _c !== void 0 ? _c : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.deviceId) !== null && _d !== void 0 ? _d : legacyCookies.deviceId;
sessionId = (_f = (_e = options.sessionId) !== null && _e !== void 0 ? _e : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.sessionId) !== null && _f !== void 0 ? _f : legacyCookies.sessionId;
optOut = (_h = (_g = options.optOut) !== null && _g !== void 0 ? _g : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.optOut) !== null && _h !== void 0 ? _h : legacyCookies.optOut;
lastEventTime = (_j = previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.lastEventTime) !== null && _j !== void 0 ? _j : legacyCookies.lastEventTime;
userId = (_l = (_k = options.userId) !== null && _k !== void 0 ? _k : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.userId) !== null && _l !== void 0 ? _l : legacyCookies.userId;
this.previousSessionDeviceId = (_m = previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.deviceId) !== null && _m !== void 0 ? _m : legacyCookies.deviceId;
this.previousSessionUserId = (_o = previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.userId) !== null && _o !== void 0 ? _o : legacyCookies.userId;
return [4 /*yield*/, useBrowserConfig(options.apiKey, __assign(__assign({}, options), { deviceId: deviceId, sessionId: sessionId, optOut: optOut, lastEventTime: lastEventTime, userId: userId, cookieStorage: cookieStorage }))];
case 9:
browserOptions = _y.sent();
return [4 /*yield*/, _super.prototype._init.call(this, browserOptions)];
case 3:
_k.sent();
case 10:
_y.sent();
isNewSession = !this.config.lastEventTime;

@@ -67,32 +100,32 @@ if (!this.config.sessionId ||

return [4 /*yield*/, this.add(new Destination()).promise];
case 4:
case 11:
// Step 4: Install plugins
// Do not track any events before this
_k.sent();
_y.sent();
return [4 /*yield*/, this.add(new Context()).promise];
case 5:
_k.sent();
case 12:
_y.sent();
return [4 /*yield*/, this.add(sessionHandlerPlugin()).promise];
case 6:
_k.sent();
case 13:
_y.sent();
return [4 /*yield*/, this.add(new IdentityEventSender()).promise];
case 7:
_k.sent();
if (!isFileDownloadTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 9];
case 14:
_y.sent();
if (!isFileDownloadTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 16];
return [4 /*yield*/, this.add(fileDownloadTracking()).promise];
case 8:
_k.sent();
_k.label = 9;
case 9:
if (!isFormInteractionTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 11];
case 15:
_y.sent();
_y.label = 16;
case 16:
if (!isFormInteractionTrackingEnabled(this.config.defaultTracking)) return [3 /*break*/, 18];
return [4 /*yield*/, this.add(formInteractionTracking()).promise];
case 10:
_k.sent();
_k.label = 11;
case 11:
if (!!((_e = this.config.attribution) === null || _e === void 0 ? void 0 : _e.disabled)) return [3 /*break*/, 13];
case 17:
_y.sent();
_y.label = 18;
case 18:
if (!!((_p = this.config.attribution) === null || _p === void 0 ? void 0 : _p.disabled)) return [3 /*break*/, 20];
webAttribution = webAttributionPlugin({
excludeReferrers: (_f = this.config.attribution) === null || _f === void 0 ? void 0 : _f.excludeReferrers,
initialEmptyValue: (_g = this.config.attribution) === null || _g === void 0 ? void 0 : _g.initialEmptyValue,
resetSessionOnNewCampaign: (_h = this.config.attribution) === null || _h === void 0 ? void 0 : _h.resetSessionOnNewCampaign,
excludeReferrers: (_r = this.config.attribution) === null || _r === void 0 ? void 0 : _r.excludeReferrers,
initialEmptyValue: (_s = this.config.attribution) === null || _s === void 0 ? void 0 : _s.initialEmptyValue,
resetSessionOnNewCampaign: (_t = this.config.attribution) === null || _t === void 0 ? void 0 : _t.resetSessionOnNewCampaign,
});

@@ -105,19 +138,19 @@ // For Amplitude-internal functionality

webAttribution.__pluginEnabledOverride =
isNewSession || ((_j = this.config.attribution) === null || _j === void 0 ? void 0 : _j.trackNewCampaigns) ? undefined : false;
isNewSession || ((_u = this.config.attribution) === null || _u === void 0 ? void 0 : _u.trackNewCampaigns) ? undefined : false;
return [4 /*yield*/, this.add(webAttribution).promise];
case 12:
_k.sent();
_k.label = 13;
case 13:
case 19:
_y.sent();
_y.label = 20;
case 20:
pageViewTrackingOptions = getPageViewTrackingConfig(this.config);
pageViewTrackingOptions.eventType = pageViewTrackingOptions.eventType || DEFAULT_PAGE_VIEW_EVENT;
return [4 /*yield*/, this.add(pageViewTrackingPlugin(pageViewTrackingOptions)).promise];
case 14:
_k.sent();
case 21:
_y.sent();
this.initializing = false;
// Step 6: Run queued dispatch functions
return [4 /*yield*/, this.runQueuedFunctions('dispatchQ')];
case 15:
case 22:
// Step 6: Run queued dispatch functions
_k.sent();
_y.sent();
return [2 /*return*/];

@@ -137,4 +170,3 @@ }

}
if (userId !== this.config.userId) {
this.previousSessionUserId = this.config.userId;
if (userId !== this.config.userId || userId === undefined) {
this.config.userId = userId;

@@ -156,4 +188,4 @@ this.setSessionId(Date.now());

AmplitudeBrowser.prototype.reset = function () {
this.setDeviceId(UUID());
this.setUserId(undefined);
this.setDeviceId(UUID());
};

@@ -179,7 +211,5 @@ AmplitudeBrowser.prototype.getSessionId = function () {

};
if (this.previousSessionUserId) {
eventOptions.user_id = this.previousSessionUserId;
}
eventOptions.device_id = this.previousSessionDeviceId;
eventOptions.user_id = this.previousSessionUserId;
this.track(DEFAULT_SESSION_END_EVENT, undefined, eventOptions);
this.previousSessionUserId = undefined;
}

@@ -190,2 +220,4 @@ this.track(DEFAULT_SESSION_START_EVENT, undefined, {

});
this.previousSessionDeviceId = this.config.deviceId;
this.previousSessionUserId = this.config.userId;
}

@@ -192,0 +224,0 @@ };

import { __assign, __awaiter, __extends, __generator, __values } from "tslib";
import { TransportType, } from '@amplitude/analytics-types';
import { Config, MemoryStorage, UUID } from '@amplitude/analytics-core';
import { CookieStorage, getCookieName, getQueryParams, FetchTransport } from '@amplitude/analytics-client-common';
import { CookieStorage, getCookieName, FetchTransport } from '@amplitude/analytics-client-common';
import { LocalStorage } from './storage/local-storage';

@@ -143,43 +143,22 @@ import { XHRTransport } from './transports/xhr';

export var useBrowserConfig = function (apiKey, options) { return __awaiter(void 0, void 0, void 0, function () {
var defaultConfig, domain, _a, _b, cookieStorage, previousCookies, queryParams, deviceId, lastEventTime, optOut, sessionId, userId, _c, _d, _e;
var _f;
var _g, _h, _j, _k, _l, _m, _o, _p, _q;
return __generator(this, function (_r) {
switch (_r.label) {
var defaultConfig, deviceId, lastEventTime, optOut, sessionId, userId, cookieStorage, domain, _a, _b, _c;
var _d;
var _e, _f;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
defaultConfig = getDefaultConfig();
if (!(options === null || options === void 0 ? void 0 : options.disableCookies)) return [3 /*break*/, 1];
_a = '';
return [3 /*break*/, 5];
case 1:
if (!((_g = options === null || options === void 0 ? void 0 : options.domain) !== null && _g !== void 0)) return [3 /*break*/, 2];
_b = _g;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, getTopLevelDomain()];
case 3:
_b = (_r.sent());
_r.label = 4;
case 4:
_a = _b;
_r.label = 5;
case 5:
domain = _a;
return [4 /*yield*/, createCookieStorage(__assign(__assign({}, options), { domain: domain }))];
case 6:
cookieStorage = _r.sent();
return [4 /*yield*/, cookieStorage.get(getCookieName(apiKey))];
case 7:
previousCookies = _r.sent();
queryParams = getQueryParams();
deviceId = (_k = (_j = (_h = options === null || options === void 0 ? void 0 : options.deviceId) !== null && _h !== void 0 ? _h : queryParams.deviceId) !== null && _j !== void 0 ? _j : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.deviceId) !== null && _k !== void 0 ? _k : UUID();
lastEventTime = (_l = options === null || options === void 0 ? void 0 : options.lastEventTime) !== null && _l !== void 0 ? _l : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.lastEventTime;
optOut = (_m = options === null || options === void 0 ? void 0 : options.optOut) !== null && _m !== void 0 ? _m : Boolean(previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.optOut);
sessionId = (_o = options === null || options === void 0 ? void 0 : options.sessionId) !== null && _o !== void 0 ? _o : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.sessionId;
userId = (_p = options === null || options === void 0 ? void 0 : options.userId) !== null && _p !== void 0 ? _p : previousCookies === null || previousCookies === void 0 ? void 0 : previousCookies.userId;
_c = BrowserConfig.bind;
_d = [void 0, apiKey];
_e = [__assign({}, options)];
_f = { cookieStorage: cookieStorage, deviceId: deviceId, domain: domain, lastEventTime: lastEventTime, optOut: optOut, sessionId: sessionId };
deviceId = (_e = options === null || options === void 0 ? void 0 : options.deviceId) !== null && _e !== void 0 ? _e : UUID();
lastEventTime = options === null || options === void 0 ? void 0 : options.lastEventTime;
optOut = options === null || options === void 0 ? void 0 : options.optOut;
sessionId = options === null || options === void 0 ? void 0 : options.sessionId;
userId = options === null || options === void 0 ? void 0 : options.userId;
cookieStorage = options === null || options === void 0 ? void 0 : options.cookieStorage;
domain = options === null || options === void 0 ? void 0 : options.domain;
_a = BrowserConfig.bind;
_b = [void 0, apiKey];
_c = [__assign({}, options)];
_d = { cookieStorage: cookieStorage, deviceId: deviceId, domain: domain, lastEventTime: lastEventTime, optOut: optOut, sessionId: sessionId };
return [4 /*yield*/, createEventsStorage(options)];
case 8: return [2 /*return*/, new (_c.apply(BrowserConfig, _d.concat([__assign.apply(void 0, _e.concat([(_f.storageProvider = _r.sent(), _f.trackingOptions = __assign(__assign({}, defaultConfig.trackingOptions), options === null || options === void 0 ? void 0 : options.trackingOptions), _f.transportProvider = (_q = options === null || options === void 0 ? void 0 : options.transportProvider) !== null && _q !== void 0 ? _q : createTransport(options === null || options === void 0 ? void 0 : options.transport), _f.userId = userId, _f)]))])))()];
case 1: return [2 /*return*/, new (_a.apply(BrowserConfig, _b.concat([__assign.apply(void 0, _c.concat([(_d.storageProvider = _g.sent(), _d.trackingOptions = __assign(__assign({}, defaultConfig.trackingOptions), options === null || options === void 0 ? void 0 : options.trackingOptions), _d.transportProvider = (_f = options === null || options === void 0 ? void 0 : options.transportProvider) !== null && _f !== void 0 ? _f : createTransport(options === null || options === void 0 ? void 0 : options.transport), _d.userId = userId, _d)]))])))()];
}

@@ -186,0 +165,0 @@ });

import { BrowserOptions, UserSession } from '@amplitude/analytics-types';
export declare const parseOldCookies: (apiKey: string, options?: BrowserOptions) => Promise<UserSession>;
export declare const parseLegacyCookies: (apiKey: string, options?: BrowserOptions) => Promise<UserSession>;
export declare const parseTime: (num: string) => number | undefined;
export declare const decode: (value?: string) => string | undefined;
//# sourceMappingURL=index.d.ts.map

@@ -1,35 +0,16 @@

import { __assign, __awaiter, __generator, __read } from "tslib";
import { __awaiter, __generator, __read } from "tslib";
import { getOldCookieName } from '@amplitude/analytics-client-common';
import { createCookieStorage, getDefaultConfig, getTopLevelDomain } from '../config';
export var parseOldCookies = function (apiKey, options) { return __awaiter(void 0, void 0, void 0, function () {
var storage, _a, _b, _c, _d, oldCookieName, cookies, _e, deviceId, userId, optOut, sessionId, lastEventTime;
var _f;
var _g, _h;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:
_a = createCookieStorage;
_b = [__assign({}, options)];
_f = {};
if (!(options === null || options === void 0 ? void 0 : options.disableCookies)) return [3 /*break*/, 1];
_c = '';
return [3 /*break*/, 5];
import { createCookieStorage, getDefaultConfig } from '../config';
export var parseLegacyCookies = function (apiKey, options) { return __awaiter(void 0, void 0, void 0, function () {
var storage, oldCookieName, cookies, _a, deviceId, userId, optOut, sessionId, lastEventTime;
var _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, createCookieStorage(options)];
case 1:
if (!((_g = options === null || options === void 0 ? void 0 : options.domain) !== null && _g !== void 0)) return [3 /*break*/, 2];
_d = _g;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, getTopLevelDomain()];
case 3:
_d = (_j.sent());
_j.label = 4;
case 4:
_c = _d;
_j.label = 5;
case 5: return [4 /*yield*/, _a.apply(void 0, [__assign.apply(void 0, _b.concat([(_f.domain = _c, _f)]))])];
case 6:
storage = _j.sent();
storage = _c.sent();
oldCookieName = getOldCookieName(apiKey);
return [4 /*yield*/, storage.getRaw(oldCookieName)];
case 7:
cookies = _j.sent();
case 2:
cookies = _c.sent();
if (!cookies) {

@@ -40,9 +21,9 @@ return [2 /*return*/, {

}
if (!((_h = options === null || options === void 0 ? void 0 : options.cookieUpgrade) !== null && _h !== void 0 ? _h : getDefaultConfig().cookieUpgrade)) return [3 /*break*/, 9];
if (!((_b = options === null || options === void 0 ? void 0 : options.cookieUpgrade) !== null && _b !== void 0 ? _b : getDefaultConfig().cookieUpgrade)) return [3 /*break*/, 4];
return [4 /*yield*/, storage.remove(oldCookieName)];
case 8:
_j.sent();
_j.label = 9;
case 9:
_e = __read(cookies.split('.'), 5), deviceId = _e[0], userId = _e[1], optOut = _e[2], sessionId = _e[3], lastEventTime = _e[4];
case 3:
_c.sent();
_c.label = 4;
case 4:
_a = __read(cookies.split('.'), 5), deviceId = _a[0], userId = _a[1], optOut = _a[2], sessionId = _a[3], lastEventTime = _a[4];
return [2 /*return*/, {

@@ -49,0 +30,0 @@ deviceId: deviceId,

@@ -1,2 +0,2 @@

export declare const VERSION = "1.9.0-beta.1";
export declare const VERSION = "1.9.0-beta.2";
//# sourceMappingURL=version.d.ts.map

@@ -1,2 +0,2 @@

export var VERSION = '1.9.0-beta.1';
export var VERSION = '1.9.0-beta.2';
//# sourceMappingURL=version.js.map

@@ -5,2 +5,3 @@ import { AmplitudeCore } from '@amplitude/analytics-core';

config: BrowserConfig;
previousSessionDeviceId: string | undefined;
previousSessionUserId: string | undefined;

@@ -7,0 +8,0 @@ init(apiKey?: string, userId?: string, options?: BrowserOptions): import("@amplitude/analytics-types").AmplitudeReturn<void>;

import { BrowserOptions, UserSession } from '@amplitude/analytics-types';
export declare const parseOldCookies: (apiKey: string, options?: BrowserOptions) => Promise<UserSession>;
export declare const parseLegacyCookies: (apiKey: string, options?: BrowserOptions) => Promise<UserSession>;
export declare const parseTime: (num: string) => number | undefined;
export declare const decode: (value?: string) => string | undefined;
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

export declare const VERSION = "1.9.0-beta.1";
export declare const VERSION = "1.9.0-beta.2";
//# sourceMappingURL=version.d.ts.map
{
"name": "@amplitude/analytics-browser",
"version": "1.9.0-beta.1",
"version": "1.9.0-beta.2",
"description": "Official Amplitude SDK for Web",

@@ -49,4 +49,4 @@ "keywords": [

"@amplitude/analytics-types": "^0.17.0-beta.0",
"@amplitude/plugin-page-view-tracking-browser": "^0.6.0-beta.1",
"@amplitude/plugin-web-attribution-browser": "^0.6.0-beta.1",
"@amplitude/plugin-page-view-tracking-browser": "^0.6.0-beta.2",
"@amplitude/plugin-web-attribution-browser": "^0.6.0-beta.2",
"@amplitude/ua-parser-js": "^0.7.31",

@@ -71,3 +71,3 @@ "tslib": "^2.4.1"

],
"gitHead": "1c7e1613e485026105fb138cab17fed924da6e92"
"gitHead": "aa29547d7c880f9bc82abbf62a287850abe22503"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc