Sitecore 6.5 DMS - Registering a goal completion via the API

1.7k views Asked by At

I want to register a goal/conversion on my Sitecore 6.5 site using the API rather than a 'thank-you' page.

I've seen this question about how to do it Sitecore OMS - achieving a goal on a form submission but the answer relates to the API prior to Sitecore 6.5 where it was overhauled quite significantly.

Has anyone done this? Or has this functionality been intentionally removed?

2

There are 2 answers

4
Jens Mikkelsen On BEST ANSWER

Have you tried something like

protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
    {
        PageEventData eventData = new PageEventData("My Goal Name");
        eventData.Data = "this is some event data.";
        VisitorDataSet.PageEventsRow pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(eventData);
        Sitecore.Analytics.Tracker.Submit();
    }
} 

That should register the goal on the currentpage, but not before you decide to in your code

0
StephenHynds On

You can also use a modified version of the code which references the Goal Item by its GUID:

if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
{
PageEventItem goal = new PageEventItem(Sitecore.Context.Database.GetItem("GOALGUID"));
VisitorDataSet.PageEventsRow pageEventsRow = Sitecore.Analytics.Tracker.CurrentPage.Register(goal);
Sitecore.Analytics.Tracker.Submit();
}

Make sure you have deployed and published your goal and or goal category too as the code will fail otherwise.