rnc-archive / react-native-google-analytics

Google Analytics for React Native! Compatible with react-native-ab

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unsupported BodyInit type

igorregis opened this issue · comments

I am receiving this unhandled promise rejection message.

I have tried to change the send function from the Analytics class, but when I add a body with a content, the Google Analytics stop computing the hits.

I coded this class to send my hits, as far as I can tell, there is nothing wrong with it:

Obs.: As you can see I have tried to catch the promise rejection, but it seens to be pointeless as it ignore my catch. (There is this issue into react-native about this behaviour but the cause was not the same: facebook/react-native#2538)

export class Analytics {
  constructor(props) {
    let clientId = ConfigRepo.getInstance().FirebaseAuth.currentUser.uid;
    let userAgent = DeviceInfo.getUserAgent();
    this.ga = new GA('UA-00000000-0', clientId, 1, userAgent);
  }

  sendScreenView(viewName: String) {
    var screenView = new GAHits.ScreenView(
      'AppName',
      viewName,
      version,
      DeviceInfo.getBundleId()
    );
    this.ga.send(screenView).catch(e => console.log(e));
  }

Just woke up this morning and realised that the error is happening when the fetch library tries do build google analytics response. As you can see below after response it calls the initBody and then the error happens because it can't parse the response body.

Nov 26 12:45:36 SFOLAPMAC002 estamosquitesreact[66554] <Warning>: -[SMXCrashlytics log:] line 19 $  Possible Unhandled Promise Rejection (id: 0):
	unsupported BodyInit type
	_initBody@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:29469:16
	Response@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:29623:15
	onload@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:29689:21
	dispatchEvent@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:83275:13
	responseDataReady@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:83130:21
	_onDone@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:83156:18
	_onDone@[native code]
	tryCallOne@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:30378:10
	http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:30464:19
	callTimer@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:4016:9
	callImmediatesPass@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:4120:28
	callImmediates@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:4135:43
	guard@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:3657:3
	__callImmediates@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:3825:6
	http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:3739:24
	guard@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:3657:3
	invokeCallbackAndReturnFlushedQueue@http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:3737:6
	invokeCallbackAndReturnFlushedQueue@[native code]

Never mind. I found the cause. I am using a polyfill that enable me to upload blob files to Firebase Storage and this polyfill is causing the error.