3

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 Answers 3

1
ReactGA.set({ checkProtocolTask: null }) // Disable file protocol checking.
1
  • This got me past the "Unallowed document protocol. Aborting hit" error but now I'm getting "Storage not available. Aborting hit".
    – Tom
    Commented Sep 23, 2021 at 21:06
0

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

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."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.