I want to display some different sublayout if user has visit some page more than 2 times so I want to use this rules "where the visit no. compares to number" but I do not have idea how I can use it? I tried to add this rule and replace "number" to 2 but it is not working.
-
What revision of Sitecore 8 are you using? What do you mean by "I have no idea how I can use it" .Have you got the rule set up on a sub layout and published it? – Ian Graham Mar 06 '16 at 13:49
-
1There's a good article here on setting up personalization - http://www.nonlinearcreations.com/Digital/how-we-think/articles/2014/06/Sitecore-DMS-personalization-howto.aspx – Ian Graham Mar 06 '16 at 14:00
-
1`Where the visit no. compares to ...` rule means that it's user n-th visit on the site, not that user opened one of the pages multiple times. – Marek Musielak Mar 06 '16 at 15:54
2 Answers
As Marek said this is not possible with the condition you are using. However you could adjust the Rule condition to achieve this by looking at the VisitPageIndex for the page.
public class ContactVisitPageIndexCondition<T> : OperatorCondition<T> where T : RuleContext
{
public int No
{
get;
set;
}
public ID PageGUID
{
get;
set;
}
public ContactVisitPageIndexCondition()
{
}
protected override bool Execute(T ruleContext)
{
Assert.ArgumentNotNull(ruleContext, "ruleContext");
Assert.IsNotNull(Tracker.Current, "Tracker.Current is not initialized");
Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session is not initialized");
Assert.IsNotNull(Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized");
int contactVisitPageIndex = Tracker.Current.Session.Interaction.Pages.SingleOrDefault(p => p.Item.Id == PageGUID).VisitPageIndex;
switch (base.GetOperator())
{
case ConditionOperator.Equal:
{
return contactVisitPageIndex == this.No;
}
case ConditionOperator.GreaterThanOrEqual:
{
return contactVisitPageIndex >= this.No;
}
case ConditionOperator.GreaterThan:
{
return contactVisitPageIndex > this.No;
}
case ConditionOperator.LessThanOrEqual:
{
return contactVisitPageIndex <= this.No;
}
case ConditionOperator.LessThan:
{
return contactVisitPageIndex < this.No;
}
case ConditionOperator.NotEqual:
{
return contactVisitPageIndex != this.No;
}
}
return false;
}
}

- 3,206
- 1
- 15
- 23
-
`VisitPageIndex` is a pain and only returns the index of the page was viewed in the Contact's Visit but this is a good answer - just replace `Tracker.Current.Session.Interaction.Pages.SingleOrDefault(p => p.Item.Id == PageGUID).VisitPageIndex;` with `Tracker.Current.Session.Interaction.Pages.Count(p => p.Item.Id.Equals(yourPageId))` – Jonathan Robbins Mar 06 '16 at 20:41
As Marek Musielak said, Where the visit no. compares to ..
related to visit to the site and not an individual page.
I had a look in the Sitecore API, its Tracker
namespace and the closest property I can find to individual page view count is VisitPageIndex
but decompiling the code and checking in MongoDB
shows that is just the index of the page was viewed for that visit to the site so this won't work for you.
Looking in MongoDB
there are no properties to store page views but it does store the Pages
viewed for Interactions
so you could write a custom rule counting the number of times that page is in the Pages array
e.g.
int pageViewed = Tracker.Current.Session.Interaction.Pages.Count(p => p.Item.Id.Equals(yourPageId))
An alternative if you don't want to write custom is to change your approach a bit inline with how Sitecore personalisation scan work out of the box.
You'll want to use or create profile keys
in the Marketing Centre
e.g. 'Brand Aware'. Assign your new profile key
to the page in question and assign it a score e.g. 10. This means that each time a user visits this page they will be given a 10 points in 'Brand Aware'.
Now for the personalisation bit. Create a new personalisation rule on the existing sublayout
using 'where the value of the specific profile key compares to specific value' set it to hide if the score is greater than or equal to
20. Create another to display your new sublayout
if the value is greater than or equal to
20.
I've wrote a blog about this if you need more info

- 2,027
- 1
- 16
- 30