sukesh
sukesh

Reputation: 2425

Sitecore personalisation - previous page

The website has these pages - Home, Product1, Product2 and the Home page has a banner.

When user's journey is - Home > Product1 > Home, the banner should show image1.

When user's journey is - Home > Product2 > Home, the banner should show image2.

When user visits - Home > Product2 > Product1 > Home, the banner should show image1.

..which means, I want to show the image based on the last visited page before Home.

In the rule set editor, I set the 3 rules:
1. where the specific page during the visit is "product1" , then the image will be image1.
2. where the specific page during the visit is "product2" , then the image will be image2.
3. Default - hide banner

This is not working as desired. If user visits product1 first, then its always image1 in the banner. I understand it's working according the rule, as rule 1 will always become true here.

But, how can I achieve what I need.

Upvotes: 0

Views: 598

Answers (1)

Trayek
Trayek

Reputation: 4410

You'll have to create a custom condition for that. There are lots of blogposts around how to do that part, so I won't focus on that.

Your condition could be something like where previous page is specific page

Then in your condition, you'll pass in an ID (where it says specific page). You can then do something like this in the condition:

var pagesVisited = Sitecore.Analytics.Tracker.Current.Interaction.GetPages().ToList();
return pagesVisited.Last().Item.Id == Guid.Parse(id); // id is the item you've selected in the Rule Editor

(Note that I haven't tested the code, but it should be similar to this. You might also want to run a bit of a performance test on it of course).

Upvotes: 4

Related Questions