Skip to content

add ability to get user from initialize #1286

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

silesky
Copy link
Contributor

@silesky silesky commented Apr 30, 2025

This doesn't work:

      analytics.on('initialize', () =>  {
         user = analytics.user();
         console.log(user)
});

image

Currently, this works, but the semantics of .ready() means that it is not resilient to failed plugins. analytics.initialize should get the analytics instance as soon as its available, and all critical plugins are registered.

      analytics.ready(() => {
         console.log(analytics.user())
  });

If you just need access to the user in a way that is resillient to failed plugins, you can still do:

  analytics.register({
      type: 'utility',
      load(_ctx, analytics) {
             console.log(analytics.user()) 
       }
  })

Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: f8e54f6

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-next Minor

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

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.87%. Comparing base (6483541) to head (f8e54f6).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1286   +/-   ##
=======================================
  Coverage   82.87%   82.87%           
=======================================
  Files         225      225           
  Lines        6019     6019           
  Branches     1365     1365           
=======================================
  Hits         4988     4988           
  Misses       1031     1031           
Flag Coverage Δ
browser 92.21% <100.00%> (ø)
core 89.86% <ø> (ø)
node 87.93% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@silesky silesky marked this pull request as draft April 30, 2025 20:55
@silesky silesky requested a review from pooyaj April 30, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant