analytics-next icon indicating copy to clipboard operation
analytics-next copied to clipboard

Do not throw error when analytics are disabled.

Open Pruxis opened this issue 2 years ago • 4 comments

Imagine the following case where you disable segment in your code.

const { Analytics } = require('@segment/analytics-node'); new Analytics({ writeKey: processe.env.WRITE_KEY || '', disable: true });

If WRITE_KEY is not present, but your analytics are disabled this still throws an error.

This would simplify local setups and do not force them to have a truthy string as write key

Pruxis avatar Jul 15 '23 06:07 Pruxis

🦋 Changeset detected

Latest commit: d25217d4eda3e06dcd06e665afcd939a71ae20ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jul 15 '23 06:07 changeset-bot[bot]

@Pruxis Thanks for opening this pull request! I think from a TypeScript perspective writeKey will still be required with this change - @silesky do you think we should update types as well (I think we'd need a tagged union to make this nice) or really just keep this a runtime check?

chrisradek avatar Jul 18 '23 17:07 chrisradek

@Pruxis Thanks for opening this pull request! I think from a TypeScript perspective writeKey will still be required with this change - @silesky do you think we should update types as well (I think we'd need a tagged union to make this nice) or really just keep this a runtime check?

Runtime only; no Typescript changes are needed here IMO.

silesky avatar Jul 18 '23 17:07 silesky

@silesky Do I need to write some tests to get this merged?

Pruxis avatar Aug 11 '23 09:08 Pruxis