Пример #1
0
        private async Task SendDataAsync(GaBaseHit model)
        {
            var data = model.Transform();

            _log.WriteInfo(nameof(SendDataAsync), data, model.Type);

            HttpResponseMessage response = await _gaSettings.ApiUrl
                                           .WithHeader("User-Agent", model.UserAgent)
                                           .PostUrlEncodedAsync(data);

            if (!response.IsSuccessStatusCode)
            {
                var res = await response.Content.ReadAsStringAsync();

                _log.WriteWarning(nameof(SendEventAsync), model, $"{_gaSettings.ApiUrl} returned {response.StatusCode}: {res}");
            }
        }
Пример #2
0
        private async Task FillGaHitAsync(GaBaseHit model)
        {
            GaUser gaUser = await _gaUserService.GetGaUserAsync(model.UserId, model.Cid);

            model.UserId     = gaUser.TrackerUserId;
            model.Cid        = gaUser.Cid;
            model.TrackingId = _gaSettings.ApiKey;

            model.Traffic = await _gaUserService.GetGaUserTrafficAsync(gaUser.ClientId);

            var deviceInfo = new DeviceInfo();

            deviceInfo.ParseUserAgent(model.UserAgent);
            deviceInfo.ParseClientInfo(model.ClientInfo);

            model.UserAgent        = deviceInfo.GetUserAgentString();
            model.ScreenResolution = deviceInfo.ScreenResolution;
            model.AppVersion       = deviceInfo.AppVersion;
        }