Add Features

Get User's Install ID

Each time Pilgrim is installed on a user's device, Pilgrim creates a unique installId. The returned value will be a Promise<string>. This can be used to allow your users to submit Data Erasure Requests or for debugging in our Event Logs tool in your developer console. Example usage:

import React, { Component } from 'react';
import { Text } from 'react-native';
import PilgrimSdk from '@foursquare/pilgrim-sdk-react-native';

export default class MyScreen extends Component {
  state = {
    installId: '-',
  };

  componentDidMount() {
    PilgrimSdk.getInstallId().then(installId => {
      this.setState({ installId: installId });
    });
  }

  render() {
    return (
      <>
        <Text>Install ID: {this.state.installId}</Text>
      </>
    );
  }
}

Get User's Current Location

You can actively request the current location of the user by calling the PilgrimSdk.getCurrentLocation method. The return value will be a Promise<CurrentLocation>. The CurrentLocation object has the current venue the device is most likely at as well as any geofences that the device is in (if configured). More information here. Example usage:

import React, { Component } from 'react';
import { Alert, Text } from 'react-native';
import PilgrimSdk from '@foursquare/pilgrim-sdk-react-native';

export default class MyScreen extends Component {
  state = {
    currentLocation: null,
  };

  getCurrentLocation = async function() {
    try {
      const currentLocation = await PilgrimSdk.getCurrentLocation();
      this.setState({ currentLocation: currentLocation });
    } catch (e) {
      Alert.alert('Pilgrim SDK', `${e}`);
    }
  };

  componentDidMount() {
    this.getCurrentLocation();
  }

  render() {
    if (this.state.currentLocation != null) {
      const venue = this.state.currentLocation.currentPlace.venue;
      const venueName = venue.name || 'Unnamed venue';
      return (
        <>
          <Text>Venue: {venueName}</Text>
        </>
      );
    } else {
      return (
        <>
          <Text>Loading...</Text>
        </>
      );
    }
  }
}

Passive Location Detection

Passive location detection is controlled with the PilgrimSdk.start and PilgrimSdk.stop methods. When started, Pilgrim SDK will send notifications to Webhooks and other third-party integrations.

Example usage:

import React, { Component } from 'react';
import { Alert, Button } from 'react-native';
import PilgrimSdk from '@foursquare/pilgrim-sdk-react-native';

export default class MyScreen extends Component {
  startPilgrim = async function() {
    const canEnable = await PilgrimSdk.canEnable();
    const isSupportedDevice = await PilgrimSdk.isSupportedDevice();
    if (canEnable && isSupportedDevice) {
      PilgrimSdk.start();
      Alert.alert('Pilrim SDK', 'Pilgrim started');
    } else {
      Alert.alert('Pilrim SDK', 'Error starting');
    }
  };

  stopPilgrim = function() {
    PilgrimSdk.stop();
    Alert.alert('Pilrim SDK', 'Pilgrim stopped');
  };

  render() {
    return (
      <>
        <Button
          title="Start"
          onPress={() => {
            this.startPilgrim();
          }}
        />
        <Button
          title="Stop"
          onPress={() => {
            this.stopPilgrim();
          }}
        />
      </>
    );
  }
}

Note: If you wish to handle background notifications locally on the device, you will need to add the notification handler and delegate in the native piece of each platform, as mentioned in the Installation instructions.


Did this page help you?