0
votes

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.

1
You can switch the order of rules #1 and #2, then image2 will have priority over image1. If that is not good enough for you—then yeah, you'll need to create a custom rule. - Dmytro Shevchenko

1 Answers

4
votes

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).