segmentio / analytics-react-native

The hassle-free way to add analytics to your React-Native app.
https://segment.com/docs/sources/mobile/react-native/
MIT License
367 stars 191 forks source link

Android install instructions #591

Closed rborn closed 2 years ago

rborn commented 2 years ago

Hello,

I'm trying to upgrade from 1.5.1 to 2.3.2 but for some reason I don't seem to be able to see any events in Segment debugger when I build for android.

I see that in the example folder the MainApplication.java file has some packages added, but there is no mention in the current readme about this.

The old docs (V1) had this: https://github.com/segmentio/analytics-react-native/tree/analytics-react-native-v1#android

Thank you

Steps to reproduce

Install as per docs, build, segment debugger won't show any event tracked for the device

Expected behavior

We should see events in debugger

Actual behavior

No events are tracked,

NoRoboto commented 2 years ago

I think this is not related to missing step in the configuration, it's more on the sdk side.

After spending several hours debugging what is happening, is decided to create a new project, but the problem persists, found that the request to the service:

https://cdn-settings.segment.com/v1/projects/<your_key>/settings fails with the following error:

Could not receive settings from Segment. Device mode destinations will be ignored unless you specify default settings in the client config.

I decided to perform this same fetch without using the sdk and the result is the same in the android application, followed the following recommendations without success:

On the other hand, this is what logcat throws: No valid NAT64 prefix after fetch call.

Could it be that this issue is caused by a misconfiguration in the DNS of the host? I found a very similar issue

This is the code used for testing:

import React from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';

import {createClient} from '@segment/analytics-react-native';

const segmentClient = createClient({
  writeKey: 'xxxx',
  trackAppLifecycleEvents: true,
});

const App = () => {
  return (
    <View style={styles.sectionContainer}>
      <Text>Hola</Text>
      <Button
        title="press me"
        onPress={async () => {
          const data = await fetch(
           // 'https://cdn-settings.segment.com/v1/projects/xxx/settings' also fails
            'https://cdn.segment.com/v1/projects/xxx/settings',
          );
          console.log('data', await data.json());
        }}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  sectionContainer: {
    margin: 32,
    flex: 1,
    justifyContent: 'center',
    alignContent: 'center',
  },
});

export default App;

Note: Other fetch calls work fine in the same app, for example: fetch(https://api.github.com/users/noroboto);

rborn commented 2 years ago

Should we rename the issues then ?

rborn commented 2 years ago

Also is there any workaround? basically this invalidates the library on android 😅

alanjcharles commented 2 years ago

@rborn @NoRoboto Apologies, it seems there may have been a caching issue on the settings endpoint side. Can you let me know if you're still running into this? Thanks!

rborn commented 2 years ago

@alanjcharles thanks for getting back to us. Sadly I still have the issue.

The logs show the app tracking correctly, but I don't see anything in my debugger view. I've set the apikey correctly, set flushInterval , flushAt to 1, but still nothing

INFO  IDENTIFY event saved {"traits": {}, "type": "identify", "userId": "VVvVX6OlxcW5e7X1tma5_blah"}
INFO  SCREEN event saved {"name": "Home", "properties": {}, "type": "screen"}

INFO  IDENTIFY event saved {"traits": {}, "type": "identify", "userId": "VVvVX6OlxcW5e7X1_blah"}
INFO  TRACK event saved {"event": "tabChange", "properties": {"screen": "Home"}, "type": "track"}

A fetch to the settings endpoint seems to work fine and I also have the message Received settings from Segment succesfully. on app load.

This is my config

        Analytics = createClient({
            writeKey: configuration.apiKeys.segmentio,
            autoAddSegmentDestination: false,
            trackAppLifecycleEvents: true,
            trackAttributionData: true,
            debug: true,
            flushInterval: 1,
            flushAt: 1
            trackDeepLinks: true
        });

Any idea? 😄 Thank you 🙏

NoRoboto commented 2 years ago

@rborn I did some tests for some of our users and they have no problems using the latest sdk (located in Canada and the United States), but for me (I'm in Latin America) I don't see traffic from my requests (just like using VPN for the US). I don't know if it's due to a geographic zone restriction.

rborn commented 2 years ago

@NoRoboto I'm in Spain and the old version works.

@alanjcharles any news on this? Google is forcing us to move to v2 that respects the new Data Policy and the deadline is pretty close 😅

I also tested on iOS and I have exactly the same, local logs show fine, I see no data in the online debugger. ( I thought iOS works, but it seems is not)

Thank you 🙏

rborn commented 2 years ago

@alanjcharles sorry to be a pain, is there any way I could debug this or at least find a workaround? Thank you

rborn commented 2 years ago

So I feel kind of dumb 😅 I had autoAddSegmentDestination: false, in config, but to my defence it doesn't say anywhere it will disable Segment entirely, so maybe the docs should be updated?

Anyway, closing and sorry for the mess