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:
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!
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:
Yes! You want it harder?