Custom goals scoring
Discover how to set up and trigger custom goals in Umbraco Engage using C# code.
Last updated
Discover how to set up and trigger custom goals in Umbraco Engage using C# code.
Last updated
To set custom goals:
Navigate to Settings > Goals in the Umbraco Engage section.
Set the goal type to Custom.
Execute C# code to trigger the goal.
Creating the goal is similar to creating a page view or page event goal. The goal ID displayed in the code snippet after saving, as it's needed to trigger the goal from the code.
To trigger the goal, execute C# code during the visitor's pageview. Inject Umbraco.Engage.Business.Analytics.Goals.IGoalService
, which has a TriggerGoal(long goalId, int value)
method. An implementation looks like:
The method automatically determines the current page view, linking the goal to a session and visitor. This means the HttpContext should be available.
To trigger a goal outside of an HTTP request, use the overload of TriggerGoal that takes the GUID of the pageview.
Retrieve the pageview GUID in the original request using Umbraco.Engage.Business.Analytics.Common.IPageviewGuidManager. You will need to store this pageview GUID for later use when invoking:
This custom goal can now be used like other goals and will show up in any statistics related to goals.