Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
Submit transaction is working fine when iam copy the basic example from analytics.js and hard code the parameter ,here iam using asynchronous method example. When i trying to pass dynamic valus from site it is not submitting transaction .
Please find the below code and update it and help

C#
$.ajax({
        type: "POST",
        url: "/WSHub/wsTransactionReceipt.asmx/GetOrderDetailsforanalytics",
        data: JSON.stringify(sdata),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var Total = 0;
            for (var i = 0; i < data.d.length; i++) {
                Total = Total + parseFloat(data.d[i].UnitPrice);
            }
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-48304226-1']);
            _gaq.push(['_trackPageview']);
            _gaq.push(['_addTrans',
                    '"' + objResult.SalesOrderNumber + '"',         // transaction ID - required
                    '',                                             // affiliation or store name
                    '"' + Total + '"',                              // total - required
                    '',                                             // tax
                    '',                                             // shipping
                    '',                                             // city
                    '',                                             // state or province
                    ''                                              // country
                  ]);
            for (var i = 0; i < data.d.length; i++) {
               // debugger;
                // add item might be called for every item in the shopping cart
                // where your ecommerce engine loops through each item in the cart and
                // prints out _addItem for each
                _gaq.push(['_addItem',
                    '"' + objResult.SalesOrderNumber + '"',    // transaction ID - required
                    '"' + data.d[i].SKUName + '"',             // SKU/code - required
                    '"' + data.d[i].ProductName + '"',         // product name
                    '',                                        // category or variation
                    '"' + data.d[i].UnitPrice + '"',           // unit price - required
                    '"' + data.d[i].Quantity + '"'             // quantity - required
                  ]);
            }
            _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
            (function () {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();
        }
    });
Posted
Updated 13-May-14 18:32pm
v4
Comments
Sergey Alexandrovich Kryukov 8-May-14 1:12am    
Not a question, no relevant information...
—SA
anilthyajman 13-May-14 8:21am    
Moved to the question...
Sergey Alexandrovich Kryukov 13-May-14 15:45pm    
Why not moving this code to the question body using "Improve question" (where it can be formatted in a readable way) and ask you question? Not a request for doing something for you, but a question. I am sorry to say, this is Quick Questions & Answers forum.
—SA
anilthyajman 14-May-14 0:37am    
Dear Sergey Alexandrovich Kryukov ,

I have updated the question using improve question option ,it is in readable format.
Please help it is urgent.
Sergey Alexandrovich Kryukov 14-May-14 0:41am    
Very nice, thank you for understanding...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900