public ResponseObject IsTimeSpentCurrentNode(string nodeId) { var response = new ResponseObject(); response.Success = false; var segments = NcbtSegment.GetAllLight(); foreach (var s in segments) { var id = s.Id; var segment = NcbtSegment.GetById(id); var alias = s.Alias; if (segment.CriterionGroups.Count() > 0) { foreach (var cGroup in segment.CriterionGroups) { foreach (var c in cGroup.Criterions) { if (c.PropertyAlias == "idw.timeSpent") { var validNodes = c.PropertyValue; if (validNodes.Contains(nodeId)) { response.Success = true; response.Alias = alias; response.Delay = int.Parse(validNodes.Split('|')[0].ToString()); } } } } } } return(response); }
public static void AddToSegment(HttpContextBase httpContext, NcbtSegment segment) { if (segment == null) { throw new ArgumentNullException(nameof(segment)); } var responseCookies = httpContext.Response.Cookies; var cookieName = string.Format(CookieNameFormat, segment.Alias); var cookie = new HttpCookie(cookieName); if (segment.Persistence == 0) { // Persistence: None. cookie.Expires = DateTime.MinValue; // Session. } else if (segment.Persistence < 0) { // Persistence: Permanent. cookie.Expires = DateTime.UtcNow.AddYears(5); responseCookies.Add(cookie); } else if (segment.Persistence > 0) { // Persistence: X days. cookie.Expires = DateTime.UtcNow.AddDays(segment.Persistence); if (httpContext.Request.Cookies[cookieName] != null) { // Don't update existing cookies that expire after X days. return; } responseCookies.Add(cookie); } }
public void AddToSegment(string visitorId, NcbtSegment segment) { if (visitorId == null) { throw new ArgumentNullException(nameof(visitorId)); } AddToSegment(httpContextAccessor(), segment); }
public static void AddVisitorToSegment(string visitorId, NcbtSegment segment) { if (!CanSegment) { return; } foreach (var segmenter in Segmenters) { segmenter.AddToSegment(visitorId, segment); } }
public void AddToSegment(string visitorId, NcbtSegment segment) { try { BlockingEnqueue(visitorId, new Dictionary <string, string> { [segment.Alias] = DateTimeOffset.UtcNow.ToString("O") }); } catch (Exception ex) { LogHelper.Error <CustomerIoTrackingDataSource>($"Could not put {visitorId} into {segment.Alias}.", ex); } }
/// <summary> /// Counts the number of visitors in a given segment /// </summary> /// <param name="segmentAlias">Alias of the segment</param> /// <returns>Number of visitors</returns> public static long CountVisitorsInSegment(string segmentAlias) { if (!CanAggregate) { return(0); } var segment = NcbtSegment.GetByAlias(segmentAlias); if (segment == null) { return(0); } return(Aggregators.Select(x => x.CountVisitorsInSegment(segment)).Max()); }
public bool IsVisitorInSegment(string visitorId, NcbtSegment segment) { if (visitorId == null) { throw new ArgumentNullException(nameof(visitorId)); } if (segment == null) { throw new ArgumentNullException(nameof(segment)); } var httpContext = httpContextAccessor(); var requestCookies = httpContext.Request.Cookies; var cookieName = string.Format(CookieNameFormat, segment.Alias); return(requestCookies.AllKeys.Any(x => x == cookieName)); }
/// <summary> /// Gets a list of visitors in a given segment with the passed property settings<br/> /// Dictionary contains aliases and a bool describing whether or not they should be set or not /// </summary> /// <param name="segmentAlias">Alias of the segment</param> /// <param name="properties">Dictionary of properties to include or not</param> /// <returns>List of visitors in segment</returns> public static List <dynamic> GetVisitorsInSegmentWithProperties(string segmentAlias, Dictionary <string, bool> properties) { if (!CanAggregate) { return(new List <dynamic>()); } var segment = NcbtSegment.GetByAlias(segmentAlias); if (segment == null) { return(new List <dynamic>()); } return(Aggregators.Select(x => x.GetVisitorsInSegmentWithProperties(segment, properties)) .OrderByDescending(x => x.Count) .First() .ToList()); }
/// <summary> /// Gets a list of visitors in a given segment /// </summary> /// <param name="segmentAlias">Alias of the segment</param> /// <returns>List of visitors in segment</returns> public static List <dynamic> GetVisitorsInSegment(string segmentAlias) { // TODO: Remove? if (!CanAggregate) { return(new List <dynamic>()); } var segment = NcbtSegment.GetByAlias(segmentAlias); if (segment == null) { return(new List <dynamic>()); } return(Aggregators.Select(x => x.GetVisitorsInSegment(segment)) .OrderByDescending(x => x.Count) .First() .ToList()); }
public static string SetVisitorProperty(string visitorId, IReadOnlyDictionary <string, object> values) { if (CanWrite) { foreach (var writer in Writers) { writer.SetVisitorProperties(visitorId, values); } } foreach (var segment in NcbtSegment.GetAllLight()) { if (IsVisitorInSegment(visitorId, segment.Alias)) { AddVisitorToSegment(visitorId, segment); } } return(visitorId); }
public static string PushToVisitorProperty(string visitorId, string key, object value) { // TODO: Remove? if (CanWrite) { foreach (var writer in Writers) { writer.PushToVisitorProperty(visitorId, key, value); } } foreach (var segment in NcbtSegment.GetAllLight()) { if (IsVisitorInSegment(visitorId, segment.Alias)) { AddVisitorToSegment(visitorId, segment); } } return(visitorId); }
public static bool IsVisitorInSegment(string visitorId, string segmentAlias) { var segment = NcbtSegment.GetByAlias(segmentAlias); if (segment == null) { return(false); } if (CanRead) { foreach (var reader in Readers) { var isInSegment = reader.IsVisitorInSegment(visitorId, segment); if (isInSegment) { return(true); } } } return(false); }