Giter Site home page Giter Site logo

segmentio / analytics-next Goto Github PK

View Code? Open in Web Editor NEW
374.0 374.0 123.0 8.11 MB

Segment Analytics.js 2.0

Home Page: https://segment.com/docs/connections/sources/catalog/libraries/website/javascript

License: MIT License

JavaScript 2.21% Shell 0.17% TypeScript 90.29% HTML 4.70% Makefile 0.27% Prolog 0.31% CSS 2.05%
analytics sdk segment typescript

analytics-next's People

Contributors

509dave16 avatar alanjcharles avatar arielsilvestri avatar bryanmikaelian avatar chrisradek avatar danieljackins avatar dependabot[bot] avatar github-actions[bot] avatar gpsamson avatar juliofarah avatar kurtfurbush avatar maritzuhcom avatar mericsson avatar michaelghseg avatar nettofarah avatar nicholasluimy avatar oscb avatar pooyaj avatar reslear avatar ryder-wendt avatar silesky avatar thomasskk avatar williamgrosset avatar zikaari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

analytics-next's Issues

[Propose] Convert Repo to mono-repository setup

Things like from the docs,

  const [analytics, setAnalytics] = useState<Analytics | undefined>(undefined)
  const [writeKey, setWriteKey] = useState('<YOUR_WRITE_KEY>')

  useEffect(() => {
    const loadAnalytics = async () => {
      let [response] = await AnalyticsBrowser.load({ writeKey })
      setAnalytics(response)
    }
    loadAnalytics()
  }, [writeKey])

Could be shared under @segment/analytics-react or something like that, so maybe convert the package into a mono-repository so we can collaborate in the subject matter.

I am currently doing early adoptions, so I can take some ownership on proposing some solutions based on our existing setup.

Localstorage persisted-queue not being utilized even when retry flag is set (when batching?)

We have an issue on our site where when clicking a link that also sends an event, we're not seeing those events in segment.
My answer to that was "segment uses local storage to make sure events can be sent".
However, I dove a little deeper and wasn't able to verify that this is working (at least for us).

I cracked open some of the segment-next (v2) source code, and I believe that the localstorage should be populated with keys that start with "persisted-queue".
image

I checked our localstorage and I'm not seeing any keys going in/out of local storage to that effect. I've also opened up the PersistedPriorityQueue class in my browser and can't get any break points to stop there. I found some suspicious code in analytics.ts
image
It looked to me that dispatchSingle didn't use any queuing, which would cause it to skip the persistence.
That being said, I also overrode analytics.queue.isEmpty = () => false like so, and even calling dispatch isn't triggering breakpoints for me.

Both retries and analytics 2.0 are enabled for me.
image

Anonymous function causes trouble in Next.js

Next.js is warning about an Anonymous function in @segment/analytics-next/dist/pkg/index.js when using as npm package.

warn - ./node_modules/@segment/analytics-next/dist/pkg/index.js
Anonymous function declarations cause Fast Refresh to not preserve local component state.

Disabling tracking in development mode

In the development environment, I'd like to keep tracking disabled. I'm trying to skip analytics.load() in dev mode. But then this is breaking analyics.track() calls that pass a callback to fire after tracking. The other option I see is to skip including analytics.js altogether in dev but then that would mean I'm checking if analytics is defined everywhere its being used. Another option is to create a mock implementation of analytics.js that does nothing but is API compatible with the library.

Is there a better way to transparently run this in development mode without breaking the application or having to write a lot of conditionals? Or should I just setup a free Segment account and link development mode to that account?

Just looking to see if there is a clean recommended approach for this use case.

Queue calls while awaiting `load` when using the NPM package

I'm loading from NPM rather than through the snippet.

I may be misunderatanding how AnalyticsBrowser.load() works, and I see reference in the docs to the library enqueuing calls before the script loads, but according to the example in the README, the analytics instance is optional until await AnalyticsBrowser.load({ ... }) is completed. This means any analytics?.track(...), analytics?.identify(...) etc. will be no-ops while awaiting. This seems quite bad since there will now be race conditions between our initial events like page views, versus the time for the AnalyticsBrowser.load to complete.

Am I misunderstanding things? How can I get all of my calls to analytics to work, even those that run immediately after calling await AnalyticsBrowser.load but before that response has come back? Do I have to wrap the lib and implement enqueing myself?

