Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/addon-catalog/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export function useAnalytics() {

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic event properties
function track(eventName: string, properties?: Record<string, any>) {
plausible(eventName, { props: properties });
posthog.capture(eventName, properties);
try {
plausible(eventName, { props: properties });
} catch (e) {
/* */
}
try {
posthog.capture(eventName, properties);
} catch (e) {
/* */
}
}

return track;
Expand Down
22 changes: 20 additions & 2 deletions apps/frontpage/app/event-log/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto from 'node:crypto';
import type { NextRequest } from 'next/server';
import postHogClient from '../../lib/posthog';

const sentryEnvelopeUrl = `https://o4507096816484352.ingest.sentry.io/api/4507096819892224/envelope/?sentry_key=${process.env.SENTRY_KEY ?? ''}&sentry_version=7`;

Expand Down Expand Up @@ -70,7 +71,7 @@ export async function POST(request: NextRequest) {
}

if (received.payload?.userAgent) {
requests.push(forwardToPlausible(received, headers));
requests.push(forwardToAnalytics(received, headers));
}

const responses = await Promise.allSettled(requests);
Expand All @@ -96,6 +97,7 @@ export async function POST(request: NextRequest) {

interface TelemetryEvent {
eventType: string;
sessionId: string;
context: {
storybookVersion?: string;
anonymousId: string;
Expand Down Expand Up @@ -215,7 +217,7 @@ async function forwardToSentry(received: TelemetryEvent) {
});
}

async function forwardToPlausible(received: TelemetryEvent, headers: Headers) {
async function forwardToAnalytics(received: TelemetryEvent, headers: Headers) {
const ip = headers.get('x-forwarded-for') ?? headers.get('x-real-ip');
const { userAgent, step, isNewUser, timeSinceInit } = received.payload ?? {};

Expand Down Expand Up @@ -245,6 +247,22 @@ async function forwardToPlausible(received: TelemetryEvent, headers: Headers) {
storybookVersion,
};

try {
const posthog = postHogClient();
posthog.capture({
distinctId: received.sessionId,
event: name,
properties: {
...props,
$ip: ip ?? '127.0.0.1',
$user_agent: userAgent ?? 'unknown',
$process_person_profile: false,
},
});
} catch (e) {
/* */
}

return fetch('https://plausible.io/api/event', {
method: 'POST',
headers: {
Expand Down
12 changes: 10 additions & 2 deletions apps/frontpage/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export function useAnalytics() {

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic event properties
function track(eventName: string, properties?: Record<string, any>) {
plausible(eventName, { props: properties });
posthog.capture(eventName, properties);
try {
plausible(eventName, { props: properties });
} catch (e) {
/* */
}
try {
posthog.capture(eventName, properties);
} catch (e) {
/* */
}
}

return track;
Expand Down
12 changes: 10 additions & 2 deletions packages/ui/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export function useAnalytics() {

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic event properties
function track(eventName: string, properties?: Record<string, any>) {
plausible(eventName, { props: properties });
posthog.capture(eventName, properties);
try {
plausible(eventName, { props: properties });
} catch (e) {
/* */
}
try {
posthog.capture(eventName, properties);
} catch (e) {
/* */
}
}

return track;
Expand Down