@funnelsgrove/analytics 0.17.0 → 0.19.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.
|
@@ -7,6 +7,8 @@ type AnalyticsEvent = {
|
|
|
7
7
|
/** Maps the same normalized event used by PostHog, preserving its identity. */
|
|
8
8
|
export declare class AmplitudeDelivery {
|
|
9
9
|
private readonly delivery;
|
|
10
|
+
/** Public names from NEXT_PUBLIC_AMPLITUDE_EXCLUDED_EVENTS; PostHog still receives these events. */
|
|
11
|
+
private readonly excludedEvents;
|
|
10
12
|
static create(options: Partial<BrowserDeliveryOptions>): AmplitudeDelivery | null;
|
|
11
13
|
private constructor();
|
|
12
14
|
enqueue(event: AnalyticsEvent): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toAmplitudeEvent } from './analytics-export.js';
|
|
1
|
+
import { toAmplitudeEvent, toPostHogEventName } from './analytics-export.js';
|
|
2
2
|
import { runtimeEnvConfig } from '@funnelsgrove/runtime/config/env.config';
|
|
3
3
|
import { BrowserEventDelivery } from './browser-event-delivery.js';
|
|
4
4
|
const ENDPOINTS = { us: 'https://api2.amplitude.com/2/httpapi', eu: 'https://api.eu.amplitude.com/2/httpapi' };
|
|
@@ -15,6 +15,9 @@ export class AmplitudeDelivery {
|
|
|
15
15
|
return new AmplitudeDelivery(options, runtimeEnvConfig.amplitudeRegion === 'eu' ? ENDPOINTS.eu : ENDPOINTS.us, key);
|
|
16
16
|
}
|
|
17
17
|
constructor(options, endpoint, key) {
|
|
18
|
+
/** Public names from NEXT_PUBLIC_AMPLITUDE_EXCLUDED_EVENTS; PostHog still receives these events. */
|
|
19
|
+
this.excludedEvents = new Set((runtimeEnvConfig.amplitudeExcludedEvents || '').split(',')
|
|
20
|
+
.map((name) => name.trim()).filter(Boolean).map(toPostHogEventName));
|
|
18
21
|
this.delivery = new BrowserEventDelivery(options, {
|
|
19
22
|
enabled: true, endpoint, batchPrefix: `{"api_key":${JSON.stringify(key)},"events":[`,
|
|
20
23
|
});
|
|
@@ -22,6 +25,8 @@ export class AmplitudeDelivery {
|
|
|
22
25
|
enqueue(event) {
|
|
23
26
|
if (event.properties.environment !== 'live' && runtimeEnvConfig.amplitudeIncludeTestEvents !== 'true')
|
|
24
27
|
return true;
|
|
28
|
+
if (this.excludedEvents.has(event.event))
|
|
29
|
+
return true;
|
|
25
30
|
try {
|
|
26
31
|
return this.delivery.enqueue(toAmplitudeEvent({
|
|
27
32
|
distinctId: String(event.properties.distinct_id), messageId: String(event.properties.$insert_id),
|
|
@@ -2,6 +2,8 @@ export declare const sanitizeAnalyticsUrl: (value: unknown, sensitiveKeys?: RegE
|
|
|
2
2
|
export declare const analyticsUrlSanitizerSource: string;
|
|
3
3
|
/** Snapshot before filtering so custom toJSON values cannot bypass the export policy. */
|
|
4
4
|
export declare const sanitizeAnalyticsExport: (value: unknown) => unknown;
|
|
5
|
+
/** Maps raw SDK lifecycle event types to the public event names sent to every destination. */
|
|
6
|
+
export declare const toPostHogEventName: (eventType: string) => string;
|
|
5
7
|
export type RudderstackTrackEvent = {
|
|
6
8
|
type: 'track';
|
|
7
9
|
event: string;
|
|
@@ -46,6 +46,21 @@ export const sanitizeAnalyticsExport = (value) => {
|
|
|
46
46
|
};
|
|
47
47
|
return project(JSON.parse(json), 0);
|
|
48
48
|
};
|
|
49
|
+
/** Maps raw SDK lifecycle event types to the public event names sent to every destination. */
|
|
50
|
+
export const toPostHogEventName = (eventType) => {
|
|
51
|
+
switch (eventType) {
|
|
52
|
+
case 'funnel_start':
|
|
53
|
+
return 'funnel_started';
|
|
54
|
+
case 'step_start':
|
|
55
|
+
return 'step_started';
|
|
56
|
+
case 'step_end':
|
|
57
|
+
return 'step_completed';
|
|
58
|
+
case 'step_exit':
|
|
59
|
+
return 'step_exited';
|
|
60
|
+
default:
|
|
61
|
+
return eventType;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
49
64
|
/** Provider-neutral normalized input shared by browser and server destinations. */
|
|
50
65
|
export const toRudderstackTrackEvent = (input) => {
|
|
51
66
|
const properties = Object.assign({}, input.properties);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RudderstackDelivery } from './rudderstack-delivery.js';
|
|
2
2
|
import { AmplitudeDelivery } from './amplitude-delivery.js';
|
|
3
|
+
import { toPostHogEventName } from './analytics-export.js';
|
|
3
4
|
import { PostHogDelivery } from './posthog-delivery.js';
|
|
4
5
|
import { FUNNEL_ANALYTICS_EVENT_CONTRACTS, funnelSdkService, getPaywallUser, readAdTrackerClickIdProperties, readCrossFunnelEventProperties, FUNNEL_STEP_CONTRACTS, } from '@funnelsgrove/runtime';
|
|
5
6
|
import { APP_DEALS_API_BASE_URL, FUNNEL_ID, FUNNEL_VERSION_ID, getFunnelSdkPublishableKey, PROJECT_ID, } from './runtime-api.config.js';
|
|
@@ -111,20 +112,6 @@ const buildEventId = () => {
|
|
|
111
112
|
}
|
|
112
113
|
return `sdk_evt_${Date.now()}_${Math.random().toString(16).slice(2, 10)}`;
|
|
113
114
|
};
|
|
114
|
-
const toPostHogEventName = (eventType) => {
|
|
115
|
-
switch (eventType) {
|
|
116
|
-
case 'funnel_start':
|
|
117
|
-
return 'funnel_started';
|
|
118
|
-
case 'step_start':
|
|
119
|
-
return 'step_started';
|
|
120
|
-
case 'step_end':
|
|
121
|
-
return 'step_completed';
|
|
122
|
-
case 'step_exit':
|
|
123
|
-
return 'step_exited';
|
|
124
|
-
default:
|
|
125
|
-
return eventType;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
115
|
const buildDefinedRecord = (value) => {
|
|
129
116
|
return Object.fromEntries(Object.entries(value).filter(([, candidate]) => candidate !== undefined));
|
|
130
117
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/analytics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"@types/node": "^20",
|
|
46
46
|
"typescript": "^5",
|
|
47
47
|
"vitest": "^3.2.4",
|
|
48
|
-
"@funnelsgrove/runtime": "0.
|
|
48
|
+
"@funnelsgrove/runtime": "0.37.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@funnelsgrove/runtime": "^0.
|
|
51
|
+
"@funnelsgrove/runtime": "^0.37.0"
|
|
52
52
|
}
|
|
53
53
|
}
|