Adding Gimbal Place attributes as Tags in Urban Airship

Configuring Gimbal Place

Setting Gimbal Place attributes as tags in Urban 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.

  1. Ensure that either a Beacon or Geofence is configured in your Gimbal place.
  2. Under Attributes, set a Key for the app to identify the tag and set the Value as the tag you wish to add in Urban Airship.Gimbal_Manager.png
  3. Click the +Add button
  4. (For iOS) Using the Gimbal Adapter class, provided in our documentation on Urban 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 Urban 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 = "GimbalUAVisitedTag";

    /**
     * GimbalAdapter entered attribute key.
     */
    private static final String ENTERED_ATTRIBUTE_KEY = "GimbalUAEnteredTag";

    /**
     * GimbalAdapter exited attribute key.
     */
    private static final String EXITED_ATTRIBUTE_KEY = "GimbalUAExitedTag";

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()));           

RegionEvent enter = new RegionEvent(visit.getPlace().getIdentifier(), SOURCE, RegionEvent.BOUNDARY_EVENT_ENTER);           

UAirship.shared().getAnalytics().addEvent(enter);           

RecordPlaceTask.recordPlace(visit.getPlace(), RegionEvent.BOUNDARY_EVENT_ENTER, visit.getArrivalTimeInMillis());           

Attributes attributes = visit.getPlace().getAttributes();           

if (attributes != null)
{               
// Update current tag set with current tags               
Set<String> tags = UAirship.shared().getPushManager().getTags();               

// Remove Exited tag if one exists in place attributes under EXITED_ATTRIBUTE_KEY               
tags.remove(attributes.getValue(EXITED_ATTRIBUTE_KEY));               

// Add Visited tag if one exists in place attributes under VISITED_ATTRIBUTE_KEY               
if (attributes.getValue(VISITED_ATTRIBUTE_KEY) != null) {                   
tags.add(attributes.getValue(VISITED_ATTRIBUTE_KEY));               
}               

// Add Entered tag if one exists in place attributes under ENTERED_ATTRIBUTE_KEY               
if (attributes.getValue(ENTERED_ATTRIBUTE_KEY) != null) {                   
tags.add(attributes.getValue(ENTERED_ATTRIBUTE_KEY));               
}               
// Set the tags               
UAirship.shared().getPushManager().setTags(tags);           
}       
}
       
@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()));           

RegionEvent exit = new RegionEvent(visit.getPlace().getIdentifier(), SOURCE, RegionEvent.BOUNDARY_EVENT_EXIT);           

UAirship.shared().getAnalytics().addEvent(exit);           

RecordPlaceTask.recordPlace(visit.getPlace(), RegionEvent.BOUNDARY_EVENT_EXIT, visit.getDepartureTimeInMillis());           

Attributes attributes = visit.getPlace().getAttributes();           

if (attributes != null) {               
// Update current tag set with current tags               
Set<String> tags = UAirship.shared().getPushManager().getTags();               

// Remove Entered tag if one exists in place attributes under ENTERED_ATTRIBUTE_KEY               
tags.remove(attributes.getValue(ENTERED_ATTRIBUTE_KEY));               

// Add Exited tag if one exists in place attributes under EXITED_ATTRIBUTE_KEY               
if (attributes.getValue(EXITED_ATTRIBUTE_KEY) != null) {  
                  tags.add(attributes.getValue(EXITED_ATTRIBUTE_KEY));               
}                // Set the tags               
UAirship.shared().getPushManager().setTags(tags);           
}       
}   
};

    

6. Make sure you've followed the other Gimbal & Urban Airship steps to get set up and that's all there is to it!

 

Related Content