Trigger an Outcome Programmatically

As you probably already know, the main difference between an outcome and a goal, is the possibility to assign a monetary value to an outcome so that you can use it to get better reporting within your analytics and eventually to understand which paths/content converted better.

Outcomes can only be assigned programmatically, this snippet simulate a controller rendering that trigger the ProductPurchase Outcome.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sitecore.Mvc;
using System.Web.Mvc;
using System.Web;
using Sitecore.Analytics.Outcome.Extensions;
using Sitecore.Analytics.Outcome.Model; 

public ActionResult PurchaseOutcome()
        // Register an outcome
        //It will only be saved to the database on session end

        var id = Sitecore.Data.ID.NewID;
        var interactionId = Sitecore.Data.ID.NewID;
        var contactId = Sitecore.Data.ID.NewID;

       // definition item for Purchase Outcome
      var definitionId = new Sitecore.Data.ID("{9016E456-95CB-42E9-AD58-997D6D77AE83}");

        var outcome = new ContactOutcome(id, definitionId, contactId);
        outcome.MonetaryValue = 153;
        return Content("Outcome purchase 153");

These are the references required:


And this is the Outcome definition:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s