terveystalo / react-native-piwik-pro-sdk

React Native wrapper for Piwik Pro SDK
https://www.npmjs.com/package/react-native-piwik-pro-sdk
MIT License
2 stars 2 forks source link

Tracker already initialized warnings in dev mode #30

Open aeirola opened 4 years ago

aeirola commented 4 years ago

When running an app in development mode, the library will likely complain about Tracker already initialized errors on app refreshes. This is due to the fact that the iOS native SDK does not support being initialised more than once (https://github.com/PiwikPRO/piwik-pro-sdk-demo-ios/issues/1).

The best fix would be for the native SDK to support re-initialisation, but until that happens it would be nice for this library to provide some way of handling the errors in development mode.

aeirola commented 3 years ago

Until we have a better solution at the library level, a simple local workaround for this looks something like this:

  piwikPro
    .init(config.apiUrl, config.siteId)
    .catch(error => {
      // Development server refresh will re-initialized the tracker
      // Catch re-init errors for nicer devleoper experience
      if (__DEV__ && error.message === 'Tracker already initialized') {
        return;
      }
      console.warn('Failed to initialize Piwik tracker', error);
    });