public async Task <IActionResult> UserRegisteredEvent([FromBody] TrackEventModel model) { if (!ModelState.IsValid) { return(BadRequest(ErrorResponse.Create(ModelState.GetErrorMessage()))); } if (!model.UserId.IsValidPartitionOrRowKey()) { return(BadRequest(ErrorResponse.Create($"Invalid {nameof(model.UserId)} value"))); } if (!string.IsNullOrEmpty(model.Traffic)) { var traffic = GaTraffic.Parse(model.UserId, model.Traffic); if (traffic != null) { await _gaUserService.AddGaUserTrafficAsync(traffic); } } await _gaTrackerService.SendEventAsync(new TrackerInfo { UserId = model.UserId, UserAgent = model.UserAgent, ClientInfo = model.ClientInfo, Ip = model.Ip, CreatedAt = model.CreatedAt, Cid = model.Cid, Traffic = model.Traffic }, TrackerCategories.Users, TrackerEvents.UserRegistered); return(Ok()); }
private async Task <CachedGaTraffic> GetTrafficAsync(string clientId) { var traffic = await _trafficRepository.GetAsync(clientId); return(traffic == null ? new CachedGaTraffic(GaTraffic.CreateDefault(clientId)) : new CachedGaTraffic(traffic)); }
public async Task <GaTraffic> GetGaUserTrafficAsync(string clientId) { var cachedValue = await _cache.TryGetOrAddAsync( GetTrafficKey(clientId), async() => await GetTrafficAsync(clientId)); return(cachedValue == null ? GaTraffic.CreateDefault(clientId) : new GaTraffic { ClientId = cachedValue.ClientId, Source = cachedValue.Source, Medium = cachedValue.Medium, Campaign = cachedValue.Campaign, Keyword = cachedValue.Keyword, Content = cachedValue.Content }); }
public async Task <IActionResult> AddGaUserTraffic([FromBody] GaTrafficModel model) { if (!ModelState.IsValid) { return(BadRequest(ErrorResponse.Create(ModelState.GetErrorMessage()))); } var traffic = new GaTraffic { ClientId = model.ClientId, Source = model.Source, Medium = model.Medium, Campaign = model.Campaign, Keyword = model.Keyword, Content = model.Content }; await _gaUserService.AddGaUserTrafficAsync(traffic); return(Ok()); }