@statsig/web-analytics 0.0.1-beta.23 → 0.0.1-beta.25
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/package.json +3 -3
- package/src/AutoCapture.d.ts +1 -2
- package/src/AutoCapture.js +2 -3
- package/src/index.d.ts +1 -2
- package/src/index.js +2 -34
- package/src/WebAnalytics.d.ts +0 -5
- package/src/WebAnalytics.js +0 -25
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/web-analytics",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.25",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
6
|
-
"@statsig/js-client": "0.0.1-beta.
|
|
5
|
+
"@statsig/client-core": "0.0.1-beta.25",
|
|
6
|
+
"@statsig/js-client": "0.0.1-beta.25"
|
|
7
7
|
},
|
|
8
8
|
"jsdelivr": "./build/statsig-web-analytics.min.js",
|
|
9
9
|
"type": "commonjs",
|
package/src/AutoCapture.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { StatsigClient } from '@statsig/js-client';
|
|
2
2
|
export declare class AutoCapture {
|
|
3
|
-
private _sdkKey;
|
|
4
3
|
private _client;
|
|
5
4
|
private _startTime;
|
|
6
5
|
private _deepestScroll;
|
|
7
|
-
constructor(
|
|
6
|
+
constructor(_client: StatsigClient);
|
|
8
7
|
private _addEventHandlers;
|
|
9
8
|
private _autoLogEvent;
|
|
10
9
|
private _initialize;
|
package/src/AutoCapture.js
CHANGED
|
@@ -4,8 +4,7 @@ exports.AutoCapture = void 0;
|
|
|
4
4
|
const client_core_1 = require("@statsig/client-core");
|
|
5
5
|
const Utils_1 = require("./Utils");
|
|
6
6
|
class AutoCapture {
|
|
7
|
-
constructor(
|
|
8
|
-
this._sdkKey = _sdkKey;
|
|
7
|
+
constructor(_client) {
|
|
9
8
|
this._client = _client;
|
|
10
9
|
this._startTime = Date.now();
|
|
11
10
|
this._deepestScroll = 0;
|
|
@@ -124,7 +123,7 @@ class AutoCapture {
|
|
|
124
123
|
const event = {
|
|
125
124
|
eventName: `auto_capture::${name}`,
|
|
126
125
|
value,
|
|
127
|
-
metadata: Object.assign({ sessionId: (0, Utils_1.getWebSessionId)(this.
|
|
126
|
+
metadata: Object.assign({ sessionId: (0, Utils_1.getWebSessionId)(this._client.getContext().sdkKey), page_url: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.href) || '' }, metadata),
|
|
128
127
|
};
|
|
129
128
|
this._client.logEvent(event);
|
|
130
129
|
client_core_1.Log.debug('Enqueued Event', event);
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,39 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AutoCapture =
|
|
4
|
-
const client_core_1 = require("@statsig/client-core");
|
|
3
|
+
exports.AutoCapture = void 0;
|
|
5
4
|
const AutoCapture_1 = require("./AutoCapture");
|
|
6
5
|
Object.defineProperty(exports, "AutoCapture", { enumerable: true, get: function () { return AutoCapture_1.AutoCapture; } });
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "WebAnalytics", { enumerable: true, get: function () { return WebAnalytics_1.WebAnalytics; } });
|
|
9
|
-
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { WebAnalytics: WebAnalytics_1.WebAnalytics,
|
|
10
|
-
AutoCapture: AutoCapture_1.AutoCapture });
|
|
6
|
+
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { AutoCapture: AutoCapture_1.AutoCapture });
|
|
11
7
|
exports.default = __STATSIG__;
|
|
12
|
-
function _attemptAutoInit() {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
if (typeof window === 'undefined' ||
|
|
15
|
-
typeof document === 'undefined' ||
|
|
16
|
-
!document.currentScript) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const srcUrl = document.currentScript.getAttribute('src');
|
|
20
|
-
const baseUrl = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.href;
|
|
21
|
-
if (!srcUrl || !baseUrl) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
const url = new URL(srcUrl, baseUrl);
|
|
26
|
-
const params = url.searchParams;
|
|
27
|
-
const sdkKey = (_b = params.get('sdkkey')) !== null && _b !== void 0 ? _b : params.get('sdkKey');
|
|
28
|
-
if (sdkKey) {
|
|
29
|
-
WebAnalytics_1.WebAnalytics.autoInit(sdkKey);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
client_core_1.Log.error('Statsig Web AutoCapture: No SDK key provided');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
client_core_1.Log.error('Statsig Web AutoCapture: Invalid source URL');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
_attemptAutoInit();
|
package/src/WebAnalytics.d.ts
DELETED
package/src/WebAnalytics.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebAnalytics = void 0;
|
|
4
|
-
const client_core_1 = require("@statsig/client-core");
|
|
5
|
-
const js_client_1 = require("@statsig/js-client");
|
|
6
|
-
const AutoCapture_1 = require("./AutoCapture");
|
|
7
|
-
class WebAnalytics {
|
|
8
|
-
static autoInit(sdkKey) {
|
|
9
|
-
var _a;
|
|
10
|
-
const current = (_a = __STATSIG__ === null || __STATSIG__ === void 0 ? void 0 : __STATSIG__.instances) === null || _a === void 0 ? void 0 : _a[sdkKey];
|
|
11
|
-
if (current instanceof js_client_1.StatsigClient) {
|
|
12
|
-
this._client = current;
|
|
13
|
-
}
|
|
14
|
-
if (!this._client) {
|
|
15
|
-
this._client = new js_client_1.StatsigClient(sdkKey, {
|
|
16
|
-
userID: `web-analytics-user::${(0, client_core_1.getUUID)()}`,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
this._capture = new AutoCapture_1.AutoCapture(sdkKey, this._client);
|
|
20
|
-
this._client.initializeSync();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.WebAnalytics = WebAnalytics;
|
|
24
|
-
WebAnalytics._capture = null;
|
|
25
|
-
WebAnalytics._client = null;
|