Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct remix example #8960

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Changes from 1 commit
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
45 changes: 23 additions & 22 deletions contents/tutorials/remix-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,32 @@ With these, go to `entry.client.tsx` and initialize PostHog using a component. T

```tsx
// app/entry.client.tsx
import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode, useEffect } from "react";
import { hydrateRoot } from "react-dom/client";
import posthog from "posthog-js";

function PosthogInit() {
useEffect(() => {
posthog.init('<ph_project_api_key>', {
api_host: '<ph_client_api_host>',
person_profiles: 'identified_only',
});
}, []);
import * as React from 'react';
import { RemixBrowser } from '@remix-run/react';
import { hydrateRoot } from 'react-dom/client';
import posthog from 'posthog-js';

function hydrate() {
posthog.init('token', {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only',
pauldambra marked this conversation as resolved.
Show resolved Hide resolved
});

return null;
React.startTransition(() => {
hydrateRoot(
document,
<React.StrictMode>
<RemixBrowser />
</React.StrictMode>,
);
});
}

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
<PosthogInit/>
</StrictMode>
);
});
if (window.requestIdleCallback) {
window.requestIdleCallback(hydrate);
} else {
window.setTimeout(hydrate, 1);
}
```

After relaunching your app, PostHog begins autocapturing initial pageviews, clicks, [session replays](/docs/session-replay) (if [you enable them](https://app.posthog.com/settings/project#replay)), and more.
Expand Down
Loading