Segment trackEvent doesn't work right after CodePush update installs

221 Views Asked by At

Our React Native project has both Segment and CodePush integrated.

Segment works fine, normally.

But there's a scenario where Segment stops working right after a CodePush update has been installed. Nothing gets flushed out and none of the events are shown in the Live Debugger list - except for events that are tracked in the native layer (eg: "Application Opened" and "Application Backgrounded" - only these show up).

So I assumed that any Segment call in the RN - Javascript layer only stops working after the app restarts the bundle (by CodePush).

The user should close and kill the app and reopen the app for it to work normally again.

Happens to both iOS and Android (when installed from the store).

And weirdly enough, I cannot recreate the issue on Android when I run a debug or release build directly to my Android phone from my machine (it just works ‍♂️). Same goes for iOS simulators.

Any ideas or workarounds on this?


This is how the setup looks like:

import React, { Component } from "react";
import CodePush from "react-native-code-push";
import segment from "@segment/analytics-react-native";

...

class App extends Component {

    constructor(props) {
        super(props);

        this.setupSegment();
    }

    private setupSegment(): void {
        segment.setup("<Segment Write Key>", {
            debug: true,
            trackAppLifecycleEvents: true,
            ios: {
                trackAdvertising: true
            }
        });
    }

    ...
}

export default CodePush({
    installMode: CodePush.InstallMode.IMMEDIATE,
    checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
    updateDialog: null
})(App);

react-native: 0.61.5
react-native-code-push: 6.1.0
@segment/analytics-react-native: 1.1.1-beta.2 (also tried 1.1.1-beta.5)
0

There are 0 best solutions below