amplitude / amplitude/Amplitude-TypeScript
Initiating Amplitude SDK in _app.js Breaks Pages with SSR (Next js)
- Dominant language
- TypeScript
- Stars
- 180
- Forks
- 68
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 29
Description
## Expected Behavior:
The Next App example for shows that users should be able to be initiate amplitude in the _app.js file using the following code:
`amplitude.init(AMPLITUDE_API_KEY);`
## Current Behavior
If you have pages that use the `getServerSideProps` function, calling amplitude.init() in the root file causes these pages to throw a 500 error when accessing them. I suspect this is because of an incompatibility with Server Side Rendering.
Steps to reproduce:
1. Add the init function call to _app.js file. `amplitude.init(AMPLITUDE_API_KEY);`
2. Create a page that uses the getServerSideProps function.
3. Run the Next.js development server and observe the behavior when navigating to the page from step 2.
## Environment
- JS SDK Version: "@amplitude/analytics-browser": "^2.2.0",
- Installation Method: npm
Contributor guide
Assessment
This issue has not been assessed yet.