简体   繁体   English

Google Analytics(分析):从后台删除/编辑交易

[英]Google Analytics : remove/edit a transaction from back-office

I have a little problem with Analytics. 我对Google Analytics(分析)有一点问题。

To correct some mistakes that may appear in transactions (user not coming back on the site after payment for exemple) I tried to implement a fixing page in the back office. 为了更正交易中可能出现的一些错误(用户支付示例费用后用户没有回到网站上),我尝试在后台安装固定页面。

With the PHP API, i retrieve all of the transactions and I display it them into a table with an input and a button to execute removing script. 使用PHP API,我检索了所有事务,并将它们显示在带有输入和按钮的表中,以执行删除脚本。

But it doesn't work. 但这是行不通的。 The code is executed correctly, and Analytics Chrome extension sees no error, but there is no modification in the stats. 该代码已正确执行,并且Google Analytics(分析)Chrome扩展程序未看到任何错误,但统计信息中没有任何修改。

Here is a sample of my code. 这是我的代码示例。

//Top of my page

<script type="text/javascript">
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-10XX3X1-1', 'xxxxxxx.com');
    ga('require', 'ecommerce', 'ecommerce.js');
</script>

/*
Display of Transactions
*/

<script type="text/javascript">
        function modifiyTransaction(e){
            var valueT=document.getElementById(e.name).value.toString();
            console.log(typeof valueT+" : "+ valueT);
            console.log(typeof e.name+" : "+ e.name);

                    //Fixing transactions

                    ga('ecommerce:addTransaction', {
                        'id': e.name, // order ID - required
                        'affiliation': 'Rental', // affiliation or store name
                        'revenue': valueT // total - required
                    });
                   ga('ecommerce:send');
                   $("#sendingEvent").show();
                   setTimeout(function(){
                        document.getElementById(e.name).value="Done";
                        $("#sendingEvent").hide();
                    }, 1000);
        }       
</script>

The value and the id I get are correct and both strings. 我得到的值和ID是正确的,并且都是字符串。

Does someone have a solution ? 有人有解决方案吗? :) :)

Edit : 编辑:

If this is not possible this way, can it be done directly via the PHP API ? 如果无法通过这种方式实现,可以直接通过PHP API完成吗? I did not see something related to this in the doc. 我在文档中没有看到与此相关的内容。

Ok so, using the Measurement Protocol with AJAX worked. 好的,可以将Measurement Protocol与AJAX结合使用。

Here is a sample of my code if someone is struggling with the same problem. 如果有人遇到同样的问题,这是我的代码示例。

$.ajax({
                type: "POST",
                url: 'https://ssl.google-analytics.com/collect',
                data: { v: "1", tid: "UA-XXXXXXXX-1", cid: clientId, 
                       t: "transaction", ti: transactionId, 
                       ta: "Rental", tr: valueToChange },
                success: function(){
                    $("#sendingEvent").hide();
                    document.getElementById(e.name).value="Done";
                },
                error: function(){
                    $("#sendingEvent").hide();
                    document.getElementById(e.name).value="Error!";
                }
            });

Finally super easy. 终于超级容易。

For more information : https://developers.google.com/analytics/devguides/collection/protocol/v1/?hl=fr + the developer guide and the reference guide linked in it. 有关更多信息: https : //developers.google.com/analytics/devguides/collection/protocol/v1/?hl=fr +开发人员指南和其中链接的参考指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM