Home and Work Detection

After 3-7 days of use the SDK will determine the user’s home and work location. You can see if this has been set by checking the hasHomeOrWork property.

PilgrimManager.shared().hasHomeOrWork()
FrequentLocations.hasHomeOrWork(context)

Note: It’s possible that you won’t want to process any visits or only trust visits that have a ‘High’ confidence until home/work has been set. This is due to the fact that a user’s home is not in our venue database, so we may be attributing ‘home’ visits to a venue nearby until we learn that this is in fact their home. An example of this simple check on iOS is below:

func pilgrimManager(_ pilgrimManager: PilgrimManager, didVisit visit: Visit) {
    if pilgrimManager.hasHomeOrWork() {

        // Home and work are set. Lets print them out
        print(pilgrimManager.homeLocations)
        print(pilgrimManager.workLocations)

    } else if visit.confidence != .high {
        // Home and work aren't set and visit confidence isn't High
        // Depending on my application I might not want to trust this visit
    }
}

Other Possible Venues

By default, Pilgrim only returns the single venue that it believes the device is at. There is also a setting to return 4 alternate places (ordered by confidence) for arrival events. To enable these other venues, there is a checkbox on the Pilgrim Console of your Foursquare Developer account that you can turn on to begin to receiving these venues.

Once enabled, you can access the other places as follows:

func pilgrimManager(_ pilgrimManager: PilgrimManager, didVisit visit: Visit) {
    let otherVenues = visit.otherPossibleVenues
    // Do something with the alternate venues
}
protected static final PilgrimNotificationHandler pilgrimNotificationHandler = new PilgrimNotificationHandler() {
    @Override
    public void handlePlaceNotification(Context context, PilgrimSdkPlaceNotification notif) {
        CurrentPlace currentPlace = notif.getCurrentPlace();
        List<Venue> otherVenues = currentPlace.getOtherPossibleVenues();
        // Do something with the alternate venues
    }
}

Custom User Data

On occasion, you may want to send custom user data into Pilgrim to pass along to another server or service. This is common if you want to tie a Pilgrim event to a specific user in your own database or in a third-party MMA integration. Once set, the custom user data will be passed along within our webhook payload.

Where to set

Ideally, the user info should be set in Application#onCreate (for Android) or in the AppDelegate’s didFinishLaunchingWithOptions (for iOS). Setting it in other locations of your app could result in only sending the user info once that specific process is open. If the app ever dies or the user closes the app, the next time Pilgrim wakes the app up, the value may not be stored (and thus not get sent to the webhook or MMA). The Pilgrim SDK doesn’t persist the userInfo dictionary, it needs to be set every time.

If setting the user info in the Application#onCreate or AppDelegate’s didFinishLaunchingWithOptions is not feasible, the general recommendation is that you set it as soon as you have a way to identify your user (upon logging in or once you have their session in the app).

It is also important to remember that while you are not responsible for if a user revokes location permissions, you’ll probably want to stop Pilgrim if a user logs out of their account within the app; otherwise, you’ll receive visits without any user associated.

Examples

// NOTE: the below code should be placed AFTER you set up the SDK (ideally in AppDelegate's didFinishLaunchingWithOptions) using PilgrimManager.configure(...)

let userInfo = UserInfo()
// the String myCustomUserId would be a previously set variable that stores the user's unique id:
userInfo.setUserId(myCustomUserId)
// You can also set other custom fields using:
userInfo.setUserInfo("My custom value", forKey: "myCustomField")
// Starting in v2.1.2, you have the ability to persist userinfo across sessions:
PilgrimManager.shared().setUserInfo(userInfo, persisted: true)

// To unset persisted fields:
PilgrimManager.shared().setUserInfo(nil, persisted: true)
// NOTE: the below code should be placed AFTER you set up the SDK (ideally in AppDelegate's didFinishLaunchingWithOptions) using [[FSQPPilgrimManager sharedManager] configureWith...]

FSQPUserInfo *userInfo = [[FSQPUserInfo alloc] init];
// the String myCustomUserId would be a previously set variable that stores the user's unique id:
[userInfo setUserId:myCustomUserId];
// You can also set other custom fields using:
[userInfo setUserInfo:myCustomField forKey: @"myCustomField"];
// Starting in v2.1.2, you have the ability to persist userinfo across sessions:
[[FSQPPilgrimManager sharedManager] setUserInfo:userInfo persisted:YES];

// To unset persisted fields:
[[FSQPPilgrimManager sharedManager] setUserInfo:nil persisted:YES];
// NOTE: the below code should be placed AFTER you set up the SDK (ideally in Application#onCreate) using PilgrimSdk.with(builder);

PilgrimUserInfo userInfo = new PilgrimUserInfo();
// the String myCustomUserId would be a previously set variable that stores the user's unique id:
userInfo.setUserId(myCustomUserId);
// You can also set other custom fields using:
userInfo.put("myCustomField", "My custom value");
// Starting in v2.1.2, you have the ability to persist userinfo across sessions:
PilgrimSdk.get().setUserInfo(userInfo, persisted: true);

// To unset persisted fields:
PilgrimSdk.get().setUserInfo(null, persisted: true)
// NOTE: the below code should be placed AFTER you set up the SDK (ideally in Application#onCreate) using PilgrimSdk.with(builder);

val userInfo = PilgrimUserInfo().apply {
    // the String myCustomUserId would be a previously set variable that stores the user's unique id:
    setUserId(myCustomUserId)

    // You can also set other custom fields using:
    set("myCustomField", "My custom value")
}
// Starting in v2.1.2, you have the ability to persist userinfo across sessions:
PilgrimSdk.get().setUserInfo(userInfo, persisted: true)

// To unset persisted fields:
PilgrimSdk.get().setUserInfo(null, persisted: true)

Testing

The best and quickest way to test and confirm that you are accurately setting the custom user data is to set up and test via our webhook. If you do not already have webhook ingestion set up, you can easily use a tool called ngrok, which can be used to create a tunnel to monitor activity on your local dev machine.


Venue Harmonization

If you maintain your own venue database, you may want to know if a visit has occurred at one of those venues. We have a guide for venue harmonization in our API documentation, but we can also store a copy of the harmonization and return your venue Id in the Pilgrim visit callback. We enable this on a parter-by-partner basis, please contact us if you feel like this feature should be enabled for you. Once enabled, you will start seeing your venue Ids returned for visits where we have a mapping.

func pilgrimManager(_ pilgrimManager: PilgrimManager, didVisit visit: Visit) {
    let partnerId = visit.venue?.partnerVenueId
    // Do something with your own venue Id
}
protected static final PilgrimNotificationHandler pilgrimNotificationHandler = new PilgrimNotificationHandler() {
    @Override
    public void handlePlaceNotification(Context context, PilgrimSdkPlaceNotification notif) {
        String partnerId = notif.getContentId();
        // Do something with your own venue Id
    }
}

Next Steps

Check out the Changelog for the latest updates.

Changelog

Was this page helpful?
Yes
No
Thank you!