Programmatically “Visit” a page (and all xDB-related)

Yesterday during my presentation at the SUG-Quebec (check video here), my host and good friend Jeff L’Heureux asked if I could share the multiple challenges involved in the Smart Bookshelf for Sitecore Demo. In response to that, I’m putting together a number of articles, modules and other resources, to share how each of these things works.

The present article shows how we can simulate a visit to a Sitecore page, along with all xDB-related events that happens when you actually do it. For instance, if your page has Profile Card(s) associated, then your contact should get points in that profile when the page is visited.

The Smart Bookshelf has the following situation:

Anthology Profile Cards

As you can see, Genres have corresponding Profile Cards, so when a Genre page is visited, the corresponding Profile Card is summed up to the contact’s profile. This is how we can track and define the user’s preferred Book Genres.

Now we want to apply the same Genre Profile Cards when the user visits a Book Page. Given that each book belongs to a single Genre, we don’t have to manually associate the Profile Card to individual books. Instead, we can use the following technique to simulate a visit to a Genre Page when a Book is visited.

 

Enough talking – show me the code!

Ozzy Rock

So simple and easy, that you’ll probably want to kill me for the long intro

 

Step 1 – Get the item you want to simulate a visit to

In my case, Books are direct children of Genres, so all I have to do is to get the parent item:

var bookItem = Sitecore.Context.Item;
var genreItem = bookItem.Parent;

Step 2 – Simulate the visit

Go ahead and call the following static method:

Sitecore.Analytics.Data.TrackingFieldProcessor.Process(genreItem);

Thats it?

Yes! You want it harder?

Minions saying NO!

Thought so ;)

Publicado em Analytics, xDB

Leave a Reply

Your email address will not be published. Required fields are marked *

*

  Am Not Spammer

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>