Configuring Gimbal Place
Setting Gimbal Place attributes as tags in Airship first requires you to do some configuring in your Gimbal Manager for the Gimbal Place you have set up. To do so, begin by either editing an existing Place, or create a new Gimbal Place.
- Ensure that either a Beacon or Geofence is configured in your Gimbal place.
- Under Attributes, set a Key for the app to identify the tag and set the Value as the tag you wish to add in Airship.
- Click the Update Place button
- (For iOS) Using the Gimbal Adapter class, provided in our documentation on Airship Gimbal Adapters, modify the didBeginVisit and didEndVisit methods to add or remove a tag from the device when a Gimbal Place has been visited or exited.
- (void)placeManager:(GMBLPlaceManager *)manager didBeginVisit:(GMBLVisit *)visit {
UA_LDEBUG(@"Entered a Gimbal Place: %@ on the following date: %@", visit.place.name, visit.arrivalDate);
if ([visit.place.name isEqual: @"<Name_of_place_in_Gimbal"]) //Make sure you place the name you gave the Gimbal Place here
{
[[UAirship push] addTag:[visit.place.attributes stringForKey:@"Addtag1"]];
}
[self reportPlaceEventToAnalytics:visit.place boundaryEvent:UABoundaryEventEnter];
}
- (void)placeManager:(GMBLPlaceManager *)manager didEndVisit:(GMBLVisit *)visit {
UA_LDEBUG(@"Exited a Gimbal Place: %@ Entrance date:%@ Exit Date:%@", visit.place.name, visit.arrivalDate, visit.departureDate);
if ([visit.place.name isEqual: @"<Name_of_place_in_Gimbal>"]) //Make sure you place the name you gave the Gimbal Place here
{
[[UAirship push] removeTag:[visit.place.attributes stringForKey:@"AddTag1"]];
}
[self reportPlaceEventToAnalytics:visit.place boundaryEvent:UABoundaryEventExit];
}
5. (For Android) Using the Gimbal Adapter class, provided in our documentation on Airship Gimbal Adapters, modify the OnVisitBegin and OnVisitEnd methods to add or remove a tag from the device when a Gimbal Place has been visited or exited.
/**
* GimbalAdapter visited attribute key.
*/
private static final String VISITED_ATTRIBUTE_KEY = "AddTag1";
private PlaceEventListener placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
Log.i(TAG, "Entered place: " + visit.getPlace().getName() + "Entrance date: " + DateUtils.createIso8601TimeStamp(visit.getArrivalTimeInMillis()));
UAirship.shared(new UAirship.OnReadyCallback() {
@Override
public void onAirshipReady(UAirship airship) {
RegionEvent enter = new RegionEvent(visit.getPlace().getIdentifier(), SOURCE, RegionEvent.BOUNDARY_EVENT_ENTER);
airship.getAnalytics().addEvent(enter);
Attributes attributes = visit.getPlace().getAttributes();
if (attributes != null) {
UAirship.shared().getPushManager().editTags() // Update current tag set with current tags
.addTag(attributes.getValue(VISITED_ATTRIBUTE_KEY))
.apply();
}
synchronized (listeners) {
for (Listener listener : new ArrayList<>(listeners)) {
listener.onRegionEntered(enter, visit);
}
}
}
});
}
@Override
public void onVisitEnd(Visit visit) {
Log.i(TAG, "Exited place: " + visit.getPlace().getName() + "Entrance date: " + DateUtils.createIso8601TimeStamp(visit.getArrivalTimeInMillis()) + "Exit date:" + DateUtils.createIso8601TimeStamp(visit.getDepartureTimeInMillis()));
UAirship.shared(new UAirship.OnReadyCallback() {
@Override
public void onAirshipReady(UAirship airship) {
RegionEvent exit = new RegionEvent(visit.getPlace().getIdentifier(), SOURCE, RegionEvent.BOUNDARY_EVENT_EXIT);
airship.getAnalytics().addEvent(exit);
if (attributes != null) {
UAirship.shared().getPushManager().editTags() // Update current tag set with current tags
.removeTag(attributes.getValue(VISITED_ATTRIBUTE_KEY))
.apply();
}
synchronized (listeners) {
for (Listener listener : new ArrayList<>(listeners)) {
listener.onRegionExited(exit, visit);
}
}
}
});
}
};
6. Make sure you've followed the other Gimbal & Airship steps to get set up and that's all there is to it!