AndyButland / UmbracoPersonalisationGroups

Package for personalisation of content with Umbraco.
MIT License
38 stars 18 forks source link

Cookie values for new visitors not incrementing, cookie is null in initial check #10

Closed SimonAntony closed 6 years ago

SimonAntony commented 7 years ago

Umbraco version 7.6.6 brand new site Using the new starter kit Setup personalisation as per Andy's examples but also added another group which is set as following:

Match: All Duration in group: Per Visitor (also tried session) Score: 50 Criteria: Number of visits - visitor has viewed the site more than 5 times.

windows_7_dev_64bit

Three blog posts, last one should only show when visits > 5 (using the above group).

What happens is that the personalisationGroupsNumberOfVisits cookie is not incrementing each time I visit the site. The personalisationGroupsPagesViewed is working as expected and shows the nodes visited so obviously cookie set code is working.

windows_7_dev_64bit

Digging into the source, I managed to trace through to TrackSession in RegisterApplicationEvents. Line 40 gets this cookie, however it's always null hence a new one is created again - as the count is always set to 1, the condition is not triggered and hence the blog post is not showing.

windows_7_dev_64bit

First time i've used this so maybe something else is wrong, especially as nobody has reported it before. I may have time to try and older version of the package and Umbraco to see if this worked ok previously.

AndyButland commented 7 years ago

Hi Simon - not too sure of the reason for the issue you are having but I don't think the issue you've raised in the source is the problem.

What's going on here is that it first looks for a session cookie - to see if the current visit has been tracked. If it doesn't find it, it then looks for a second, persistent cookie. If it finds that it increments the value by 1, and if it doesn't find it it creates it with a value of 1. Then it sets the session cookie such that the persistent cookie isn't updated again within the course of the users session.

So what should happen this is if you come back to the site in a new session (i.e. open a new browser, or an incognito window) the session cookie won't exist and so the persistent cookie will be checked, found and it's value incremented. So first probably just making sure you are definitely starting a new session to see the value increment further.

AndyButland commented 7 years ago

See also https://github.com/AndyButland/UmbracoPersonalisationGroups/issues/9

jarfer commented 7 years ago

Hi Andy,

Thanks for the feedback! I've tested this further and think I may have found something (not sure if this is down to language / communication or whether an actual bug):

Bascially we were testing this with "number of visits" feature (i.e. when visitor has made 5 web requests to the site for example).

When using "Duration in group:" set to "Per Session" this behaves as I would expect: The counter is only incremented only when a new session is initiated and the user visits the site (I do this by closing down all instances of my browser and launching again, this has the desired effect - new session, increments visits by 1)

However, when setting "Duration in group:" set to "Per Page Request" I would expect this counter to increment with every page access, which it doesn't (see line 37 of RegisterApplicationEvents.cs) - the increment of the page view count happens only inside the condition where the session cookie is null, hence it will only increment view count on new session, regardless of how "duration in group" is set.

Not sure if this is more down to my misunderstanding of what these options mean - but based on the language, I would have expected this to track each page view, not just those that happen within a new sesison (if this makes sense!)

Sorry to ramble, hope this helps!

Rog

AndyButland commented 7 years ago

Hi Rog

I see the confusion - and maybe need to consider naming better here - but actually these two things are different concepts.

The "Number of visits" criteria is intended to always be under of unique session to the website. So you'd have to close your browser/open an incognito window before a second visit would be counted.

The "Duration in group" is something that applies across all criteria. The intention here is to decide how often you want to check if a user is still in a given group.

Say for example you have a querystring criteria, that checks whether a given querystring exists when you land on the site, which is then used to personalise something on the home page. If the user then clicks around the site a bit and then returns to the home page without the querystring existing any more, should the home page be personalised as it was when they first arrived? Or should it treat the user as no longer being in the group (as the querystring is no longer present) and hence present something different? How about if they come back without the querystring next week?

The "duration in group" option allows you to control this - either fixing the user in the group for a given page request, a given session, or persistently across sessions.

Hope that helps clear it up!