Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Support for multiple write keys.

Open
#367 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
analytics

Research direction

Start with the linked reproduction, using public/index.html and src/index.tsx to load both analytics-next instances with separate write keys. Reload the application and inspect requests to the p endpoint while only the window.analytics instance sends a page event. Done means concurrent loading no longer produces a request from the other instance.

Written by the indexing model from the issue text.

Description

enhancement

Hello,

We were led to believe that it is possible to run two instances of analytics-next with different write keys side by side. One via segment source snippet (exposed on window.analytics) and the other one as an npm module.

When we try to do this, it mostly works with one quirk/bug. If the two instances are loading concurrently (which is the common scenario), it can happen that events fired via window.analytics (segment source snippet) cause two network requests - one using the segment source snippet write key and the other one using npm module's source key. Once both instances are finished loading they behave as expected with each only firing network requests for its own events.

We were speculating that this is due to the fact that window.analytics as provided by snippet creates a queueing implementation of methods (to be used before the analytics-next is fully loaded) and then somehow snippet and npm module versions both read and fire events on that queue. Not sure if this is actually the case - it's just a guess.

I assembled a small sample application that demonstrates the issue. It loads analytics-next from both snippet and npm module, but only fires a page event on the snippet version. If you reload the page several times, you should see examples of that single page event causing two requests to be sent to a p endpoint. See:
Two requests to p

You will of course need to provide your own write keys here and here.

Using multiple instances of analytics with different write keys seems to have been something that was "advertised" as a feature, and when talking to our Segment representative they said that this should be possible with analytics-next as well.

Thanks for any help or further info.

Dominant language
TypeScript
Stars
478
Forks
161
Avg merge
6h 19m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from segmentio/analytics-next

All issues in segmentio/analytics-next

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.