Esempio n. 1
0
        /// <summary>
        /// Makes a matched group sticky for the visitor via a cookie setting according to group definition
        /// </summary>
        /// <param name="definition">Matched group definition</param>
        /// <param name="groupNodeId">Id of the matched groups node</param>
        internal static void MakeStickyMatch(PersonalisationGroupDefinition definition, int groupNodeId)
        {
            if (definition.Duration == PersonalisationGroupDefinitionDuration.Page)
            {
                return;
            }

            var key            = GetCookieKeyForMatchedGroups(definition.Duration);
            var cookieProvider = new HttpContextCookieProvider();
            var cookie         = cookieProvider.GetCookie(key);

            if (cookie != null)
            {
                cookie.Value = AppendGroupNodeId(cookie.Value, groupNodeId);
            }
            else
            {
                cookie = new HttpCookie(key)
                {
                    Value    = groupNodeId.ToString(),
                    HttpOnly = true,
                };
            }

            if (definition.Duration == PersonalisationGroupDefinitionDuration.Visitor)
            {
                var cookieExpiryInDays = PersonalisationGroupsConfig.Value.PersistentMatchedGroupsCookieExpiryInDays;
                cookie.Expires = DateTime.Now.AddDays(cookieExpiryInDays);
            }

            cookieProvider.SetCookie(cookie);
        }
Esempio n. 2
0
        public static void TrackSession(object sender, EventArgs e)
        {
            var config         = PersonalisationGroupsConfig.Value;
            var cookieProvider = new HttpContextCookieProvider();

            // Check if session cookie present
            var sessionCookie = cookieProvider.GetCookie(config.CookieKeyForTrackingIfSessionAlreadyTracked);

            if (sessionCookie == null)
            {
                // If not, create or update the number of visits cookie
                var trackingCookie = cookieProvider.GetCookie(config.CookieKeyForTrackingNumberOfVisits);
                if (trackingCookie != null)
                {
                    trackingCookie.Value = int.TryParse(trackingCookie.Value, out int cookieValue) ? (cookieValue + 1).ToString() : "1";
                }
                else
                {
                    trackingCookie = new HttpCookie(config.CookieKeyForTrackingNumberOfVisits)
                    {
                        Value    = "1",
                        HttpOnly = true,
                    };
                }

                trackingCookie.Expires = DateTime.Now.AddDays(config.NumberOfVisitsTrackingCookieExpiryInDays);
                cookieProvider.SetCookie(trackingCookie);

                // Set the session cookie so we don't keep updating on each request
                sessionCookie = new HttpCookie(config.CookieKeyForTrackingIfSessionAlreadyTracked)
                {
                    Value    = "1",
                    HttpOnly = true,
                };
                cookieProvider.SetCookie(sessionCookie);
            }
        }
Esempio n. 3
0
        public static void TrackPageView(int pageId)
        {
            var cookieProvoder = new HttpContextCookieProvider();
            var config         = PersonalisationGroupsConfig.Value;
            var key            = config.CookieKeyForTrackingPagesViewed;
            var cookie         = cookieProvoder.GetCookie(key);

            if (cookie != null)
            {
                cookie.Value = AppendPageIdIfNotPreviouslyViewed(cookie.Value, pageId);
            }
            else
            {
                cookie = new HttpCookie(key)
                {
                    Value = pageId.ToString(), HttpOnly = true,
                };
            }

            cookie.Expires = DateTime.Now.AddDays(config.ViewedPagesTrackingCookieExpiryInDays);
            cookieProvoder.SetCookie(cookie);
        }