@reservamos/browser-analytics 1.1.2-alpha.0 → 1.1.3-alpha.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/CHANGELOG.md +5 -0
- package/README.md +35 -0
- package/dist/browser-analytics.cjs +3 -3
- package/dist/browser-analytics.cjs.map +1 -1
- package/dist/browser-analytics.d.ts +7 -0
- package/dist/browser-analytics.esm.js +50 -9
- package/dist/browser-analytics.esm.js.map +1 -1
- package/dist/browser-analytics.iife.js +3 -3
- package/dist/browser-analytics.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/events/identify/identify.test.ts +102 -0
- package/src/events/identify/identify.ts +3 -0
- package/src/init.ts +4 -0
- package/src/services/config.test.ts +39 -0
- package/src/services/config.ts +16 -1
- package/src/services/geolocation.test.ts +8 -0
- package/src/services/geolocation.ts +29 -0
- package/src/services/validator/validator.test.ts +34 -1
- package/src/services/validator/validator.ts +5 -0
- package/src/track.ts +4 -0
|
@@ -1243,6 +1243,11 @@ declare const InitConfigSchema: z.ZodObject<{
|
|
|
1243
1243
|
* Optional proxy URL for identify requests.
|
|
1244
1244
|
*/
|
|
1245
1245
|
identifyProxyUrl: z.ZodOptional<z.ZodString>;
|
|
1246
|
+
/**
|
|
1247
|
+
* Optional client platform identifier sent as the `x-app-name` header on Datalake
|
|
1248
|
+
* identify and anonymous-profile requests.
|
|
1249
|
+
*/
|
|
1250
|
+
appName: z.ZodOptional<z.ZodString>;
|
|
1246
1251
|
}, "strip", z.ZodTypeAny, {
|
|
1247
1252
|
mixpanelToken: string;
|
|
1248
1253
|
identificationKey: string;
|
|
@@ -1250,6 +1255,7 @@ declare const InitConfigSchema: z.ZodObject<{
|
|
|
1250
1255
|
isSandbox?: boolean | undefined;
|
|
1251
1256
|
mixpanelProxyUrl?: string | undefined;
|
|
1252
1257
|
identifyProxyUrl?: string | undefined;
|
|
1258
|
+
appName?: string | undefined;
|
|
1253
1259
|
}, {
|
|
1254
1260
|
mixpanelToken: string;
|
|
1255
1261
|
identificationKey: string;
|
|
@@ -1257,6 +1263,7 @@ declare const InitConfigSchema: z.ZodObject<{
|
|
|
1257
1263
|
isSandbox?: boolean | undefined;
|
|
1258
1264
|
mixpanelProxyUrl?: string | undefined;
|
|
1259
1265
|
identifyProxyUrl?: string | undefined;
|
|
1266
|
+
appName?: string | undefined;
|
|
1260
1267
|
}>;
|
|
1261
1268
|
/**
|
|
1262
1269
|
* Configuration object for initializing the tracking library.
|
|
@@ -4963,6 +4963,7 @@ const f = {
|
|
|
4963
4963
|
profiles: s
|
|
4964
4964
|
};
|
|
4965
4965
|
let environment;
|
|
4966
|
+
let appName;
|
|
4966
4967
|
const origin = window.location.origin;
|
|
4967
4968
|
const coreAPIConfig = {
|
|
4968
4969
|
sandbox: {
|
|
@@ -4983,16 +4984,27 @@ const coreAPIConfig = {
|
|
|
4983
4984
|
function setEnvironment(env) {
|
|
4984
4985
|
environment = env;
|
|
4985
4986
|
}
|
|
4987
|
+
function setAppName(name) {
|
|
4988
|
+
appName = name;
|
|
4989
|
+
}
|
|
4986
4990
|
function getCoreAPIConfig() {
|
|
4987
4991
|
if (!environment) {
|
|
4988
4992
|
throw new Error(
|
|
4989
4993
|
"Unable to get core API config, environment not set. Use configService.setEnvironment(environment) to set the environment."
|
|
4990
4994
|
);
|
|
4991
4995
|
}
|
|
4992
|
-
|
|
4996
|
+
const config = coreAPIConfig[environment];
|
|
4997
|
+
return {
|
|
4998
|
+
...config,
|
|
4999
|
+
defaultHeaders: {
|
|
5000
|
+
...config.defaultHeaders,
|
|
5001
|
+
...appName ? { "x-app-name": appName } : {}
|
|
5002
|
+
}
|
|
5003
|
+
};
|
|
4993
5004
|
}
|
|
4994
5005
|
const configService = {
|
|
4995
5006
|
setEnvironment,
|
|
5007
|
+
setAppName,
|
|
4996
5008
|
getCoreAPIConfig
|
|
4997
5009
|
};
|
|
4998
5010
|
var NodeType;
|
|
@@ -13395,7 +13407,7 @@ function loadNoop(_src, onload) {
|
|
|
13395
13407
|
onload();
|
|
13396
13408
|
}
|
|
13397
13409
|
var mixpanel = init_as_module(loadNoop);
|
|
13398
|
-
const version = "1.1.
|
|
13410
|
+
const version = "1.1.3-alpha.0";
|
|
13399
13411
|
const MIXPANEL_DISTINCT_ID_CACHE_KEY = "mp_distinct_id";
|
|
13400
13412
|
const EVENT_SOURCE_SUPER_PROPERTY = {
|
|
13401
13413
|
"Event Source": "sdk"
|
|
@@ -13738,7 +13750,12 @@ const InitConfigSchema = z.object({
|
|
|
13738
13750
|
/**
|
|
13739
13751
|
* Optional proxy URL for identify requests.
|
|
13740
13752
|
*/
|
|
13741
|
-
identifyProxyUrl: z.string().optional()
|
|
13753
|
+
identifyProxyUrl: z.string().optional(),
|
|
13754
|
+
/**
|
|
13755
|
+
* Optional client platform identifier sent as the `x-app-name` header on Datalake
|
|
13756
|
+
* identify and anonymous-profile requests.
|
|
13757
|
+
*/
|
|
13758
|
+
appName: z.string().min(1, "App name cannot be empty").optional()
|
|
13742
13759
|
});
|
|
13743
13760
|
const SchemaErrorFormatter = (error) => {
|
|
13744
13761
|
return error.issues.map((issue) => {
|
|
@@ -13829,7 +13846,8 @@ async function init$1(config) {
|
|
|
13829
13846
|
identificationKey,
|
|
13830
13847
|
isSandbox = false,
|
|
13831
13848
|
mixpanelProxyUrl,
|
|
13832
|
-
identifyProxyUrl
|
|
13849
|
+
identifyProxyUrl,
|
|
13850
|
+
appName: appName2
|
|
13833
13851
|
} = config;
|
|
13834
13852
|
await mixpanelService.init(mixpanelToken, debug, mixpanelProxyUrl);
|
|
13835
13853
|
try {
|
|
@@ -13842,6 +13860,9 @@ async function init$1(config) {
|
|
|
13842
13860
|
}
|
|
13843
13861
|
await geolocationService.init();
|
|
13844
13862
|
configService.setEnvironment(isSandbox ? "sandbox" : "prod");
|
|
13863
|
+
if (appName2) {
|
|
13864
|
+
configService.setAppName(appName2);
|
|
13865
|
+
}
|
|
13845
13866
|
f.setConfig(configService.getCoreAPIConfig());
|
|
13846
13867
|
onLoaded();
|
|
13847
13868
|
}
|
|
@@ -13849,6 +13870,7 @@ function isTrackerReady() {
|
|
|
13849
13870
|
return mixpanelService.isReady();
|
|
13850
13871
|
}
|
|
13851
13872
|
let currentCoordinates = null;
|
|
13873
|
+
let currentSource = null;
|
|
13852
13874
|
const GEOLOCATION_PERMISSION_KEY = "geolocationPermissionTimestamp";
|
|
13853
13875
|
const GEOLOCATION_CACHE_KEY = "geolocationCache";
|
|
13854
13876
|
const GEOLOCATION_TRACK_EVENT = "Geolocation Requested";
|
|
@@ -13915,6 +13937,7 @@ function restoreCoordinatesFromStorage() {
|
|
|
13915
13937
|
const cache = loadCoordinatesFromStorage();
|
|
13916
13938
|
if (cache) {
|
|
13917
13939
|
currentCoordinates = { lat: cache.lat, long: cache.long };
|
|
13940
|
+
currentSource = "browser";
|
|
13918
13941
|
}
|
|
13919
13942
|
}
|
|
13920
13943
|
function isPermissionTimestampValid(lastPermissionTimestamp) {
|
|
@@ -13951,6 +13974,9 @@ function buildGeolocationEventProperties(data) {
|
|
|
13951
13974
|
properties.latitude = data.lat;
|
|
13952
13975
|
properties.longitude = data.long;
|
|
13953
13976
|
}
|
|
13977
|
+
if (data.source !== void 0) {
|
|
13978
|
+
properties.geolocation_source = data.source;
|
|
13979
|
+
}
|
|
13954
13980
|
return properties;
|
|
13955
13981
|
}
|
|
13956
13982
|
function buildGeolocationProfileProperties(data) {
|
|
@@ -13962,6 +13988,9 @@ function buildGeolocationProfileProperties(data) {
|
|
|
13962
13988
|
properties.latitude = data.lat;
|
|
13963
13989
|
properties.longitude = data.long;
|
|
13964
13990
|
}
|
|
13991
|
+
if (data.source !== void 0) {
|
|
13992
|
+
properties.geolocation_source = data.source;
|
|
13993
|
+
}
|
|
13965
13994
|
return properties;
|
|
13966
13995
|
}
|
|
13967
13996
|
function syncGeolocationToMixpanel(data) {
|
|
@@ -13987,7 +14016,8 @@ function init() {
|
|
|
13987
14016
|
updatedAt: cache.updatedAt,
|
|
13988
14017
|
lat: cache.lat,
|
|
13989
14018
|
long: cache.long,
|
|
13990
|
-
accuracy: cache.accuracy
|
|
14019
|
+
accuracy: cache.accuracy,
|
|
14020
|
+
source: "browser"
|
|
13991
14021
|
});
|
|
13992
14022
|
resolve(currentCoordinates);
|
|
13993
14023
|
return;
|
|
@@ -14004,6 +14034,7 @@ function init() {
|
|
|
14004
14034
|
(geolocation) => {
|
|
14005
14035
|
const { latitude: lat, longitude: long, accuracy } = geolocation.coords;
|
|
14006
14036
|
currentCoordinates = { lat, long };
|
|
14037
|
+
currentSource = "browser";
|
|
14007
14038
|
saveCoordinatesToStorage(currentCoordinates, updatedAt, accuracy);
|
|
14008
14039
|
updatePermissionTimestamp(now);
|
|
14009
14040
|
syncGeolocationToMixpanel({
|
|
@@ -14011,7 +14042,8 @@ function init() {
|
|
|
14011
14042
|
updatedAt,
|
|
14012
14043
|
lat,
|
|
14013
14044
|
long,
|
|
14014
|
-
accuracy
|
|
14045
|
+
accuracy,
|
|
14046
|
+
source: "browser"
|
|
14015
14047
|
});
|
|
14016
14048
|
resolve(currentCoordinates);
|
|
14017
14049
|
},
|
|
@@ -14031,9 +14063,13 @@ function init() {
|
|
|
14031
14063
|
function getCoordinates() {
|
|
14032
14064
|
return currentCoordinates;
|
|
14033
14065
|
}
|
|
14066
|
+
function getGeolocationSource() {
|
|
14067
|
+
return currentSource;
|
|
14068
|
+
}
|
|
14034
14069
|
const geolocationService = {
|
|
14035
14070
|
init,
|
|
14036
|
-
getCoordinates
|
|
14071
|
+
getCoordinates,
|
|
14072
|
+
getGeolocationSource
|
|
14037
14073
|
};
|
|
14038
14074
|
const FP_TRIGGER_EVENTS = ["Search", "View Results"];
|
|
14039
14075
|
const EXTRA_UTM_FIELDS = {
|
|
@@ -14104,10 +14140,14 @@ async function trackEvent(eventName, eventProperties, meta = {}) {
|
|
|
14104
14140
|
const fingerprint = await fingerprintService.getFingerprint(cacheOnly);
|
|
14105
14141
|
const defaultCoordinates = {};
|
|
14106
14142
|
const coordinates = geolocationService.getCoordinates();
|
|
14143
|
+
const geolocationSource = geolocationService.getGeolocationSource();
|
|
14107
14144
|
if (coordinates) {
|
|
14108
14145
|
defaultCoordinates.latitude = coordinates.lat;
|
|
14109
14146
|
defaultCoordinates.longitude = coordinates.long;
|
|
14110
14147
|
}
|
|
14148
|
+
if (geolocationSource) {
|
|
14149
|
+
defaultCoordinates.geolocation_source = geolocationSource;
|
|
14150
|
+
}
|
|
14111
14151
|
const defaultProperties = {
|
|
14112
14152
|
"User Fingerprint": fingerprint
|
|
14113
14153
|
};
|
|
@@ -14244,7 +14284,7 @@ function mapProperties(properties) {
|
|
|
14244
14284
|
return { ...parsedProperties, ...additionalProperties };
|
|
14245
14285
|
}
|
|
14246
14286
|
const identifyWithLocation = async (userId, properties) => {
|
|
14247
|
-
var _a, _b;
|
|
14287
|
+
var _a, _b, _c;
|
|
14248
14288
|
try {
|
|
14249
14289
|
const coordinates = geolocationService.getCoordinates();
|
|
14250
14290
|
if (!coordinates) {
|
|
@@ -14264,7 +14304,8 @@ const identifyWithLocation = async (userId, properties) => {
|
|
|
14264
14304
|
headers: {
|
|
14265
14305
|
"Content-Type": "application/json",
|
|
14266
14306
|
"Authorization": ((_a = coreApiConfig.defaultHeaders) == null ? void 0 : _a.Authorization) || "",
|
|
14267
|
-
"Origin": ((_b = coreApiConfig.defaultHeaders) == null ? void 0 : _b.Origin) || ""
|
|
14307
|
+
"Origin": ((_b = coreApiConfig.defaultHeaders) == null ? void 0 : _b.Origin) || "",
|
|
14308
|
+
...((_c = coreApiConfig.defaultHeaders) == null ? void 0 : _c["x-app-name"]) ? { "x-app-name": coreApiConfig.defaultHeaders["x-app-name"] } : {}
|
|
14268
14309
|
},
|
|
14269
14310
|
body: JSON.stringify({
|
|
14270
14311
|
profile_params: {
|