EVGContext Class Reference

Inherits fromDeclared in
NSObjectEVGContext.h

Provides APIs to handle data campaigns, track item views and activity, and track manual actions, all within a lifecycle-managed context such as EVGScreen.

Typically used as [UIViewController(Evergage) evergageScreen] and, if necessary, [Evergage globalContext].

If this context is currently active or not.

Availability

1.2.0

Discussion

A typical EVGScreen context is active when the screen is visible and the app is not backgrounded.

Besides some initial setup just before becoming visible or active (setCampaignHandler:forTarget:, viewItem: etc), activity generally occurs while a context is active.

Context activity, in addition to app state and user idleness, can affect campaign delivery. For more information, see setCampaignHandler:forTarget:.

To optionally support custom data campaigns, register a campaign handler for the app-defined target within this context. Can set nil to clear.

Parameters

ParameterDescription
handlerThe campaign handler this context should use for the specified target.
targetApp-defined string that uniquely identifies the payload data schema - what the data represents and its purpose. For more information, see [EVGCampaign target].

Discussion

Campaigns can potentially be received in response to actions (see trackAction:) and item interactions (see viewItem:) tracked on this context.

The target is an app-defined string that uniquely identifies the payload data schema - what the data represents and its purpose. For more information, see [EVGCampaign target].

While the context, app, and user is active, the handler may receive asynchronous callbacks (on the main thread) with campaigns for the target, in response to actions/events sent. The handler code should show/update the campaign to the user, when appropriate, and follow best practices using weak references. For example code, see EVGCampaignHandler.

Campaigns may be held for delivery while either:

  • The context, app, or user is inactive
  • No handler is found for the campaign’s target within this context

For each context and target, only the most recent campaign will be held.

Lifecycle details for an EVGScreen based context:

  • We recommend to always call this method just before becoming visible, specifically UIViewController viewWillAppear:.
  • In order to prevent accidental leaks in the handler block (see weak references in EVGCampaignHandler example code to prevent this), a screen has a limited time to become visible, after which its handlers and held campaigns will be cleared.
  • When a screen transitions to not visible (viewWillDisappear:), all handlers and held campaigns are cleared. These limitations and automatic cleanup do not apply to [Evergage globalContext].

See Also

Tracks an impression for the provided campaign. Call this method after showing the campaign to the user or after the campaign would be shown but the user is in the control group. For more information, see Mobile Data Campaigns and EVGCampaignHandler.

Parameters

ParameterDescription
campaignThe campaign for which an impression should be tracked.

See Also

Tracks a dismissal for the provided campaign. Call this method after showing the campaign to the user and the user dismissed the campaign. For more information, see Mobile Data Campaigns and EVGCampaignHandler.

Parameters

ParameterDescription
campaignThe campaign for which a dismissal should be tracked.

See Also

Tracks a clickthrough for the provided data campaign. Call this method after showing the campaign to the user and the user clicked campaign content. For more information, see Mobile Data Campaigns and EVGCampaignHandler.

Parameters

ParameterDescription
campaignThe campaign for which a clickthrough should be tracked.

See Also

You do not normally need to call this method. It tracks a click on custom UI you chose to render from a notification received in the foreground.

Parameters

ParameterDescription
notificationThe notification/userInfo as received from iOS.
actionIdentifierThe actionIdentifier from the notification, if any.

Availability

1.3.0

Discussion

Personalization automatically tracks clicks on push notifications. However, when the notification is received while the app is in the foreground, the notification is not automatically shown to the user. If you are using UNUserNotificationDelegate, you have some options with userNotificationCenter:willPresentNotification:withCompletionHandler:

  • If you don’t show anything to the user, there is no click to track.
  • If you show the notification with UNNotificationPresentationOptionAlert, Personalization will automatically track any user click.
  • If you don’t show the notification, but instead render some other UI based on the notification, and want to track user clicks, call this method when the user clicks on the associated UI.

See Also

Tracks that an item is being viewed. Set nil to indicate no longer viewing any item/category/tag.

Parameters

ParameterDescription
itemThe item being viewed.

Discussion

Recommended to call just before visible, viewWillAppear for a view controller.

Personalization will automatically track the time spent viewing the item while the context, app, and user is active. The item will remain the one viewed until this method or viewItemDetail: are called again.

See Also

Same as viewItem: but with a different action name to distinguish this View Item.

Parameters

ParameterDescription
itemThe item being viewed.
actionNameOptional different action name.

Availability

1.3.0

Discussion

Only tracks an action if item is non-null.

Tracks that the details of an item are being viewed, such as viewing other product images or a specifications tab. Set nil to indicate no longer viewing any item/category/tag.

Parameters

ParameterDescription
itemThe item whose details are being viewed.

Discussion

Recommended to call just before visible, viewWillAppear for a view controller.

Personalization will automatically track the time spent viewing the item while the context, app, and user is active. The item will remain the one viewed until this method or viewItem: are called again.

See Also

Same as viewItemDetail: but with a different action name to distinguish this View Item Detail.

Parameters

ParameterDescription
itemThe item whose details are being viewed.
actionNameOptional different action name.

Availability

1.3.0

Discussion

Only tracks an action if item is non-null.

Tracks that a category is being viewed. Set nil to indicate no longer viewing any item/category/tag.

Parameters

ParameterDescription
categoryThe category being viewed.

Discussion

Recommended to call just before visible, viewWillAppear for a view controller.

See Also

Same as viewCategory: but with a different action name to distinguish this View Category.

Parameters

ParameterDescription
categoryThe category being viewed.
actionNameOptional different action name.

Availability

1.3.0

Discussion

Only tracks an action if category is non-null.

Tracks that a tag is being viewed. Set nil to indicate no longer viewing any item/category/tag.

ParameterDescription
tagThe tag being viewed.

Discussion

Recommended to call just before visible, viewWillAppear for a view controller.

See Also

Same as viewTag: but with a different action name to distinguish this View Tag.

ParameterDescription
tagThe tag being viewed.
actionNameOptional different action name.

Availability

1.3.0

Discussion

Only tracks an action if tag is non-null.

Tracks that a line item is being added to the shopping cart.

ParameterDescription
lineItemThe line item being added.

Tracks that an order was purchased.

ParameterDescription
orderThe order that was purchased.

Discussion

If the order contains no lineItems, the lineItems currently in the cart will be used. If orderId is set and multiple purchase events are received for the same orderId, all but the first will be ignored.

Tracks that an item was reviewed.

ParameterDescription
itemThe item that was reviewed.

Tracks that an item was reviewed, as well as the optional details of the review.

ParameterDescription
itemThe item that was reviewed.
reviewDetailsThe optional details of the review, such as the rating.

Tracks that an item was shared, for instance by email or on a social network.

ParameterDescription
itemThe item that was shared.

Tracks that an item was commented on. For instance, an article or blog might accept comments.

ParameterDescription
itemThe item that was commented on.

Tracks that an item was marked by the user as a favorite item. This is an explicit action taken by the user (often indicated by a single star).

ParameterDescription
itemThe item that was marked as favorite.

Sends an event to Personalization describing an action to track.

ParameterDescription
actionA short string that identifies the action.

Discussion

When considering the action name, remember that datasets encompass multiple platforms and apps. The name can match a corresponding action/behavior from another platform/app. A campaign can use a source rule to be limited to a specific source or set of sources. For recommeneded rules, see Mobile Data Campaigns.