@funnelsgrove/analytics 0.1.26 → 0.1.27
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.
|
@@ -7,7 +7,7 @@ const DEFAULT_OPTIONS = {
|
|
|
7
7
|
batchSize: 20,
|
|
8
8
|
flushIntervalMs: 1500,
|
|
9
9
|
};
|
|
10
|
-
const
|
|
10
|
+
const POSTHOG_BATCH_ENDPOINT = '/batch/';
|
|
11
11
|
const DEFAULT_FUNNEL_DOMAIN_SIGNAL = 'funnelsgrove';
|
|
12
12
|
const normalizeEnvironment = (value) => {
|
|
13
13
|
if (typeof value !== 'string') {
|
|
@@ -96,13 +96,6 @@ const toDurationMs = (startedAt, endedAt) => {
|
|
|
96
96
|
}
|
|
97
97
|
return endedMs - startedMs;
|
|
98
98
|
};
|
|
99
|
-
const toPostHogOffset = (occurredAt) => {
|
|
100
|
-
const occurredMs = new Date(occurredAt).getTime();
|
|
101
|
-
if (!Number.isFinite(occurredMs)) {
|
|
102
|
-
return 0;
|
|
103
|
-
}
|
|
104
|
-
return Math.max(0, Date.now() - occurredMs);
|
|
105
|
-
};
|
|
106
99
|
const buildEventId = () => {
|
|
107
100
|
var _a;
|
|
108
101
|
if (canUseDom() && typeof ((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === 'function') {
|
|
@@ -556,14 +549,17 @@ export class PublicAnalyticsSdkService {
|
|
|
556
549
|
const eventEnvironment = event.environment || analyticsEnvironment;
|
|
557
550
|
return {
|
|
558
551
|
event: toPostHogEventName(event.eventType),
|
|
559
|
-
properties: buildDefinedRecord(Object.assign(Object.assign({
|
|
552
|
+
properties: buildDefinedRecord(Object.assign(Object.assign({ distinct_id: event.userId || this.ensureUserId(), $groups: {
|
|
560
553
|
project: PROJECT_ID,
|
|
561
554
|
}, $insert_id: event.eventId, project_id: PROJECT_ID, funnel_id: FUNNEL_ID || undefined, funnel_version_id: FUNNEL_VERSION_ID || undefined, environment: eventEnvironment, test: eventEnvironment === 'test' || undefined, step_id: event.stepId || undefined, step_name: event.stepName || undefined, step_type: event.stepType || undefined, started_at: event.startedAt || undefined, ended_at: event.endedAt || undefined, duration_ms: (_a = event.durationMs) !== null && _a !== void 0 ? _a : undefined, engagement_threshold_ms: (_b = event.engagementThresholdMs) !== null && _b !== void 0 ? _b : undefined, event_source: 'client' }, buildFeatureFlagProperties(event.featureFlags)), { selected: Object.keys(event.selected).length > 0 ? event.selected : undefined, payload: Object.keys(event.payload).length > 0 ? event.payload : undefined, context: Object.keys(event.context).length > 0 ? event.context : undefined, metadata: Object.keys(event.metadata).length > 0 ? event.metadata : undefined })),
|
|
562
|
-
|
|
555
|
+
timestamp: event.occurredAt,
|
|
563
556
|
};
|
|
564
557
|
});
|
|
565
|
-
const payload = JSON.stringify(
|
|
566
|
-
|
|
558
|
+
const payload = JSON.stringify({
|
|
559
|
+
api_key: POSTHOG_PROJECT_API_KEY,
|
|
560
|
+
batch,
|
|
561
|
+
});
|
|
562
|
+
const endpoint = `${POSTHOG_API_HOST}${POSTHOG_BATCH_ENDPOINT}`;
|
|
567
563
|
if (canUseDom() && typeof navigator.sendBeacon === 'function') {
|
|
568
564
|
const accepted = navigator.sendBeacon(endpoint, new Blob([payload], { type: 'application/json' }));
|
|
569
565
|
if (accepted) {
|