Create and Use Goal

In this Article we will cover, What is the goal?, Why use goal? , How to create and use goal in Sitecore.

What is the goal?

A goal in Sitecore is any action that a user completed. It can be a page that has been viewed, a form that has been completed or other actions.

Why use the goal?

Goals are used to track and measure how visitors engage with the website and campaigns. Engagement value points use to measure relative contact engagement across your website.

You can use engagement value points to

=>Create and implement personalization rules for contacts

=>Create marketing automation campaigns that evaluate the number of engagement value points that contact has achieved to determine what action should be taken.

The Engagement Value Scale looks like as shown below image:

EngagementValueScale

How to create and use goal in Sitecore.

1) Default Goals:-> Those goals which are default creates under Marketing Control Panel=>Goals are called default goals

e.g. “Download Broucher”,” Login”, “Register” etc.

Use Default Goals:-> In my case, I used “Download Broucher” goal on the media item, as shown below.MediaItemGoal

Click on Analyze tab=>Click on Goals and select “Download brochure” after that save and publish for applying this goal.

2) Custom Goals:->Creating new Goals under System=>Marketing Control Panel=> Goals, are called custom Goals.

E.g. I created goal, which name is “Read More Goal” after that click on “deploy action” can be found on the review tab,

for showing the goal in the list of rule during applying the goal on presentation rendering of an item.Deploy Goal

How to Trigger a Goal

Method 1: Trigger a Goal using Query Parameter This method uses the “sc_trk” query parameter to trigger the goal

In Sitecore, if your anchor link used “General Link” URL, click on

“Insert link” as shown belowGenerallink_Querystring

After that assign query string value like sc_trk=[goal name]or [goal itemID], as shown belowApply

Method 2: Trigger a Goal using Goal Item ID / Item Name (Preferable Way) This method uses the item ID of the goal to trigger because of Goals Ids in Sitecore do not change.

If the location of the goal is changed or if the name of the goal is changed.

Ajax call for Api Method:

$(‘.personalisegoal’).click(function(){

var url = “/api/sitecore/API/AnalyticsEvent/”;

var Obj = {};

Obj.ItemId=”0526CFBE-9547-42C0-8410-914BE47B73E1”;

var objPageEventModel=JSON.stringify({ ‘pageEventModel’: Obj });

$.ajax({

contentType: ‘application/json; charset=utf-8’,

dataType: ‘json’,

url: url,

data: objPageEventModel,

cache: false,

type: “POST”,

success: function(response) {

console.log(response);

}

,

error: function(response) {

console.log(“error”, response);

}

});

Api controller

public JsonResult AnalyticsEvent(PageGoalModel pageGoalModel)
{
try
{
Sitecore.Data.ID suzukiConnnectGoal = new Sitecore.Data.ID(pageGoalModel. ItemId);
RegisterEventDataService.TriggerGoal(suzukiConnnectGoal);

}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error(“Error in SaveEMICalculatorAnalytics Method , Item Path : ” + Sitecore.Context.Site.StartPath + “”, ex, this);
}
return Json(true, JsonRequestBehavior.AllowGet);
}

Service Code

public static void TriggerGoal(Sitecore.Data.ID goalId)
{
if (!Tracker.IsActive)
{
Tracker.StartTracking();
}
if (Tracker.IsActive && Tracker.Current.CurrentPage != null)
{
Sitecore.Data.Items.Item goalItem = Sitecore.Context.Database.GetItem(goalId);
if (goalItem != null)
{
var goalTrigger = Tracker.MarketingDefinitions.Goals[goalId.ToGuid()];
var goalEventData = Tracker.Current.CurrentPage.RegisterGoal(goalTrigger);
goalEventData.Data = goalItem[“Name”];
goalEventData.ItemId = goalItem.ID.ToGuid();
goalEventData.DataKey = goalItem.Paths.Path;
goalEventData.Text = goalItem[“Name”];
Tracker.Current.Interaction.AcceptModifications();
}
}
}

Where we can apply all created goals?

On the item of the content tree, we will apply the created goals.

First select an item “About Habitat” from the content tree, after that click on “Presentation”=> “Detail ”=>Click on “Personalise tab” of selected Rendering. As shown below.AllRendering

Image: Showing All RenderingSelect Rendering and Applying Goal

Image: Select Rendering and Applying GoalChange the Datasource after the meet Goals

Image: Change the Datasource after the meet Goals

Happy Coding 🙂