cc @chrisradek @pooyaj @danieljackins

[Question] Vuejs Integration

Hey, any example of how to integrate with Vue, but most importantly, how to not use the snippet provided by Segment, so we initialise everything via the library?

Thank you!

Custom integration with analytics-next

Hello,

I've been investigating the possibility of using the custom integration for Analytics-next.

It appears that I can only use the ones listed here: https://github.com/segmentio/analytics.js-integrations/tree/master/integrations and they are loaded from the Segment CDN on analytics init.

Would it be possible to use a completely custom integration without submitting it to https://github.com/segmentio/analytics.js-integrations/tree/master/integrations?

Thanks!

Using Analytics.js 2.0 + Heap with Angular

Is Angular a 2nd class citizen :[ ?

Could we have some docs on creating a nice angular service for the new version please?

Thanks!

p.s. I'm going to have a go at the service; will post it here.

create-react-app Shows warnings in console.

Hello!

After installing and using analytics-next in a create-react-app we're getting quite a few warnings in the console when running in development, they are all similar to the following:

image

Does not work with Next.js SSR or api routes

When trying to use analytics-next on backend window is not defined. The source code that breaks the initialization lies here:
https://github.com/segmentio/analytics-next/blob/master/src/lib/priority-queue/persisted.ts#L112

Am I doing anything wrong?

ReferenceError: window is not defined
    at new PersistedPriorityQueue (/Users/franzvonderlippe/Programming/ally/node_modules/@segment/analytics-next/dist/cjs/lib/priority-queue/persisted.js:88:9)
    at new Analytics (/Users/franzvonderlippe/Programming/ally/node_modules/@segment/analytics-next/dist/cjs/analytics.js:36:97)
    at getServerSideProps (webpack-internal:///./pages/bookings/[id]/index.tsx:237:27)
    at Object.renderToHTML (/Users/franzvonderlippe/Programming/ally/node_modules/next/dist/server/render.js:479:26)
    at async doRender (/Users/franzvonderlippe/Programming/ally/node_modules/next/dist/server/next-server.js:1389:38)
    at async /Users/franzvonderlippe/Programming/ally/node_modules/next/dist/server/next-server.js:1484:28
    at async /Users/franzvonderlippe/Programming/ally/node_modules/next/dist/server/response-cache.js:63:36
    ```

ajs_anonymous_id can't be read from local storage using JSON.parse

This package seems to throw an error when reading the ajs_anonymous_id from local storage.
See screenshots below which triggers the error.

Im using a next project (^11.1.2) with the lastest version of this package (^1.30.0)

Local Storage on initial load

image

Cookies on initial load

image

Local Storage on refresh

image

Which results in the following error

image
image

Chrome Extension ChunkLoadErrors - option to package a standalone JS file?

We want to use Segment in a Chrome extension application. It's a Vue 2 app packaged with webpack.
Chrome extensions can't use Analytics.js as a script src include because external code is not allowed in the new MV3 version of Chrome extensions. All code needs to be packaged with the app for audit / review.

So I imported the NPM and adapted the Vue 3 example to work in Vue 2. But I'm getting ChunkLoadError's which seem to be related to code splitting. Several JS files got created but you can't load them without proper addressing - Chrome extensions aren't a website, and file dependencies need to be declared and then loaded through chrome.runtime.getURL().

So, does the NPM support any way of packaging into a standalone JS file without code splitting? Then I could just load that file (as long as it doesn't pull any additional src dependencies down from the CDN).

Sample error:

ChunkLoadError: Loading chunk vendors~ajs-destination failed.
(error: chrome-extension://<snipped - extension_id>/extensionvendors~ajs-destination.js)
    at Function.requireEnsure [as e] (devtools_panel.js:106)

Can we use plugins with AnalyticsNode?

I haven't seen much discussion about the AnalyticsNode portion of the repo, but it seems to support sending Analytics events from a server.

Is there any way to use the same plugins functionality that is used by AnalyticsBrowser? If not, is there any way to add middleware to AnalyticsNode?

Package is missing from npm

My build is failing with an error that @segment/analytics-next is not found:

#28 104.0 npm ERR! code E404
#28 104.0 npm ERR! 404 Not Found - GET https://registry.npmjs.org/@segment/analytics-next/-/analytics-next-1.30.0.tgz - Not found
#28 104.0 npm ERR! 404 
#28 104.0 npm ERR! 404  '@segment/analytics-next@https://registry.npmjs.org/@segment/analytics-next/-/analytics-next-1.30.0.tgz' is not in the npm registry.
#28 104.0 npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
#28 104.0 npm ERR! 404 
#28 104.0 npm ERR! 404 Note that you can also install from a
#28 104.0 npm ERR! 404 tarball, folder, http url, or git url.
#28 104.1 
#28 104.1 npm ERR! A complete log of this run can be found in:
#28 104.1 npm ERR!     /root/.npm/_logs/2021-10-29T22_55_20_809Z-debug.log

Plus, the NPM page: https://www.npmjs.com/package/@segment/analytics-next

Allow cdn in AnalyticsSettings

Hello 👋

If I understand correctly the current way to set the cdn is this

window.analytics._cdn = <cdn>

Because this variable can then be reused in the plugins

We try to avoid touching the window object as much as possible
Would it be possible to pass the cdn in the AnalyticsSettings which is then passed down to the plugins ?

AnalyticsBrowser.load({ writeKey, cdn })
export function loadLegacySettings(writeKey: string, cdn: string): Promise<LegacySettings> {
  return fetch(`${cdn}/v1/projects/${writeKey}/settings`)
    .then((res) => ({ ...res.json(), cdn }))
    .catch((err) => {
      console.warn('Failed to load settings', err)
      throw err
    })
}

Thanks :)

Self-hosted/Standalone Implementation

I've been looking through the next analytics repo to set up a self-hosted implementation of the analytics repo and it seems all initialization entry points lead to loading the legacy settings from segment API. Is it possible to the settings directly without the hitting the API and load the integrations from the modules themselves without loading them from the CDN?

Thanks in advanced.

process is not defined

Hello,

Leveraging the example in the README raises the following error with v1.30.0:

image

It looks like process.env variables aren't being replaced during the pkg build:

new webpack.EnvironmentPlugin({
LEGACY_INTEGRATIONS_PATH: 'https://cdn.segment.com/next-integrations',
DEBUG: false,
VERSION: version,
ASSET_PATH,
}),

Great job on the new library! I'm working on replacing our use of https://github.com/segmentio/analytics.js-core with it.

Thanks

Tip: you might also want to add files: ["dist/", "src/"] to package.json so only runtime files are published to NPM (see files) as opposed to the whole repo
image

Expose Callback

Related to: #311 (comment)

Doing the following,

// Notice the Callback usage
export function analyticsTrack<TProperties = object | Callback>() {
  const analyticsContext = useSegmentAnalyticsContext();
  return (eventName: string, properties?: TProperties) => {
    return analyticsContext.analytics.track(eventName, properties);
  };
}

I need access to the Callback since importing from import { Callback } from '@segment/analytics-next/dist/pkg/core/callback'; will make it fail, see #311

26 high severity vulnerabilities in the latest release

Just update to the latest release and found that there are 26 high severity vulnerabilities used as dependencies.

                      === npm audit security report ===                        
                                                                                
# Run  npm update minimist --depth 29  to resolve 26 vulnerabilities
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @emotion/server                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @emotion/server > html-tokenize > minimist                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ eslint-plugin-import [dev]                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ eslint-plugin-import > tsconfig-paths > json5 > minimist     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ eslint-config-next [dev]                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ eslint-config-next > eslint-import-resolver-typescript >     │
│               │ tsconfig-paths > json5 > minimist                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest > @stdlib/cli-ctor > minimist │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest > @stdlib/cli-ctor > minimist │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-float32 >    │
│               │ @stdlib/utils-library-manifest > @stdlib/cli-ctor > minimist │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-float64 >    │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/cli-ctor > minimist                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-reim >       │
│               │ @stdlib/complex-float64 > @stdlib/complex-float32 >          │
│               │ @stdlib/utils-library-manifest > @stdlib/cli-ctor > minimist │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/cli-ctor > minimist                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest > @stdlib/utils-convert-path  │
│               │ > @stdlib/regexp-eol > @stdlib/assert-is-boolean >           │
│               │ @stdlib/utils-native-class >                                 │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path >                             │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-object >  │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path >                             │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-object >  │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-float32 >    │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path >                             │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-object >  │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-float64 >    │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/fs-resolve-parent-path >                             │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-object >  │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-assert-is-infinite >                       │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-float32 >    │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-float64 >    │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/fs-resolve-parent-path > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-reim >       │
│               │ @stdlib/complex-float64 > @stdlib/complex-float32 >          │
│               │ @stdlib/utils-library-manifest >                             │
│               │ @stdlib/fs-resolve-parent-path > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/fs-resolve-parent-path > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/fs-resolve-parent-path >                             │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/utils-convert-path > @stdlib/regexp-eol >            │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/math-base-special-copysign >                         │
│               │ @stdlib/math-base-napi-binary > @stdlib/complex-reim >       │
│               │ @stdlib/complex-float64 > @stdlib/complex-float32 >          │
│               │ @stdlib/utils-library-manifest > @stdlib/utils-convert-path  │
│               │ > @stdlib/string-replace > @stdlib/assert-is-regexp-string > │
│               │ @stdlib/regexp-eol > @stdlib/assert-is-plain-object >        │
│               │ @stdlib/assert-is-function > @stdlib/utils-type-of >         │
│               │ @stdlib/utils-constructor-name > @stdlib/assert-is-buffer >  │
│               │ @stdlib/assert-is-object-like >                              │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/utils-convert-path > @stdlib/string-replace >        │
│               │ @stdlib/assert-is-regexp-string > @stdlib/regexp-eol >       │
│               │ @stdlib/assert-is-plain-object > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/utils-convert-path > @stdlib/string-replace >        │
│               │ @stdlib/assert-is-regexp-string > @stdlib/regexp-eol >       │
│               │ @stdlib/assert-is-plain-object >                             │
│               │ @stdlib/utils-get-prototype-of > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/cli-ctor >       │
│               │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution in minimist                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @segment/analytics-next                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @segment/analytics-next > @segment/tsub >                    │
│               │ @stdlib/math-base-special-ldexp >                            │
│               │ @stdlib/number-float64-base-normalize >                      │
│               │ @stdlib/math-base-special-abs > @stdlib/math-base-napi-unary │
│               │ > @stdlib/complex-reim > @stdlib/complex-float64 >           │
│               │ @stdlib/complex-float32 > @stdlib/utils-library-manifest >   │
│               │ @stdlib/utils-convert-path > @stdlib/string-replace >        │
│               │ @stdlib/assert-is-regexp-string > @stdlib/regexp-eol >       │
│               │ @stdlib/assert-is-plain-object >                             │
│               │ @stdlib/utils-get-prototype-of > @stdlib/assert-is-function  │
│               │ > @stdlib/utils-type-of > @stdlib/utils-constructor-name >   │
│               │ @stdlib/assert-is-buffer > @stdlib/assert-is-object-like >   │
│               │ @stdlib/assert-tools-array-function >                        │
│               │ @stdlib/assert-is-array > @stdlib/utils-native-class >       │
│               │ @stdlib/assert-has-tostringtag-support >                     │
│               │ @stdlib/assert-has-symbol-support > @stdlib/fs-read-file >   │
│               │ @stdlib/cli-ctor > minimist                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-xvch-5gv4-984h            │
└───────────────┴──────────────────────────────────────────────────────────────

Logger being blocked by adblocker

Hello,
Recently we've run into a lot of problems with Segment being blocked by adblockers (particularly the built-in ones on the Brave browser) while this library. It manifests itself as errors like these (which we're working on a fix to handle gracefully):

Cannot read properties of undefined (reading 'identify')

as we call it like this

window.analytics.identify(...)

We are fairly certain that the "mounting logic" is being called and our logger is initially made available. We're wrapping our _app.tsx in a SegmentProvider that handles this logic as following:
SegmentProvider.tsx

export const SegmentProvider: React.FC<SegmentProviderProps> = ({ children }) => {
  const SEGMENT_WRITE_KEY = process.env.SEGMENT_WRITE_KEY!;
  const plugins: Plugin[] = process.env.NODE_ENV !== "production" ? [debugLogger] : [];

  useEffect(() => {
    const loadAnalytics = async (): Promise<void> => {
      let [response] = await AnalyticsBrowser.load({ writeKey: SEGMENT_WRITE_KEY, plugins });
      (window as any).analytics = response;
      // eslint-ignore-next-line no-console
      console.log("✅ Segment logger initiated");
    };
    loadAnalytics();
  }, [SEGMENT_WRITE_KEY]);

  return <Box id="segment-provider">{children}</Box>;
};

_app.tsx

...
<SegmentProvider>
    <Component {...pageProps} />
</SegmentProvider>
...

Any insights, best practices, etc. would be greatly appreciated!

Does it support nonce?

For CSP, I'd like to do AnalyticsBrowser.load({ writeKey, nonce }) where nonce is a CSP nonce passed to allow specific scripts

Querystring `ajs_uid` is not decoded when passed to identify

Hi, we use email as User ID and want to use querystring api, but what happens if I send customers to https://example.com/[email protected] it often ends on https://example.com/?ajs_uid=some%40example.org because web-server or app redirect to encoded url, it results that identify is fired for some%40example.org however the url parameter is still [email protected] if accessed properly using URLSearchParams.

I expect that analytics.js should be able to decode url params properly.

Error when registering an integration from segmentio/analytics.js-integrations

Trying to add some client-side plugins from "https://github.com/segmentio/analytics.js-integrations", and I am getting a callback error.

Here is my implementation:

const analytics = new Analytics({
  writeKey: 'some-write-key'
})
import { Analytics } from '@segment/analytics-next'
import * as Amplitude from '@segmentio/analytics.js-integrations/integrations/amplitude'
const plugins: Plugin[] = []
const amplitude: Plugin = Amplitude({apiKey: 'my-api-key'})
plugins.push(amplitude)
analytics.register(...plugins)
analytics.initialize()

Error:

Uncaught TypeError: callback is not a function

It is trying to call a callback that does not exists in this code:

exports.load = function(name, locals, callback) {
  // Argument shuffling
  if (typeof name === 'function') { callback = name; locals = null; name = null; }
  if (name && typeof name === 'object') { callback = locals; locals = name; name = null; }
  if (typeof locals === 'function') { callback = locals; locals = null; }

  // Default arguments
  name = name || 'library';
  locals = locals || {};

  locals = this.locals(locals);
  var template = this.templates[name];
  if (!template) throw new Error(fmt('template "%s" not defined.', name));
  var attrs = render(template, locals);
  callback = callback || noop;
  var self = this;
  var el;

  switch (template.type) {
  case 'img':
    attrs.width = 1;
    attrs.height = 1;
    el = loadImage(attrs, callback);
    break;
  case 'script':
    el = loadScript(attrs, function(err) {
      if (!err) return callback();
      self.debug('error loading "%s" error="%s"', self.name, err);
    });
      // TODO: hack until refactoring load-script
    delete attrs.src;
    each(function(val, key) {
      el.setAttribute(key, val);
    }, attrs);
    break;
  case 'iframe':
    el = loadIframe(attrs, callback);
    break;
  default:
      // No default case
  }

  return el;
};

Is this not the correct way to implement integrations from "https://github.com/segmentio/analytics.js-integrations"?

Debug mode doesn't work

It looks like calling analytics.debug() no longer enables the debug mode.
This can be reproduced on segment.com itself, though not on app.segment.com which seems to still be running an older version.

I'm encountering this issue in Chrome 94 and Firefox 93 on mac.

A similar (and probably related) issue is probably not being able to turn off the debug mode by calling analytics.debug(false) if it was still on since before the update.

Using AnalyticsNode causes node process to hang

Hello, I'm currently working on a library that wraps this library to support both Node.js and React (as well as providing some custom validation logic). As I've been working on the Node.js side, I noticed that running code similar to the sample script in #352 causes the node process to hang. I have two questions:

  1. Is it intended for the node process to keep running after calling AnalyticsNode.load? If so, is there a way to gracefully stop the process?
  2. Is this the best library to use for integrating Segment into backend Node.js applications? I saw that there's https://github.com/segmentio/analytics-node, but using the same library for both frontend and backend would simplify the maintenance of our wrapper library.

Any help would be appreciated, thank you!

Allow overriding messageId

We have other tracking libraries we use on our site that we wish to use the same messageId for the same event sent to different sources, for example:

User clicks button (Event A):

const messageId = generateMsgId() // 456
const event = 'Event A'

segment.track(event, {}, { messageId }) // sends Event A with messageId 456
anotherSDK.track(event, { messageId }) // sends Event A with messageId 456

Instead, this is the problem we're running into:

User clicks button (Event A):

const messageId = generateMsgId() // 456
const event = 'Event A'
const properties = ...

segment.track(event, properties, { messageId }) // sends Event A with different messageId `ajs-next-*`
anotherSDK.track(event, properties, { messageId }) // sends Event A with messageId 456

Is there not a way to override the messageId per event, so we can use our own format in order to aggregate the same event across different sources? I see no way to do it with this library, but in the docs it says we can and you can in your other libs:

Keep in mind that Segment’s libraries all generate message_ids for each event payload, with the exception of the Segment HTTP API, which assigns each event a unique message_id when the message is ingested. You can override these default generated IDs and manually assign a message_id if necessary.

If there isn't a way in JS, I would propose Segment's JS lib allows it according to your docs.

Error: [vite]: Rollup failed to resolve import "tslib"

Using vite, I get this error when trying to start my Express server:

Error: [vite]: Rollup failed to resolve import "tslib" from "node_modules/@segment/analytics-next/dist/pkg/analytics.js".

It seems like tslib is a devDependency and in dist/pkg/analytics.js tslib is being imported on line 1:

import { __awaiter, __extends, __generator, __spreadArrays } from "tslib";

I'm guessing this vite/Rollup error is due to the devDependency not being available when it's referenced in my app? Adding tslib to my app's dependencies fixes the issue, but maybe it should be a non dev dependency in analytics-next?

Make protocol configurable

We use our backend as a proxy to Segment API in order to bypass ad-blockers. But we are unable to test it in local dev environment on our machines where HTTP is used instead of HTTPS.

It looks like HTTPS protocol is hardcoded here. Can you create a new settings property which specifies protocol and defaults to https?

I've already asked for this in segmentio/analytics.js-integrations#559 and there hasn't been any response.

Unsafe global usage

Always targeting global in the code breaks the build for some bundlers like Vite unless you stub it in the define function. However, doing so can break other packages. I would suggest safely getting global like Sentry.

/**
 * Safely get global scope object
 *
 * @returns Global scope object
 */
export function getGlobalObject<T>(): T & SentryGlobal {
  return (isNodeEnv()
    ? global
    : typeof window !== 'undefined' // eslint-disable-line no-restricted-globals
    ? window // eslint-disable-line no-restricted-globals
    : typeof self !== 'undefined'
    ? self
    : fallbackGlobalObject) as T & SentryGlobal;
}

Possibility to call Analytics methods before AnalyticsBrowser.load and flush buffer after

Hey everyone.

We are trying to use this library inside our project but we are seeing a situation. We need a way to start call analytics methods before the AnalyticsBrowser.load finishes.

We tried to instantiate Analytics and started to call the methods, which seems to be working.
But following the examples inside this repository README, which says to call Analytics.load and assign/merge the response results to the previous instantiated Analytics, doesn't seem to be dispatching the "queued" items

We did something like this:

import { Analytics, AnalyticsBrowser } from '@segment/analytics-next'

const analytics = new Analytics({})

analytics.page('pagename')

AnalyticsBrowser.load({ writeKey: xxxxxx }).then(([response]) => {
  analytics = response
  // we tried Object.merge as well
  Object.assign(analytics, response)
})

The events dispatched after the .load are working. Only the previous ones are not being dispatched

Are we doing something wrong?
Should we implement our own "queue" and flush after the load()?

Setting custom domain when using a proxy

Hi 👋
We're using a proxy for analytics.js following the Segment guidelines. In the classic version it was possible to set the domain using apiHost. What's the correct way of doing this using analytics-next?

We're working around it by setting window.analytics._cdn = 'https://my.custom-domain.com' before calling AnalyticsBrowser.load(writeKey).

I'm sure there is a better way but couldn't work it out looking through the code.

Appreciate any help.

Add @types/jquery as dependency

Issue

When using this repo in a TypeScript project that does not include jquery, the TypeScript compiler has an error:

../node_modules/@segment/analytics-next/dist/pkg/core/auto-track.d.ts:1:23 - error TS2688: Cannot find type definition file for 'jquery'.

1 /// <reference types="jquery" />

This is because this project's compiled TypeScript definitions depends on jquery, specifically @types/jquery.

Solution

Move @types/jquery from devDependencies to dependencies.

Intercom integration is failing in some cases

We are using Segment together with Intercom integration but sometimes (specifically on our login page) the initialization is failing. We weren't able to find a fix as we really don't understand why it's happening in the first place. On all other pages it works fine.

Can you please help us to either debug the problem or provide some instructions how to fix it? Thank you.

Here's the error we see, I can't see anything related to our code, that's why it's hard to debug:

Uncaught TypeError: Cannot read properties of undefined (reading 'hideDefaultLauncher')
    at y (index.js:39:3)
    at e.OJRb.l.bootOrUpdate (index.js:220:17)
    at e.OJRb.l.page (index.js:82:33)
    at e.page (protos.js:343:17)
    at protos.js:204:23
    at c (index.js:64:9)
    at t.exports (index.js:122:59)
    at e.flush (protos.js:203:3)
    at e.<anonymous> (index.js:21:15)
    at e.r (index.js:65:8)
    at e.n.emit (index.js:145:20)
    at e.ready (protos.js:307:8)
    at index.js:21:15
    at protos.js:262:24
    at HTMLScriptElement.<anonymous> (index.js:27:47)

Buffer calls while loading script setup

Hey peeps,

Following your example about NextJS, we had to start adding optional chaining (?) everywhere around the analytics object because there is a timing issue calling the analytics stuff.

async function flushBuffered(analytics: Analytics): Promise<void> {

It is not clear to me how we should create that window.analytics beforehand, for example, how Google Analytics does it:

(function (window, document, tagName, src, scopeName, a, m) {
  
  // this whole thing
  window['GoogleAnalyticsObject'] = scopeName;
  window[scopeName] = window[scopeName] || function () {
    (window[scopeName].q = window[scopeName].q || []).push(arguments)
  }, window[scopeName].l = 1 * new Date();

  a = document.createElement(tagName), m = document.getElementsByTagName(tagName)[0];
  a.async = 1;
  a.src = src;
  m.parentNode.insertBefore(a, m)

})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

Would be amazing to add some example about it in terms of how to setup such object to avoid timing issues.


As I was creating the ticket I realized you do the buffering already leaving extra context regardless For example:
export function useIdentifyAnalytics() {
  const analyticsContext = useSegmentAnalyticsContext();
  return (userId: string, traits: any) => {
    // TODO: Remove `?` from the call.
    // We need to find a way to wait for the analytics to be loaded first. This is a temporary fix. The downside of that
    // is that forcing the user to wait for a spinner or something like for analytics to load is not ideal.
    // Ideally, the 3rd party dependency should buffer the calls and only send them when the analytics is loaded,
    // instead us doing all that logic in our app.
    return analyticsContext.analytics?.identify(userId, traits);
  };

When this hook (or any other ones that we have) triggers, sometimes the script still loading, so there is no object available yet. So there is a timing issue.

Forcing some spinner in our app is less than ideal since it will impact the user experience drastically in an era where we can't afford more than 500ms to 1sec for user attention.

Breaks application if user disallow cookies

  • We are building an application that is hosted as an iframe with in another application.
  • We would like to check if cookie access is enabled and then call await AnalyticsBrowser.load({ writeKey }) but just importing AnalyticsBrowser crashes the application.

Steps to reproduce:-

  • git clone https://github.com/peeyushsingla1/testing-segment-analytics
  • yarn && yarn start
  • Block all cookies from chrome(as our application lives in iframe setting block third party cookies caused this issue).

Screenshot 2021-11-07 at 12 16 02

  • Visit application and it would break
    Screenshot 2021-11-07 at 12 09 17

Technical Details:-

  • Issue is happening because of persisted file.
  • Persisted uses constant that executes immediately on import, if it would be a function it won't executes until we call the function.

Possible Solution:-

Uncaught TypeError: can't redefine non-configurable property "metadata"

Hello,

Our Sentry integration has caught multiple of the above mentioned error. This seems to happen on multiple versions of Firefox ranging from v60 to v93. Also, the users seem to be using Linux.

I have tried reproducing this on my machine, but to no avail. Furthermore, the stacktrace in Sentry states the error is coming from our app, but we have no property "metadata" in our code.

Any thoughts or insight would be appreciated.

Thank you!

@segment/analytics-next still uses vulnerable version of [email protected]

The problem

@segment/analytics-next still uses vulnerable version of [email protected]

npm audit in my project fails due to having vulnerable version of [email protected].

More info about vulnerability is here: GHSA-r683-j2x4-v87g

I found that @segment/analytics-next in my node_modules still uses [email protected].

However, when you check the version in the analytics-next repository's package.json, there is [email protected] (https://github.com/segmentio/analytics-next/blob/master/package.json#L62).

How to reproduce the issue?

  1. Create a new project using npm init
  2. Run npm i @segment/analytics-next@latest
  3. Run:
cat node_modules/@segment/analytics-next/package.json | grep "\"node-fetch\""
    "node-fetch": "^2.6.1",

You can see the problem in this repo as well: https://github.com/grzegorz-zadora/analytics-vuln/blob/master/node_modules/%40segment/analytics-next/package.json#L62

It seems like it's due to a failing build here: https://buildkite.com/segment/analytics-next/builds/32390 (commit: f310f83)

Expected behavior

After installing npm i @segment/analytics-next@latest it should use [email protected] in its package.json.

Regression in functionality of `trackLink` between v1 and v2

While attempting to upgrade to using the new Segment Analytics 2.0 library I ran into a change in behavior in how the trackLink helper works.

For our use case we are attaching the trackLink method to DIV elements to track interactions within client side features that are not actually anchor elements and do not contain a href property we ever intend to direct the browser to.

This functionality is fully supported in the classic Analytics.js library as it would simply initiate a track call, then wait 300ms only if it found a href property on the direct element you called the original trackLink method on. See: https://github.com/segmentio/analytics.js-core/blob/da691296b4a184271f85677962fc19741988c0f3/lib/analytics.ts#L484

This functionality has significantly changed in the 2.0 library. It seems the new behavior is to take the element passed into trackLink and find ANY descendent A element that has an href property and treat that link as if the user actually clicked on it. Needless to say, this can lead to significant unintended consequences. See:

el.getElementsByTagName('a')[0]?.getAttribute('href')

So my question is, is this new change in functionality actually intended?

If so, I feel this is a significant regression and should be called out in the migration guide: https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/upgrade-to-ajs2/

Support for multiple write keys.

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.

Proxy HTTP(s) Calls

Is there any way to configure analytics-next to point to your own hosted proxy of the Segment API? It seems like the iOS library has this capability and I was wondering if this library has a way to do that.

Timeout not working

I cloned this repository and started up the local dev environment for testing events.

I updated the track event to output the default timeout setting and add timing events to the console:

    // @ts-ignore
    console.log(analytics.settings)
    console.time('track')
    const ctx = await analytics.track(evt?.event ?? 'Track Event', evt)
    console.timeEnd('track')

analytics.settings.timeout is set to the default 300ms, but the track call returns after 60ms:

track: 59.259765625 ms

If I add a callback to the track call, the time is essentially the same:

const ctx = await analytics.track(evt?.event ?? 'Track Event', evt, null, () => { console.timeLog('track')})

I also don't have any luck changing the timeout with window.analytics.timeout(1000) or passing it into AnalyticsBrowser.load

Is setting the default timeout supported?

Make HTTP headers configurable

We want to use our backend as a proxy to Segment API in order to bypass ad-blockers. We have CSRF protection in place so all requests to our endpoints need to contain X-CSRF-TOKEN header. But @segment/analytics-next library doesn't enable us to set custom HTTP headers.

It looks like headers are hardcoded in fetch-dispatcher and it's been like in a predecessor of this library (see segmentio/analytics.js-integrations#560).

Can you add a new configuration property which will allow us to append additional HTTP headers? Other people are asking for it as well, see #312 (comment).

Uncaught Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code.

I'm using vite with [email protected]. This error message shows up in the console when I'm in dev mode trying to load analytics-next.

vite doesn't polyfill nodejs modules and node-fetch requires node:stream.

analytics-next loads src/node which requires and loads node-fetch.

I'm not exactly sure what analytics-node is. I'd guess it's a node wrapper so you can call analytics-next from node server side? Anyhow, is there a way to make the plugin optional as well as the node-fetch dependency for analytics-next?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.