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

Analytics autoTrack "event" fails with Gatsby (SSR) #6208

Closed
ohlr opened this issue Jul 1, 2020 · 3 comments
Closed

Analytics autoTrack "event" fails with Gatsby (SSR) #6208

ohlr opened this issue Jul 1, 2020 · 3 comments
Assignees
Labels
Analytics Related to analytics feature-request Request a new feature SSR Issues related to Server Side Rendering

Comments

@ohlr
Copy link

ohlr commented Jul 1, 2020

Describe the bug
following this setup: https://docs.amplify.aws/lib/analytics/autotrack/q/platform/js#page-event-tracking

while Analytics.autoTrack("pageView") and Analytics.autoTrack("session") work fine with Gatsbys Server Side rendering (SSR)

Adding Analytics.autoTrack("event") produces the following error during production builds:

TypeError: Cannot convert undefined or null to object
Function.assign
render-page.js:3382 EventTracker../node_modules/@aws-amplify/analytics/lib-esm/trackers/EventTracker.js.EventTracker.configure
render-page.js:964 AnalyticsClass../node_modules/@aws-amplify/analytics/lib-esm/Analytics.js.AnalyticsClass.autoTrack

In development mode everything works fine.
I guess that autoTrack uses a variable like (window / location) that is not known at compile time.

The failure only occurs when being called within a React component.
Outside of components it works fine. However in order to be able to turn Analytics on and off I need it to be inside React.

This here could be the reason for failure:
https://github.com/aws-amplify/amplify-js/blob/main/packages/analytics/src/trackers/EventTracker.ts#L33

Related issues:
#5435

Env:
"aws-amplify": "^3.0.10",
"gatsby": "^2.21.9",

@ohlr ohlr added the to-be-reproduced Used in order for Amplify to reproduce said issue label Jul 1, 2020
@Amplifiyer Amplifiyer added Analytics Related to analytics feature-request Request a new feature SSR Issues related to Server Side Rendering and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels Jul 1, 2020
@Amplifiyer
Copy link
Contributor

@ohlr, as you correctly pointed out, SSR is currently not officially supported. I will mark this as a feature request and work along with #5435. cc @ericclemmons

@dr-star
Copy link

dr-star commented Dec 11, 2022

Which is the status of this task?

@stocaaro stocaaro added the investigating This issue is being investigated label Apr 13, 2023
@nadetastic nadetastic removed the investigating This issue is being investigated label Nov 20, 2023
@cwomack
Copy link
Member

cwomack commented Dec 18, 2023

@ohlr and @dr-star

With Amplify JS v6 we provide an adapter for only Next.js, although the underlying generic adapters can be used with other frameworks. We have published documentation on how to use the generic adapters which can be viewed here - docs.amplify.aws/react/build-a-backend/server-side-rendering

Let me know if you have any questions.

@cwomack cwomack added pending-response feature-request Request a new feature and removed feature-request Request a new feature labels Dec 18, 2023
@cwomack cwomack closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analytics Related to analytics feature-request Request a new feature SSR Issues related to Server Side Rendering
Projects
None yet
Development

No branches or pull requests

6 participants