Sitecore 6.5 DMS - Registering a goal completion v

2019-05-28 14:09发布

问题:

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?

回答1:

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



回答2:

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.