private void DoGoogleAnalyticsTracking()
        {
            if (order == null)
            {
                return;
            }
            if (order.AnalyticsTracked)
            {
                return;
            }
            if (store == null)
            {
                return;
            }

            try
            {
                mojoGoogleAnalyticsScript analytics = Page.Master.FindControl("mojoGoogleAnalyticsScript1") as mojoGoogleAnalyticsScript;
                if (analytics == null)
                {
                    DoAsyncTracking(); return;
                }

                AnalyticsTransaction transaction = new AnalyticsTransaction();
                transaction.OrderId   = order.OrderGuid.ToString();
                transaction.City      = order.CustomerCity;
                transaction.Country   = order.CustomerCountry;
                transaction.State     = order.CustomerState;
                transaction.StoreName = siteSettings.SiteName + " - " + store.Name;
                transaction.Tax       = order.TaxTotal.ToString(CultureInfo.InvariantCulture);
                transaction.Total     = order.OrderTotal.ToString(CultureInfo.InvariantCulture);

                foreach (OrderOffer offer in order.OrderOffers)
                {
                    AnalyticsTransactionItem item = new AnalyticsTransactionItem();
                    item.Category    = string.Empty;
                    item.OrderId     = order.OrderGuid.ToString();
                    item.Price       = offer.OfferPrice.ToString(CultureInfo.InvariantCulture);
                    item.ProductName = offer.Name;
                    item.Quantity    = offer.Quantity.ToString(CultureInfo.InvariantCulture);
                    item.Sku         = offer.OfferGuid.ToString();
                    transaction.Items.Add(item);
                }

                if (transaction.IsValid())
                {
                    analytics.Transactions.Add(transaction);
                    Order.TrackAnalytics(order.OrderGuid);
                }
            }
            catch (Exception ex)
            {
                log.Error("error tracking order in google analytics.", ex);
            }
        }
        private void DoAsyncTracking()
        {
            AnalyticsAsyncTopScript analytics = Page.Master.FindControl("analyticsTop") as AnalyticsAsyncTopScript;

            if (analytics == null)
            {
                return;
            }

            AnalyticsTransaction transaction = new AnalyticsTransaction();

            transaction.OrderId   = order.OrderGuid.ToString();
            transaction.City      = order.CustomerCity;
            transaction.Country   = order.CustomerCountry;
            transaction.State     = order.CustomerState;
            transaction.StoreName = siteSettings.SiteName + " - " + store.Name;
            transaction.Tax       = order.TaxTotal.ToString(CultureInfo.InvariantCulture);
            transaction.Total     = order.OrderTotal.ToString(CultureInfo.InvariantCulture);

            foreach (OrderOffer offer in order.OrderOffers)
            {
                AnalyticsTransactionItem item = new AnalyticsTransactionItem();
                item.Category    = string.Empty;
                item.OrderId     = order.OrderGuid.ToString();
                item.Price       = offer.OfferPrice.ToString(CultureInfo.InvariantCulture);
                item.ProductName = offer.Name;
                item.Quantity    = offer.Quantity.ToInvariantString();
                item.Sku         = offer.OfferGuid.ToString();
                transaction.Items.Add(item);
            }

            if (transaction.IsValid())
            {
                analytics.Transactions.Add(transaction);
                Order.TrackAnalytics(order.OrderGuid);
            }
        }