Search code examples
sitecoredms

Set expiration of Sitecore DMS Global cookie


I am currently working on a Sitecore 7.2 solution and the client asked us if we can change the expiration of the Global analytics cookie "SC_ANALYTICS_GLOBAL_COOKIE". We can see it is persisted for 10 years, which is odd because Sitecore documentation states it should be one year.

Apart from 10 years vs 1 year I went searching for answers but have not found any. I also went on a config/decompile mission but havent found the line yet where the cookie is saved.

So my main question is: is it possible to adjust the amount of time the global cookie is persisted?

Bonus kudos for anyone who can elaborate on the difference in documentation (1 year) vs reality (10 years) and why this seemingly insane amount of 10 years is used.


Solution

  • Sitecore global analytics cookie is saved by the VisitorKeyCookie class.

    Expires value is hardcoded as:

    httpCookie.Expires = 
        this.IsInvalid 
        ? DateTime.UtcNow.AddDays(-1.0) 
        : DateTime.UtcNow.AddYears(10);
    

    So the answer is No. You cannot change this 10 years value.

    The idea of this cookie is to be able to identify the visitor which uses particular browser and it doesn't matter if they are back after week, month, year or 5 years. I guess that's why the cookie expiry is set to 10 years.

    Why it's inconsistent with the documentation is another question ;) You should mention this to Sitecore.