2

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

mwre
  • 35
  • 3

1 Answers1

2

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();
      }
  }
Vlad Iobagiu
  • 4,118
  • 3
  • 13
  • 22
  • Hey Sitecore Climber, I had tried this as it was under the documentation for Sitecore 8 but it doesn't seem to register it. When I add the goal via the Goal option under the analyze tab in the sitecore ribbon it seems to work fine... When trying the above it doesn't seem to track the goal. – mwre Nov 13 '15 at 10:31
  • 1
    It's worth noting the write into MongoDb doesn't occur until the Session End event, typically 20 mins after the last activity of the user. You can cause the write by calling Session.Abandon() to help with development – Jonathan Robbins Nov 13 '15 at 10:50
  • 1
    Hi @JonathanRobbins, After inserting session.abandon() all the analytics appeared in the database and report... cheers for this! – mwre Nov 13 '15 at 13:06
  • @mwre For development purposes, I would recommend using `` instead. This will end the session 1 minute after the last page request. – Dmytro Shevchenko Nov 14 '15 at 08:42
  • Also for making this to work, we need to make sure we have registered @Html.Sitecore().VisitorIdentification()(@using Sitecore.Mvc.Analytics.Extensions) in the head section of the page. – Rama Krshna Ila Aug 27 '16 at 18:25