amplitude/Amplitude-TypeScript

track does not work when react native fetch promise hangs

cainlevy opened this issue · 5 comments

Expected Behavior

I can use the Amplitude library to track events and see the data in my Ingestion Debugger.

Current Behavior

Nothing. The promises returned from every track hang without resolving or rejecting.

Possible Solution

I haven't tried replacing transportProvider with something besides fetch. That might work?

Steps to Reproduce

I traced the problem through the @amplitude packages down to the implementation of fetch in @amplitude/analytics-client-common/src/transports/fetch. I lifted that implementation up to my own code and narrowed the problem down all the way to:

// curl'ing this from my computer returns:
// {"code":400,"error":"Missing request body"}
fetch('https://api2.amplitude.com/2/httpapi')
  .then(console.log, console.error);

This will never log or error. By comparison, another well known domain will resolve and log instantly:

fetch('https://google.com')
  .then(console.log, console.error);

Environment

  • JS SDK Version: @amplitude/analytics-react-native@1.1.7
  • Installation Method: npm
  • Browser and Version: react-native@0.69.7

This may be an issue with the api2.amplitude.com domain specifically.

// ⛔  hangs
fetch('https://api2.amplitude.com').then(console.log, console.error);

// ✅  resolves
fetch('https://amplitude.com').then(console.log, console.error);

// ✅  rejects immediately with a 400 error
fetch('https://api.eu.amplitude.com/2/httpapi').then(
  console.log,
  console.error,
); 

It appears that fetch('https://api2.amplitude.com') works again after upgrading React Native from 0.69 to 0.71. Not sure what that implies.

Hi @cainlevy thanks for reporting this issue. To confirm everything is working again for you using RN 0.71?

Yes, that's right. I'm not sure if you consider this worth investigating for users on older versions of RN, but I'm no longer stuck.

Thanks for confirming. I am going to close this since it seems tied to the RN version.