Add interaction events
This topic demonstrates how to add various types of events to an interaction. Keep the following in mind when adding events to an interaction:
-
It is possible to associate an event with an incorrect definition (for example, associating an outcome definition with a
Goal). The platform will not enforce any particular relationships between an event type collection model and a definition item. It is your responsibility to ensure the fidelity of your data. -
The
EngagementValueproperty is optional and must be set manually. In a tracking context, the tracker will set the engagement value to the event’s definition item’s default engagement value before saving. In a non-tracking context, must use the Marketing Operations API to retrieve the event definition item if you want to use the default engagement value.
Adding a Goal to an interaction
The following example demonstrates how to add a goal to an interaction.
Adding an Outcome to an interaction
The following example demonstrates how to add an outcome to an interaction.
Although Currency and MonetaryValue are mandatory properties, you can pass in String.Empty and 0.00m if your outcome is not associated with a monetary value.
Adding a PageViewEvent to an interaction
Web interactions are likely to have multiple, nested events (goals and page events will have a page view event parent). The following example demonstrates how to simulate a web visit, which includes adding PageViewEvent events.
The PageViewEvent allows you to store both the page URL and the associated item ID, which means that you can store alias URLs or query strings in the Url property.
Adding an event as a child of a page view event
To associate a goal with a page view, set the ParentEventId of the goal to the Id of the page view as demonstrated in the previous example.
Adding a page event
Page events are stored under /sitecore/system/Settings/Analytics/Page Events and represent common, web-specific events such as ‘user performed a search’ or ‘the page is slow’. When triggering a page event, make sure you associate with a PageViewEvent by setting the ParentEventId property.
Not all page events are represented by a specialized class. For events without a specialized class, use the base Event class and pass in the ID of the event definition item.
Adding a DownloadEvent to an interaction
The following example demonstrates how to trigger a download event. The ItemId that is passed into the constructor is the ID of the media item that was downloaded.
Adding a SearchEvent to an interaction
The following example demonstrates how to register a search event. The Keyword property is not mandatory.
Adding a CampaignEvent to an interaction
The following example demonstrates how to trigger a campaign.
The event ID of the CampaignEvent as the same event is happening - a campaign is being triggered. However, the campaign associated with the event will vary and is represented by the CampaignDefinitionId property.