AbdFatah / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

Transaction cancellation sometimes does not work. #296

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi.

Sometimes clients of our e-store make several identical orders. I've developed 
special page to cancel such duplicates in google analytics. But js code 
provided in google help sometimes not working and duplicate transactions stays 
visible in google analytics report.

Please check following peace of js code, which should cancel transaction. If 
you need more information please let me know. Thank you.

(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);
})();

(function() {
    var _gaq = window._gaq || [],
        commands = [],
        orderId = '1294981831',
        isCancel = true,
        lsOrderNumKey = 'ga_orderNum';

    commands.push(['_setAccount', 'UA-5410075-2']);
    commands.push(['_setDomainName', '.edelweiss-service.ru']);

    var profit = '-610';
    //транзакция
    commands.push(['_addTrans',
        orderId,                            // transaction ID - required
        'Desktop',                          // affiliation or store name
        profit,                             // total - required; Shown as "Revenue" in the
                                            // Transactions report. Does not include Tax and Shipping.
        '0',                                // tax
        '',                                 // shipping
        'Пермь',      // city
        '',                                 // state or province
        'Россия'    // country
    ]);
    //элементы транзакции (содержимое корзины)
        commands.push(['_addItem',
        orderId,                   // transaction ID - necessary to associate item with transaction
        '363', // SKU/code - required
        '"Классика". Букет красных роз',  // product name - necessary to associate revenue with product
        'розы',   // category or variation
        '535',      // unit price - required
        '-1'     // quantity - required
    ]);
        commands.push(['_addItem',
        orderId,                   // transaction ID - necessary to associate item with transaction
        '0', // SKU/code - required
        'Доставка по городу Пермь',  // product name - necessary to associate revenue with product
        'доставка',   // category or variation
        '75',      // unit price - required
        '-1'     // quantity - required
    ]);

    //постим транзакцию
    commands.push(['_trackTrans']);

    _gaq.push.apply(_gaq, commands);
    window._gaq = _gaq;
})();

Original issue reported on code.google.com by AShuman...@gmail.com on 19 May 2013 at 6:51