Skip to content

Analytics: Fix - Prevent multiple SDK initializations#2112

Open
cmgustavo wants to merge 1 commit intobitpay:developfrom
cmgustavo:bug/prevent-multiple-analytics-initializations-01
Open

Analytics: Fix - Prevent multiple SDK initializations#2112
cmgustavo wants to merge 1 commit intobitpay:developfrom
cmgustavo:bug/prevent-multiple-analytics-initializations-01

Conversation

@cmgustavo
Copy link
Copy Markdown
Member

@cmgustavo cmgustavo commented Apr 1, 2026

RN-2412

changes

  • Multiple calls to initialize() will reuse the same promise
  • SDK initialization is guaranteed to run only once
  • Subsequent calls will await the ongoing initialization instead of re-triggering it
  • Modified getTrackingAuthorizedByUser() to use async/await and properly waits for the tracking permission
  • Removed redundant Analytics.initialize() calls from UI-level handlers to avoid unintended re-initialization attempts

@cmgustavo cmgustavo changed the title Analytics: Bug - Prevent multiple SDK initializations Analytics: Fix - Prevent multiple SDK initializations Apr 1, 2026
@JohnathanWhite JohnathanWhite changed the base branch from master to develop April 2, 2026 22:49
@cmgustavo cmgustavo force-pushed the bug/prevent-multiple-analytics-initializations-01 branch 3 times, most recently from 800c771 to 81029c7 Compare April 9, 2026 21:51

return;
logManager.info('Successfully initialized analytics.');
} finally {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a catch here:

catch (err) {
          const errMsg =
            err instanceof Error ? err.message : JSON.stringify(err);
          logManager.error(`[Analytics] init failed: ${errMsg}`);
        }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary since each individual SDK init has already try/catch in lines 98, 111, and 139.

const flushQueue = () => {
const queue = _preInitQueue;
_preInitQueue = [];
queue.forEach(cb => cb());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a catch here for the queue:

  queue.forEach(cb => {
      try {
        cb();
      } catch (err) {
        const errMsg = err instanceof Error ? err.message : JSON.stringify(err);
        logManager.error(`[Analytics] Error executing queued event: ${errMsg}`);
      }
    });

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only useful if it’s written to handle async rejections, not just sync exceptions

Comment thread src/store/analytics/analytics.effects.ts Outdated
@cmgustavo cmgustavo force-pushed the bug/prevent-multiple-analytics-initializations-01 branch from 81029c7 to e894f11 Compare April 17, 2026 16:15
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.

2 participants