Skip to content
New issue

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

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

Already on GitHub? # to your account

Is analytics-next officially supported? #259

Closed
danielmhanover opened this issue Aug 21, 2022 · 9 comments
Closed

Is analytics-next officially supported? #259

danielmhanover opened this issue Aug 21, 2022 · 9 comments

Comments

@danielmhanover
Copy link

I noticed this lib has a dependency on window.analytics and @types/segment-analytics and so I'm wondering if this library has been tested against the newer analytics-next lib for Segment?

@ameliejyc
Copy link

Hi, I also have this same question. We're currently using the analytics-next library but to integrate with Typewriter, it looks like we need to add the Segment snippet additionally. Is that to be expected or should we be able to get it working without the snippet?

@tplessis
Copy link

tplessis commented Jan 9, 2023

Hello, same problem here, types are incompatible for window.analytics : analytics-next use AnalyticsSnippet and typewriter use AnalyticsJS.

@richessler
Copy link

Hello, also curious here - is this currently supported?

@jriall
Copy link

jriall commented Mar 22, 2023

Hi, we are also looking to implement Typewriter but cannot see an obvious way to do it with our current implementation of analytics-next. It would be great if this could be added to the library.

@jriall
Copy link

jriall commented Mar 24, 2023

After digging into this more I found that it seems possible to get typewriter to play nice with analytics-next. The blocker was that the default analytics used by typewriter is window.analytics which is not available when using analytics-next. Thankfully, you can set the analytics object to use yourself using setTypewriterOptions.

import { AnalyticsBrowser } from "@segment/analytics-next";

import { setTypewriterOptions } from "./your-generated-typewriter-client";

const analytics = new AnalyticsBrowser();
setTypewriterOptions({analytics});

From here all of your tracking events should work. The only caveat is that the analytics types are not the same (typewriter uses SegmentAnalytics.AnalyticsJS and analytics-next uses AnalyticsBrowser. So far I have just silenced the compiler/linter and it seems to work ok.

It would definitely be a lot better if there was first class support for analytics-next to avoid having to hack around the types in this way though - I can't have confidence that this won't break in future.

@tleunen
Copy link

tleunen commented Apr 19, 2023

Yeah it seems there are types conflict between the generated Context and the AnalyticsContext, especially for the campaign prop.

The AnalyticsContext.campaign has all the props being required, while the one being generated has all of them being optional.

@silesky
Copy link
Contributor

silesky commented Apr 28, 2023

⚠️ Typewriter has been upgraded to use @segment/analytics-next in v9.0.0 - https://github.com/segmentio/typewriter/releases/tag/v9.0.0

@silesky silesky closed this as completed Apr 28, 2023
@tleunen
Copy link

tleunen commented May 17, 2023

@silesky What minimum version of analytics-next is compatible with typewriter v9?

We've used v1.38.0 previously, and when upgrading to the most recent v1.57.1, we found out that events were not sent to segment anymore (but only in production for some reasons) and it's been hard to debug this so we rollback to our previous version for now. (And btw, if you have an idea what could be the problem, I'd appreciate it a lot!)

The generated file uses an AnalyticsSnippet type from analytics-next that is not present in v1.38.0 so I was wondering if you knew which version introduces it?

@silesky
Copy link
Contributor

silesky commented May 17, 2023

@tleunen I think 1.43.1?

There were significant API enhancements around 1.38. You might want to take another look at the updated README and follow the recommended way for instantiating analytics, since that has changed -- we support a synchronous API out of the box, which improves event reliability.

Also directions for logging initialization errors.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants