Skip to content

Push tokens

Affise.addPushToken(pushToken: string, service: PushTokenService)
// src/index.ts:63-65

Native dispatch: AffiseNative.addPushToken (src/native/AffiseNative.ts:71-77) maps to AffiseApiMethod.ADD_PUSH_TOKEN = "add_push_token" (src/native/AffiseApiMethod.ts:7).

From src/settings/PushTokenService.ts:1-4:

export enum PushTokenService {
FIREBASE = "fms",
APPLE = "apns",
}
import { Affise, PushTokenService } from 'affise-attribution-lib';
import firebase from '@react-native-firebase/app';
import messaging from '@react-native-firebase/messaging';
async function firebaseSetup() {
const credentials = {
appId: '',
projectId: '',
// ...
};
await firebase.initializeApp(credentials);
}
function getToken() {
messaging().getToken().then((fcmToken) => {
Affise.addPushToken(fcmToken, PushTokenService.FIREBASE);
});
}

For iOS the APNs token is acquired by native Swift/Objective-C code in the AppDelegate and forwarded to Affise.addPushToken(pushToken, .APPLE).

Affise automatically track reinstall events by using silent-push technology, to make this feature work, pass push token when it is recreated by user and on you application starts up

Pass the push token along with the PushTokenService (two required arguments — src/index.ts:63-64):

Affise.addPushToken(token, PushTokenService.FIREBASE); // or PushTokenService.APPLE