public async Task <TrackingResult> TrackTransactionAsync(string orderId, string storeName, string total, string tax, string shipping, string city, string region, string country, Dictionary <string, string> beaconParameters = null, string userAgent = null)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("utmwv", AnalyticsVersion);
            parameters.Add("utmn", GenerateUtmn());
            parameters.Add("utmhn", Hostname);
            parameters.Add("utmt", "transaction");
            parameters.Add("utmcs", CharacterSet);
            parameters.Add("utmul", Language);
            parameters.Add("utmhid", AnalyticsSession.GenerateSessionId());
            parameters.Add("utmac", TrackingAccount);
            parameters.Add("utmcc", AnalyticsSession.GenerateCookieValue());

            parameters.Add("utmtid", orderId);
            parameters.Add("utmtst", storeName);
            parameters.Add("utmtto", total);
            parameters.Add("utmttx", tax);
            parameters.Add("utmtsp", shipping);
            parameters.Add("utmtci", city);
            parameters.Add("utmtrg", region);
            parameters.Add("utmtco", country);

            // Add beacon parameters (these always override defaults)
            if (beaconParameters != null)
            {
                foreach (var beaconParameter in beaconParameters)
                {
                    parameters[beaconParameter.Key] = beaconParameter.Value;
                }
            }

            return(await RequestUrlAsync(UseSsl?BeaconUrlSsl : BeaconUrl, parameters, userAgent ?? UserAgent));
        }
 /// <summary>
 /// Set additional properties in parameters if they are empty: CacheBuster.
 /// The CacheBuster is set when UseHttpGet flag is set.
 /// <para>
 /// Override to change other properties.</para>
 /// </summary>
 /// <param name="parameters">GA request parameters.</param>
 protected virtual void AmendParameters(IGeneralParameters parameters)
 {
     if (UseHttpGet && string.IsNullOrEmpty(parameters.CacheBuster))
     {
         parameters.CacheBuster = AnalyticsSession.GenerateCacheBuster();
     }
 }
        public async Task <TrackingResult> TrackPageViewAsync(string pageTitle, string pageUrl, Dictionary <string, string> beaconParameters = null, string userAgent = null)
        {
            // Add defaults
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("utmwv", AnalyticsVersion);
            parameters.Add("utmn", GenerateUtmn());
            parameters.Add("utmhn", Hostname);
            parameters.Add("utmcs", CharacterSet);
            parameters.Add("utmul", Language);
            parameters.Add("utmdt", pageTitle);
            parameters.Add("utmhid", AnalyticsSession.GenerateSessionId());
            parameters.Add("utmp", pageUrl);
            parameters.Add("utmac", TrackingAccount);
            parameters.Add("utmcc", AnalyticsSession.GenerateCookieValue());

            var utme = _utmeGenerator.Generate();

            if (!string.IsNullOrEmpty(utme))
            {
                parameters.Add("utme", utme);
            }

            // Add beacon parameters (these always override defaults)
            if (beaconParameters != null)
            {
                foreach (var beaconParameter in beaconParameters)
                {
                    parameters[beaconParameter.Key] = beaconParameter.Value;
                }
            }

            return(await RequestUrlAsync(UseSsl?BeaconUrlSsl : BeaconUrl, parameters, userAgent ?? UserAgent));
        }
        public async Task <TrackingResult> TrackEventAsync(string category, string action, string label, int value, bool nonInteraction = false, Dictionary <string, string> beaconParameters = null, string userAgent = null)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("utmwv", AnalyticsVersion);
            parameters.Add("utmn", GenerateUtmn());
            parameters.Add("utmhn", Hostname);
            parameters.Add("utmni", "1");
            parameters.Add("utmt", "event");
            var utme = _utmeGenerator.Generate();

            parameters.Add("utme", string.Format("5({0}*{1}*{2})({3})", category, action, label ?? "", value) + utme);
            if (nonInteraction)
            {
                parameters.Add("utmi", "1");
            }

            parameters.Add("utmcs", CharacterSet);
            parameters.Add("utmul", Language);
            parameters.Add("utmhid", AnalyticsSession.GenerateSessionId());
            parameters.Add("utmac", TrackingAccount);
            parameters.Add("utmcc", AnalyticsSession.GenerateCookieValue());

            // Add beacon parameters (these always override defaults)
            if (beaconParameters != null)
            {
                foreach (var beaconParameter in beaconParameters)
                {
                    parameters[beaconParameter.Key] = beaconParameter.Value;
                }
            }

            return(await RequestUrlAsync(UseSsl?BeaconUrlSsl : BeaconUrl, parameters, userAgent ?? UserAgent));
        }
        public async Task <TrackingResult> TrackTransactionItemAsync(string orderId, string productId, string productName, string productVariation, string productPrice, string quantity, Dictionary <string, string> beaconParameters = null, string userAgent = null)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("utmwv", AnalyticsVersion);
            parameters.Add("utmn", GenerateUtmn());
            parameters.Add("utmhn", Hostname);
            parameters.Add("utmt", "item");
            parameters.Add("utmcs", CharacterSet);
            parameters.Add("utmul", Language);
            parameters.Add("utmhid", AnalyticsSession.GenerateSessionId());
            parameters.Add("utmac", TrackingAccount);
            parameters.Add("utmcc", AnalyticsSession.GenerateCookieValue());

            parameters.Add("utmtid", orderId);
            parameters.Add("utmipc", productId);
            parameters.Add("utmipn", productName);
            parameters.Add("utmiva", productVariation);
            parameters.Add("utmipr", productPrice);
            parameters.Add("utmiqt", quantity);

            // Add beacon parameters (these always override defaults)
            if (beaconParameters != null)
            {
                foreach (var beaconParameter in beaconParameters)
                {
                    parameters[beaconParameter.Key] = beaconParameter.Value;
                }
            }

            return(await RequestUrlAsync(UseSsl?BeaconUrlSsl : BeaconUrl, parameters, userAgent ?? UserAgent));
        }
示例#6
0
        private void SetRequired(IGeneralParameters parameters)
        {
            parameters.TrackingId = TrackingAccount;
            parameters.ClientId   = AnalyticsSession.GenerateSessionId();

            if (string.IsNullOrWhiteSpace(parameters.UserLanguage))
            {
                // Note: another way could be CultureInfo.CurrentCulture
                parameters.UserLanguage = "en-US";
            }
        }
        /// <summary>
        /// Set base, required parameters if they are empty: TrackingId, ClientId.
        /// </summary>
        /// <param name="parameters">GA request parameters.</param>
        private void SetRequiredParameters(IGeneralParameters parameters)
        {
            if (string.IsNullOrEmpty(parameters.ProtocolVersion))
            {
                throw new ArgumentException("No ProtocolVersion", nameof(parameters));
            }

            if (string.IsNullOrEmpty(parameters.TrackingId))
            {
                parameters.TrackingId = TrackingAccount;
            }

            if (string.IsNullOrEmpty(parameters.ClientId))
            {
                parameters.ClientId = AnalyticsSession.GenerateSessionId();
            }
        }
示例#8
0
 private void SetRequired(IGeneralParameters parameters)
 {
     parameters.TrackingId = TrackingAccount;
     parameters.ClientId   = AnalyticsSession.GenerateSessionId();
 }