keystone-design-bootstrap 1.0.70 → 1.0.71
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
CHANGED
package/src/lib/server-api.ts
CHANGED
|
@@ -81,6 +81,12 @@ export function getMetaPixelId(adsConfig: { meta_pixel_id?: string } | null | un
|
|
|
81
81
|
export type AnalyticsConfig = {
|
|
82
82
|
/** PostHog project API key — platform-wide, from POSTHOG_API_KEY env var on the Rails server. */
|
|
83
83
|
posthog_api_key?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Environment identifier from KEYSTONE_ENV on the Rails server (e.g. "production", "staging",
|
|
86
|
+
* "development"). Registered as a PostHog super property on every event so the sync job can
|
|
87
|
+
* filter by environment and avoid cross-environment data contamination.
|
|
88
|
+
*/
|
|
89
|
+
environment?: string;
|
|
84
90
|
};
|
|
85
91
|
|
|
86
92
|
/** Analytics config for customer sites. Returns platform-wide analytics keys (e.g. PostHog). */
|
|
@@ -96,6 +102,11 @@ export function getPostHogApiKey(analyticsConfig: AnalyticsConfig | null | undef
|
|
|
96
102
|
return str !== '' && str !== 'null' ? str : null;
|
|
97
103
|
}
|
|
98
104
|
|
|
105
|
+
/** Extract environment string from analytics config for use with <PostHogProvider environment={...} />. */
|
|
106
|
+
export function getKeystoneEnvironment(analyticsConfig: AnalyticsConfig | null | undefined): string {
|
|
107
|
+
return analyticsConfig?.environment?.trim() || 'development';
|
|
108
|
+
}
|
|
109
|
+
|
|
99
110
|
export async function getServices(): Promise<Service[] | null> {
|
|
100
111
|
return serverFetch<Service[]>('/public/services', defaultOptions);
|
|
101
112
|
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
getMetaPixelId,
|
|
19
19
|
getAnalyticsConfig,
|
|
20
20
|
getPostHogApiKey,
|
|
21
|
+
getKeystoneEnvironment,
|
|
21
22
|
} from '../../lib/server-api';
|
|
22
23
|
|
|
23
24
|
import type { CompanyInformation, Location, NavItem, Service, SiteConfig } from '../../types';
|
|
@@ -149,6 +150,7 @@ export async function KeystoneRootLayout(props: {
|
|
|
149
150
|
|
|
150
151
|
const metaPixelId = getMetaPixelId(adsConfig);
|
|
151
152
|
const posthogApiKey = getPostHogApiKey(analyticsConfig);
|
|
153
|
+
const keystoneEnvironment = getKeystoneEnvironment(analyticsConfig);
|
|
152
154
|
|
|
153
155
|
const services = Array.isArray(servicesData) ? servicesData : [];
|
|
154
156
|
const locations = Array.isArray(locationsData) ? locationsData : [];
|
|
@@ -226,6 +228,7 @@ export async function KeystoneRootLayout(props: {
|
|
|
226
228
|
apiHost={posthogHost}
|
|
227
229
|
accountId={accountId}
|
|
228
230
|
accountName={accountName}
|
|
231
|
+
environment={keystoneEnvironment}
|
|
229
232
|
>
|
|
230
233
|
<KeystoneAnalyticsTracker bookingUrl={bookingHref} />
|
|
231
234
|
{bodyContent}
|
|
@@ -14,6 +14,12 @@ export type PostHogProviderProps = {
|
|
|
14
14
|
accountId?: number;
|
|
15
15
|
/** Keystone account name (company_name) — attached to every event as a super property. */
|
|
16
16
|
accountName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Environment identifier from KEYSTONE_ENV on the Rails server (e.g. "production", "staging",
|
|
19
|
+
* "development"). Registered as a super property so events can be filtered by environment
|
|
20
|
+
* in PostHog and the sync job only imports data for the matching environment.
|
|
21
|
+
*/
|
|
22
|
+
environment?: string;
|
|
17
23
|
children: React.ReactNode;
|
|
18
24
|
};
|
|
19
25
|
|
|
@@ -102,7 +108,7 @@ function PostHogPageviewTracker() {
|
|
|
102
108
|
* Mount once in the root layout body. One project key covers all customer
|
|
103
109
|
* sites — filter by account_name or site_domain in the PostHog dashboard.
|
|
104
110
|
*/
|
|
105
|
-
export function PostHogProvider({ apiKey, apiHost, accountId, accountName, children }: PostHogProviderProps) {
|
|
111
|
+
export function PostHogProvider({ apiKey, apiHost, accountId, accountName, environment, children }: PostHogProviderProps) {
|
|
106
112
|
useEffect(() => {
|
|
107
113
|
posthog.init(apiKey, {
|
|
108
114
|
api_host: apiHost ?? DEFAULT_HOST,
|
|
@@ -113,9 +119,10 @@ export function PostHogProvider({ apiKey, apiHost, accountId, accountName, child
|
|
|
113
119
|
posthog.register({
|
|
114
120
|
...(accountId !== undefined && { account_id: accountId }),
|
|
115
121
|
...(accountName && { account_name: accountName }),
|
|
122
|
+
...(environment && { environment }),
|
|
116
123
|
site_domain: window.location.hostname,
|
|
117
124
|
});
|
|
118
|
-
}, [apiKey, apiHost, accountId, accountName]);
|
|
125
|
+
}, [apiKey, apiHost, accountId, accountName, environment]);
|
|
119
126
|
|
|
120
127
|
return (
|
|
121
128
|
<PHProvider client={posthog}>
|