10

Sitecore 8.2 U4

I am working on tracking the movement of the user through my registration form. As they move from section to section, I am going to add a page to their tracker so I can see that movement in a Sitecore funnel.

I am making an API call to a controller /apis/v1/registration/tracksection/{section}. In that controller I am calling Tracker.Current?.CurrentPage?.Cancel() to stop the API url from being tracked by Sitecore. Later in that controller I am calling the code below to insert a page into the tracker. I am basically trying to fake a call to a page the user didn't actually go to. I am doing this so I can track the user's UI experience in a Funnel. A funnel only tracks Sitecore pages, so I have to fake these pages in the tracker.

But the issue is that after I run the code below. The API call goes back into the page history. If I comment out of the code below, the API is removed from page history via the Tracker.Current?.CurrentPage?.Cancel() code as expected. Any idea how I can remove the API call and still inject the fake pages? Is there a different way I can add a page to the tracker that might work?

var page = Tracker.Current.Session.Interaction.CreatePage();
page.SetItemProperties(Registration.Constants.Ids.ClubInformation.Guid, "en-us", 1);
page.SetUrl(Sitecore.Context.Database.GetItem(Registration.Constants.Ids.ClubInformation).Url());
  • Which Sitecore version are you using? If it's Sitecore 9, you could use xConnect to create an interaction with required pages. – grg May 24 '18 at 8:50
  • @grg This is 8.2 U4. – Chris Auer May 24 '18 at 14:26
5

You have to cancel the page and tell the tracker about it, with

Tracker.Current.Session.Interaction.AcceptModifications();

before you start adding pages to the tracker. If you don’t accept changes, it will just bring the original page back into the tracker.

Tracker.Current?.CurrentPage?.Cancel();
Tracker.Current?.Session.Interaction.AcceptModifications(); 

var page = Tracker.Current.Session.Interaction.CreatePage();
page.SetItemProperties(pageGuid.Guid, "en-us", 1);
page.SetUrl(Sitecore.Context.Database.GetItem(pageGuid).Url());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.