Archive for category Digital Marketing Suite (DMS)

Programmatically trigger Sitecore DMS goals

Sitecore provides you with a robust way of configuring when a DMS goal is triggered using the rules editor.
Its usage is quite intuitive and there are a vast number of options available for the configuration.

But at times depending on the site specific custom business logic we have in place, we might want to be able to trigger a goal from our code.

Here is how we would do that.
Following is the Demo Goal I have created and am going to work with:

To trigger the goal from code:

            if (!Sitecore.Analytics.Tracker.IsActive)

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

            var goalItem = Sitecore.Context.Database.GetItem("{710AC40A-EFC3-43AE-B7F8-225716D73EC9}");
            var goal = new PageEventItem(goalItem);
            var pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(goal);

            pageEventsRow.Data = "Demo goal test information : " 
                + DateTime.Now.ToString("F");
            pageEventsRow.ItemId = Sitecore.Context.Item.ID.Guid;
            pageEventsRow.DataKey = Sitecore.Context.Item.Paths.Path;



using Sitecore.Analytics.Data.Items;

Getting a report of the goals triggered is not really straightforward when you use the Sitecore Engagement Analytics option.
You could instead directly fire a query on the analytics database to see immediate results with ease.

SELECT Name, DataKey, ItemId, Data, 
pe.PageEventDefinitionId AS GoalItemId, Value AS GoalValue, 
VisitorId, VisitId, [DateTime] 
FROM dbo.PageEvents pe, dbo.PageEventDefinitions ped
WHERE pe.PageEventDefinitionId = ped.PageEventDefinitionId
AND ped.IsGoal = 1
AND ped.Value!=0


, , , ,

1 Comment