EVGContext Class Reference
Inherits from | NSObject |
---|---|
Declared in | EVGContext.h |
Overview
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]
.
Lifecycle
isActive
If this context is currently active or not.
@property (nonatomic, readonly) BOOL isActive
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/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, see setCampaignHandler:forTarget:
Declared In
EVGContext.h
Campaigns and Stats
– 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.
- (void)setCampaignHandler:(nullable EVGCampaignHandler)handler forTarget:(nonnull NSString *)target
Parameters
handler |
The campaign handler this context should use for the specified target. |
---|---|
target |
App-defined string that uniquely identifies the payload data schema - what the data represents and its purpose. See |
Discussion
Campaigns can potentially be received in response to actions (see trackAction:
) and item interactions (see viewItem:
etc) 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.
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, see EVGCampaignHandler
for example code.
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:
- Recommended 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 inEVGCampaignHandler
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
Declared In
EVGContext.h
– trackImpression:
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.
See Mobile Data Campaigns Guide and <[EVGCampaignHandler]>
.
- (void)trackImpression:(nonnull EVGCampaign *)campaign
Parameters
campaign |
The campaign for which an impression should be tracked. |
---|
See Also
Declared In
EVGContext.h
– trackDismissal:
Tracks a dismissal for the provided campaign.
Call this method after showing the campaign to the user and the user dismissed the campaign.
See Mobile Data Campaigns Guide and <[EVGCampaignHandler]>
.
- (void)trackDismissal:(nonnull EVGCampaign *)campaign
Parameters
campaign |
The campaign for which a dismissal should be tracked. |
---|
See Also
Declared In
EVGContext.h
– trackClickthrough:
Tracks a clickthrough for the provided data campaign.
Call this method after showing the campaign to the user and the user clicked campaign content.
See Mobile Data Campaigns Guide and <[EVGCampaignHandler]>
.
- (void)trackClickthrough:(nonnull EVGCampaign *)campaign
Parameters
campaign |
The campaign for which a clickthrough should be tracked. |
---|
See Also
Declared In
EVGContext.h
– trackClickthrough:actionIdentifier:
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.
- (void)trackClickthrough:(nonnull NSDictionary *)notification actionIdentifier:(nullable NSString *)actionIdentifier
Parameters
notification |
The notification/userInfo as received from iOS. |
---|---|
actionIdentifier |
The actionIdentifier from the notification, if any. |
Availability
1.3.0
Discussion
Evergage 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, Evergage 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.
Declared In
EVGContext.h
Tracking Item Views
– viewItem:
Tracks that an item is being viewed.
Set nil
to indicate no longer viewing any item/category/tag.
- (void)viewItem:(nullable EVGItem *)item
Parameters
item |
The item being viewed. |
---|
Discussion
Recommended to call just before visible, viewWillAppear for a view controller.
Evergage 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
Declared In
EVGContext.h
– viewItem:actionName:
Same as viewItem:
but with a different action name to distinguish this View Item.
- (void)viewItem:(nullable EVGItem *)item actionName:(nullable NSString *)actionName
Parameters
item |
The item being viewed. |
---|---|
actionName |
Optional different action name. |
Availability
1.3.0
Discussion
Only tracks an action if item is non-null.
Declared In
EVGContext.h
– viewItemDetail:
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.
- (void)viewItemDetail:(nullable EVGItem *)item
Parameters
item |
The item whose details are being viewed. |
---|
Discussion
Recommended to call just before visible, viewWillAppear for a view controller.
Evergage 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
Declared In
EVGContext.h
– viewItemDetail:actionName:
Same as viewItemDetail:
but with a different action name to distinguish this View Item Detail.
- (void)viewItemDetail:(nullable EVGItem *)item actionName:(nullable NSString *)actionName
Parameters
item |
The item whose details are being viewed. |
---|---|
actionName |
Optional different action name. |
Availability
1.3.0
Discussion
Only tracks an action if item is non-null.
Declared In
EVGContext.h
– viewCategory:
Tracks that a category is being viewed.
Set nil
to indicate no longer viewing any item/category/tag.
- (void)viewCategory:(nullable EVGCategory *)category
Parameters
category |
The category being viewed. |
---|
Discussion
Recommended to call just before visible, viewWillAppear for a view controller.
See Also
Declared In
EVGContext.h
– viewCategory:actionName:
Same as viewCategory:
but with a different action name to distinguish this View Category.
- (void)viewCategory:(nullable EVGCategory *)category actionName:(nullable NSString *)actionName
Parameters
category |
The category being viewed. |
---|---|
actionName |
Optional different action name. |
Availability
1.3.0
Discussion
Only tracks an action if category is non-null.
Declared In
EVGContext.h
– viewTag:
Tracks that a tag is being viewed.
Set nil
to indicate no longer viewing any item/category/tag.
- (void)viewTag:(nullable EVGTag *)tag
Parameters
tag |
The tag being viewed. |
---|
Discussion
Recommended to call just before visible, viewWillAppear for a view controller.
See Also
Declared In
EVGContext.h
– viewTag:actionName:
Same as viewTag:
but with a different action name to distinguish this View Tag.
- (void)viewTag:(nullable EVGTag *)tag actionName:(nullable NSString *)actionName
Parameters
tag |
The tag being viewed. |
---|---|
actionName |
Optional different action name. |
Availability
1.3.0
Discussion
Only tracks an action if tag is non-null.
Declared In
EVGContext.h
Tracking Item Activity
– addToCart:
Tracks that a line item is being added to the shopping cart.
- (void)addToCart:(nonnull EVGLineItem *)lineItem
Parameters
lineItem |
The line item being added. The |
---|
Declared In
EVGContext.h
– removeFromCart:
Tracks that a line item is being removed from the shopping cart. The [EVGLineItem item]
should be a EVGProduct
with [EVGProduct price]
set.
- (void)removeFromCart:(nonnull EVGLineItem *)lineItem
Parameters
lineItem |
The line item being removed. |
---|
Availability
1.4.0
Declared In
EVGContext.h
– viewCart:
Tracks an entire shopping cart, which will update/replace the entire state of the mirrored cart in Evergage.
- (void)viewCart:(nonnull EVGOrder *)order
Parameters
order |
The entire cart being viewed. Each |
---|
Availability
1.4.0
Discussion
A cart can be considered an ‘open’ order. Most carts will not have an orderId
, and so the field can be left un-set.
Declared In
EVGContext.h
– purchase:
Tracks that an order was purchased.
- (void)purchase:(nonnull EVGOrder *)order
Parameters
order |
The order that was purchased. Each |
---|
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.
Declared In
EVGContext.h
– review:
Tracks that an item was reviewed.
- (void)review:(nonnull EVGItem *)item
Parameters
item |
The item that was reviewed. |
---|
Declared In
EVGContext.h
– review:reviewDetails:
Tracks that an item was reviewed, as well as the optional details of the review.
- (void)review:(nonnull EVGItem *)item reviewDetails:(nullable EVGReview *)reviewDetails
Parameters
item |
The item that was reviewed. |
---|---|
reviewDetails |
The optional details of the review, such as the rating. |
Declared In
EVGContext.h
– share:
Tracks that an item was shared, for instance by email or on a social network.
- (void)share:(nonnull EVGItem *)item
Parameters
item |
The item that was shared. |
---|
Declared In
EVGContext.h
– comment:
Tracks that an item was commented on. For instance, an article or blog might accept comments.
- (void)comment:(nonnull EVGItem *)item
Parameters
item |
The item that was commented on. |
---|
Declared In
EVGContext.h
– favorite:
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).
- (void)favorite:(nonnull EVGItem *)item
Parameters
item |
The item that was marked as favorite. |
---|
Declared In
EVGContext.h
Manually Tracking Actions
– trackAction:
Sends an event to Evergage describing an action to track.
- (void)trackAction:(nonnull NSString *)action
Parameters
action |
A 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. See Mobile Data Campaigns Guide for recommended rules.
Declared In
EVGContext.h