3
votes

I have made an app using React (Web) and bundled it using Cordova.

I am using a plugin called 'react-ga' for tracking Google Analytics.

I initialise react-ga when the app is run using:

ReactGA.initialize('my-ga-uid', { debug: true, cookieDomain: 'auto' })

And create an event using something like:

ReactGA.event({
  category: 'Test',
  action: 'Test button pressed event.'
})

or,

ReactGA.set({ location.pathname })
ReactGA.pageview(location.pathname)

The analytics work fine in the browser and on dev builds, however when I bundle a build for iOS or Android, the analytics don't seem to be tracked?

Is there something wrong with my code? Do I need to initialise something else? Do I need a cordova plugin instead (although I want analytics to still work in a web browser)?

3

3 Answers

1
votes
ReactGA.set({ checkProtocolTask: null }) // Disable file protocol checking.
0
votes

You may need to create a GA property for your mobile app that is a separate property from your website. When you set up a new property, you have the option to choose between a website and a mobile app.

0
votes

I was using ReactGA in an Android webview:

I needed to do the following:

  ReactGA.set({ checkProtocolTask: null, checkStorageTask: null })

to get passed the following errors:

"Unallowed document protocol. Aborting hit" 
"Storage not available. Aborting hit."