Matteobikk90
Matteobikk90

Reputation: 185

Google Analytics Refund not really working

I am using the Enhanced Ecommerce Refund option on my ecommerce combined with Google Analytics Debugger where the data that I send are displayed correctly but they don't appear at the google analytics panel and I am not sure why.

This is my current code:

                            var gaItemsReturn = {};

                            for (i = 0; i < res.length; ++i) {
                                if(res[i].returnEntry.type == "return") {
                                    enCode = res[i].returnEntry.product["@code"];

                                    if(!gaItemsReturn[enCode]) {
                                        gaItemsReturn[enCode]               = {};
                                        gaItemsReturn[enCode]["id"]         = enCode;
                                        gaItemsReturn[enCode]["sku"]        = enCode;
                                        gaItemsReturn[enCode]["quantity"]   = parseInt(res[i].returnEntry.quantity)
                                    }
                                    else {
                                        gaItemsReturn[enCode]["quantity"]   = gaItemsReturn[enCode]["quantity"] + 1;
                                    }

                                    ga('send', 'pageview', 'Return Product');

                                    ga('require', 'ec');

                                    $.each(gaItemsReturn, function(index, value) {
                                        // Refund a single product.
                                        ga('ec:addProduct', {
                                          'id': value["id"],                    // Product ID is required for partial refund.
                                          'quantity': value["quantity"]         // Quantity is required for partial refund.
                                        });
                                    });

                                    ga('ec:setAction', 'refund', {
                                      'id': jo["@code"]                         // Transaction ID is required for partial refund.
                                    });

                                    ga('send', 'event', 'Ecommerce', 'Refund');

                                }
                            }

I first create an empty object to check if I have a product with same SKU(code/id), loop through the res(single product) to see which one i return rathen then exchange bacause there is also this option but i don't want to send it to GA, of course. And then after few checks I send them. This is a current image of a positive response but as I mentioned they don't populate refund window in GA panel. What am I missing ? Google Analytics Debugger

Upvotes: 1

Views: 586

Answers (1)

vinoaj
vinoaj

Reputation: 1684

Everything looks in order here. Are you sure that jo["@code"] evaluates to a valid transaction ID that has already been recorded in GA?

For added assurance, you should ensure that whatever jo["@code"] evaluates to is surrounded by quote ( ' ) marks.

Upvotes: 1

Related Questions