public void Verify_That_Action_Without_Id_Throws_Exception()
        {
            // Arrange
            var action = new ActionFieldObject();

            action.List = "List";

            // Act
            string json = action.ToString();
        }
Example #2
0
        /// <summary>
        /// Tracks a purchase using the setAction and the purchase command.
        /// </summary>
        /// <remarks>
        /// You should use <seealso cref="ProductAdd"/> in additon to this, to register all
        /// the products that is part of the purchase
        /// </remarks>
        /// <see cref="https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-transactions"/>
        public void Purchase(string trackingNumber, string affiliation = null, double revenue = 0, double tax = 0, double shipping = 0, string coupon = null)
        {
            /* The actionFieldObject that is part of the purchase
             * 'id': 'T12345',                         // (Required) Transaction id (string).
             * 'affiliation': 'Google Store - Online', // Affiliation (string).
             * 'revenue': '37.39',                     // Revenue (currency).
             * 'tax': '2.85',                          // Tax (currency).
             * 'shipping': '5.34',                     // Shipping (currency).
             * 'coupon': 'SUMMER2013'
             */
            ActionFieldObject actionField = new ActionFieldObject()
            {
                Id          = trackingNumber,
                Affiliation = affiliation,
                Revenue     = revenue,
                Tax         = tax,
                Shipping    = shipping,
                Coupon      = coupon
            };

            // ga('ec:setAction', 'purchase', { ... });
            Action("purchase", actionField.ToString());
        }
        /// <summary>
        /// Tracks a purchase using the setAction and the purchase command.
        /// </summary>
        /// <remarks>
        /// You should use <seealso cref="ProductAdd"/> in additon to this, to register all
        /// the products that is part of the purchase
        /// </remarks>
        /// <see cref="https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-transactions"/>
        public void Purchase(string trackingNumber, string affiliation = null, double revenue = 0, double tax = 0, double shipping = 0, string coupon = null)
        {
            /* The actionFieldObject that is part of the purchase
              'id': 'T12345',                         // (Required) Transaction id (string).
              'affiliation': 'Google Store - Online', // Affiliation (string).
              'revenue': '37.39',                     // Revenue (currency).
              'tax': '2.85',                          // Tax (currency).
              'shipping': '5.34',                     // Shipping (currency).
              'coupon': 'SUMMER2013'
             */
            ActionFieldObject actionField = new ActionFieldObject()
            {
                Id = trackingNumber,
                Affiliation = affiliation,
                Revenue = revenue,
                Tax = tax,
                Shipping = shipping,
                Coupon = coupon
            };

            // ga('ec:setAction', 'purchase', { ... });
            Action("purchase", actionField.ToString());
        }