Search code examples
mongodbsitecoresitecore-dmssitecore7.5goal-tracking

Sitecore 7.5 DMS Tracking Goal Programmatically


I'm currently trying to track a button click in sitecore 7.5 using sitecore DMS, i'm finding alot of information on the internet but most of it is pre 7.5 before the change over to MongoDB...

Previously it would look something like this:

//Check that analytics are on...
if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)
{
  //Get the item goal.
  Item goalItem = Sitecore.Context.Database.GetItem("{xxxxx-xxx-xxx-xxxxx}");
  //Page event wrapper
  PageEventItem goal = new PageEventItem(goalItem);
  //Create the record that needs to  store the goal
   VisitorDataSet.PageEventsRow pageEventsRw = Sitecore.Analytics.Tracker.CurrentPage.Register(goal);
  //this is not mandatory
  pageEventsRw.Data = "custom text";
  Sitecore.Analytics.Tracker.Submit();
}

I want to achieve this kind of goal in Sitecore 7.5 but struggling to find much resource on the internet, wondering if any advanced sitecore users could point me in the right direction?

Cheers, MW


Solution

  • Can you try :

    if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null)
      {
          Sitecore.Data.Items.Item GoaltoTrigger = Sitecore.Context.Database.GetItem("{Item ID of the Goal}");
          if (GoaltoTrigger != null)
          {
              Sitecore.Analytics.Data.Items.PageEventItem registerthegoal = new Sitecore.Analytics.Data.Items.PageEventItem(GoaltoTrigger);
              Sitecore.Analytics.Model.PageEventData eventData = Sitecore.Analytics.Tracker.Current.CurrentPage.Register(registerthegoal);
              eventData.Data = GoaltoTrigger["Description"];
             Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications();
          }
      }