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

Initiating Amplitude SDK in _app.js Breaks Pages with SSR (Next js) #549

Open
vastava opened this issue Aug 20, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@vastava
Copy link

vastava commented Aug 20, 2023

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
@vastava vastava added the bug Something isn't working label Aug 20, 2023
@yuhao900914
Copy link
Contributor

Hi @vastava
Thanks for choosing amplitude.
Based on here, it says the page called getServerSideProps will be server side rendered at request time. However, our analytics-browser SDK only supports the client side. If you do not need to render the data during the request, then you should consider fetching data on the client side or getStaticProps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants