PostHog / PostHog/posthog

Events from Production not being tracked in posthog

Open
#28,537 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
39.9k
Forks
3.4k
Avg merge
7h 27m
Merged PRs (30d)
222

Description

Bug Description

Bug description

Hi, I have implemented posthog on multiple next js project never came accross this issue,

The events get tracked from localhost, but not from production, the error on browser console in production is this -

Attachment "productionPostHogIssues.PNG": https://us.posthog.com/uploaded_media/0194f4b3-ab13-0000-205a-a02c0510f640

Attachment "productionPostHogIssues.PNG": https://us.posthog.com/uploaded_media/0194f4b3-af8a-0000-2eb1-7e25dac67c56

'use client';

import { Elements } from '@stripe/react-stripe-js';
import { loadStripe } from '@stripe/stripe-js';
import { QueryClientProvider } from '@tanstack/react-query';
import { NuqsAdapter } from 'nuqs/adapters/next/app';
import posthog from 'posthog-js';
import { PostHogProvider } from 'posthog-js/react';
import { useEffect } from 'react';

import { TooltipProvider } from '@/components/ui/tooltip';
import config from '@/config';
import { getQueryClient } from '@/lib/query-client';

const stripePromise = loadStripe(config.stripe.publishableKey);

export default function Providers({ children }: { children: React.ReactNode }) {
const queryClient = getQueryClient();

useEffect(() => {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY as string, {
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well
});
}, []);

return (
<PostHogProvider client={posthog}>
<NuqsAdapter>
<Elements stripe={stripePromise}>
<QueryClientProvider client={queryClient}>
<TooltipProvider>{children}</TooltipProvider>
</QueryClientProvider>
</Elements>
</NuqsAdapter>
</PostHogProvider>
);
}

Please help I have been stuck with this for some time now

Debug info
- [ ] PostHog Cloud, Debug information: [please copy/paste from https://us.posthog.com/settings/project-details#variables or https://eu.posthog.com/settings/project-details#variables]
- [ ] PostHog Hobby self-hosted with `docker compose`, version/commit: [please provide]
- [ ] PostHog self-hosted with Kubernetes (deprecated, see [`Sunsetting Kubernetes support`](https://posthog.com/blog/sunsetting-helm-support-posthog)), version/commit: [please provide]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Providers entry point shown in the issue by reproducing the problem in the production deployment and inspecting the browser-console error and deployed NEXT_PUBLIC_POSTHOG_* values. Compare production initialization with localhost; done means production events reach PostHog without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, react, typescript
Domain
analytics, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.