Level: 200
 

Sitecore DMS: How to register / trigger a goal

GoalIn this article we will shortly describe how goals are triggered in Sitecore DMS. This includes how you can register goals in the UI as well as how to do it programmatically using the API.
Written by: Jens Mikkelsen
Thu, Jul 25 2013



Creating the goal

Creating a goal is fairly easy. Just fire up the Marketing Center, expand the goals node and create a new one:



Creating Sitecore DMS goal



After it has been created, you must deploy it through the standard workflow and publish. Otherwise it won’t be available in the Sitecore Analytics database.


If needed, you can also add a value point to the node, if you need to use that for measuring the value of your visitors. 



Triggering the goal using Sitecore UI

There are several ways you can trigger a goal using the UI.


You can register the goal if a specific page is loaded. This is often relevant, when you have a confirmation page for a form or similar. You can add the goal to the page through the content editor:



Register DMS goal on page



That is it. Now all you have to do is publish. The goal is actually stored in the Tracking field in the advanced field on the item:


Tracking field



You can also trigger a goal from Webforms for Marketers (WFFM), when a form is submitted successfully. To do this, open your Webform in the Form Designer. In the ribbon you can then click Properties in the Analytics section. Then you can select your goal:



Webform register Sitecore DMS goal



Triggering a goal programmatically through the API

You can also trigger the goal using the API. The goal is actually just a page event and there is no specific API for goals. Therefore you will need to use the Page Event API:


//First ensure that we have analytics enabled and the context is right

if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)

{

  //Get the item representing the goal.

  Item goalItem = Sitecore.Context.Database.GetItem("{19EBF2CB-667E-4577-B39C-EBD71E8EFF47}");

  //Page event wrapper used for the API

  PageEventItem goal = new PageEventItem(goalItem);

  //Create the record that needs to be stored (the goal)

  VisitorDataSet.PageEventsRow pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(goal);

  //Add any data you like, which will be stored with the PageEvent

  pageEventsRow.Data = "You might want to store extra data here. Like som special information about the user";

  //Submit the goal

  Sitecore.Analytics.Tracker.Submit();

}



When the goal is triggered you will be able to see it, in the Sitecore Analytics database in the table PageEvents




 

Please rate this article


6 rates / 2,33 avg.

  • About the author:

    Jens Mikkelsen

    Jens Mikkelsen is a partner at Inmento Solutions a Sitecore consulting firm. He works as a Sitecore specialist and consulting helping clients architect and build quality Sitecore solutions using the newest modules and tools. 

    Further he has been deeply envolved in various complex solutions and has built up a strong knowledge of Sitecore architecture and best practices. He has especially focused on and is specialized in debugging and analyzing Sitecore solutions.

     

    Jens is very interested in the technical mechanisms in the new marketing products such as Sitecore DMS and Sitecore ECM.

    My Sitecore Freelance CV

4 responses to "Sitecore DMS: How to register / trigger a goal"

Hi Jens,

This is kind a urgent.

I am working on one project where I used to submit the goals and have been seeing them(almost 2 months) always in PageEvent table. However, suddenly it stopped writing the events to the page table. my colleague had notified me the same problem some time back but I never had the same.

My code to register event is,
PageEventData eventData = new PageEventData(goalName);
eventData.Text = goalName; //goalName
eventData.DataKey = Sitecore.Context.User.Name + "_" + planCode;
eventData.Data = CurrentSuggestion; //Current sugg
eventData.ItemId = itemId; //Current Page
Sitecore.Analytics.Tracker.CurrentPage.Register(eventData);
Sitecore.Analytics.Tracker.Submit();
Would you have any insight to this?

--Thanks,Vipul
Posted: Wednesday, October 30, 2013 3:20 AM
Dan
Thanks for the details.

Do you know of a way to tie the goal with a click of a link? (not a web form submission)

I'd rather not put the goal on the next page load, as it might get diluted with other engagement scoring.
Posted: Sunday, July 20, 2014 9:27 PM
Hi Jens,

I've a requirement that when user clicks on a link. we need to trigger the goal. So have a written below logic one action method which used to call through AJAX request while user clicks the link.

if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
{
var goalItem = Sitecore.Context.Database.GetItem(goal);
var goalPageEvent = new PageEventItem(goalItem);
var pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(goalPageEvent);

pageEventsRow.Data = goalItem.Name + " has been fired at "
+ DateTime.Now.ToString("F");
// pageEventsRow.ItemId = Sitecore.Context.Item.ID.Guid;
// pageEventsRow.DataKey = Sitecore.Context.Item.Paths.Path;
Sitecore.Analytics.Tracker.Submit();
}

Here "goal" variable represents the ID of the goal. It's executing successfully without any exception. but i'm not view the changes in Goal analytic report in "Experience analytics" in sitecore. I'm using sitecore 8.1. Could you let me know Is there any issue in the code, If not how can we view that changes in analytics report.

Thanks in advance..

Regards,
Kali Krishna
Posted: Tuesday, November 24, 2015 12:59 PM
Hi Jens,

I've a requirement that when user clicks on a link. we need to trigger the goal. So have a written below logic one action method which used to call through AJAX request while user clicks the link.

if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
{
var goalItem = Sitecore.Context.Database.GetItem(goal);
var goalPageEvent = new PageEventItem(goalItem);
var pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(goalPageEvent);

pageEventsRow.Data = goalItem.Name + " has been fired at "
+ DateTime.Now.ToString("F");
// pageEventsRow.ItemId = Sitecore.Context.Item.ID.Guid;
// pageEventsRow.DataKey = Sitecore.Context.Item.Paths.Path;
Sitecore.Analytics.Tracker.Submit();
}

Here "goal" variable represents the ID of the goal. It's executing successfully without any exception. but i'm not view the changes in Goal analytic report in "Experience analytics" in sitecore. I'm using sitecore 8.1. Could you let me know Is there any issue in the code, If not how can we view that changes in analytics report.

Thanks in advance..

Regards,
Kali Krishna
Posted: Tuesday, November 24, 2015 1:00 PM

Leave a reply


Notify me of follow-up comments via email.
 
 
#nbsp;