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 🙂

Rendering Parameters

What is the rendering parameter? Rendering parameter is a way to pass additional items or values on the presentation component rendering, apart from rendering data source.
When we use a rendering parameter? It is a situation where content editors need additional items apart from its actual data source.

For Example, I used the Rendering Parameter to pass and additional CSS class to the component, which will allow my content editors to choose the style of their component.

How to use the rendering parameter? There are three step activity to create and consume a rendering parameter.

1)      Create Rendering Parameter Template.

2)      Assign a Rendering Parameter to a respective component.

3)      Retrieve or utilize the Rendering Parameter value in the code.

  • Create Rendering Parameter Template.

Create a new parameter Rendering template make sure creating template should inherit from “Standard Rendering Template” as shown below in the image.

Create Rendering Paramter Template

Image: creating a rendering parameter template.

After creation template, Create the field as shown below in the image.

FieldCreation Rendering Parameter

2) Assign a Rendering Parameter to a respective component.

Assign you parameter template on your required rendering under the Editor Options section of your rendering, as shown below

Assign Rendering Template at Rendering

After referencing your Rendering Template to the respective rendering, as shown above in the image, check the same by going to the content item where you are using rendering parameter go to the

Presentation Details=> Final Layout

And select your rendering and click on edit – you can see your Rendering  Parameter field there. As shown below.

Editor Assign Value at Rendering Parameter

 

 3) Retrieve or utilize the Rendering Parameter value in the code.

  1. a) Read the rendering parameter value at the partial view.

var rc = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull;

string styleName = string.Empty;

if (rc != null)

{

var parms = rc.Rendering.Parameters;

styleName = parms[“Css Name”];

}

I hope this post will help you in understanding the Rendering Parameter.

Happy Coding 🙂