segmentio / analytics-next

Segment Analytics.js 2.0
https://segment.com/docs/connections/sources/catalog/libraries/website/javascript
MIT License
408 stars 136 forks source link

AnalyticsBrowser - amplitude-plugins/sessionId - Unexpected token '.' #734

Open Jackman3005 opened 1 year ago

Jackman3005 commented 1 year ago

The Issue

In our production environment Sentry is picking up an error when a user tries to fire an analytics event. (Out of the 10 Sentry events I analyzed all but one had the error occur right after the second analytics event is fired, ONE of them happened without the second event occurring at all)

Stack Trace

Here's the Raw Stack Trace

SyntaxError: Unexpected token '.'
  at definition.actions.sessionId.perform(webpack://[name]Destination/./src/destinations/amplitude-plugins/sessionId/index.ts:60:23)

Sentry provides the following "pretty" stack trace. As noted in the stack trace above, the offending error occurs at position 60:23. Line 60 is the first line with the if statement, character 23 is the . between the first appearance of event.integrations in that line.

if (context.event.integrations?.All !== false || context.event.integrations['Actions Amplitude']) {
  context.updateEvent('integrations.Actions Amplitude', {})
  context.updateEvent('integrations.Actions Amplitude.session_id', id)
}

More Context

It does not appear to be happening all the time, but it comes up regularly in our Sentry logs.

From what I can tell the order of events on our side is: 1 - User opens app - Start App analytics event is fired (no apparent issue with this) 2 - Segment GET request to https://cdn.segment.com/v1/projects/{our-project-id}/settings completes 3 - We fire an analytics event Navigate to Screen to record the initial screen they start on 4 - ??? 5 - Error happens

I don't know for sure if the order is different than when it "works" but the error message in the stack does seem a bit strange.

Has anyone else run into this yet?

Thanks in advance, Jack (& The Questmate Team)

silesky commented 1 year ago

Thanks. Looks related to https://github.com/segmentio/action-destinations/pull/943

Jackman3005 commented 1 year ago

Ahh, nice. Yeah seems likely! I look forward to updating and testing when the PR is merged.

Jackman3005 commented 1 year ago

Hey all 👋 I just wanted to confirm that we are still seeing this error. Here are the details for the latest reported error:

SyntaxError: Unexpected token .
  at s.actions.sessionId.perform(./destinations/amplitude-plugins/src/sessionId/index.ts:79:23)
Jackman3005 commented 1 year ago

Hi @silesky it appears that the PR you linked to earlier in this thread has turned out to not be the best approach to solving this issue. Do you have some ideas of other options to explore that could resolve the issue?

Please let me know if there is some way I can help.

Cheers, Jack

silesky commented 1 year ago

@Jackman3005 Sorry -- the team responsible for that repo removed the issue queue, and while I've reached out, there's been a lot of churn. Two of the main people on that thread are on other projects/away.

I would create a formal support ticket and link to that GitHub issue. Basically, the issue is that action destinations are not transpiled for support for older browsers -- link to the action destinations issue first (not this one).

If you're enterprising: there is a hot off the press "workaround" / feature on the latest ajs assuming you're already installing analytics via npm:

https://github.com/segmentio/segment-docs/pull/5315/files

If you install: @segment/analytics-browser-actions-amplitude-plugins

and pass it (see doc link), you can transpile it to es5 using your own build system (e.g webpack + babel)

Jackman3005 commented 1 year ago

Hey @silesky thanks for the reply and insight. We are not in an enterprise environment and are hoping to avoid the ownership of the solution you suggested, but I do appreciate you bringing it up and potentially others may benefit from it.

I have created a Segment support ticket that should hopefully kick start things a bit and get a resolution to this soon.

Cheers! Jack