Google Analytics Ecommerce conversion code decimal issue

Options
A while back we had assiatance with an outside agency and Luminate support to put together the necessary scripting to feed donation info to Google Analytics to show ecommerce conversions. The code was placed, but the position handling the monitoring and recording of the GA info was only recently filled. Now, in loking at the conversions, we find that anything over three digits - $1,000 or more, the decimal is somehow messing up. Whill 999.00 is that, $1000 gets reported to GA at $1.00; $10,000 becomes $10, etc. I have tried to dissect the files that controls the feed to GA, but the coding makes no sense to me, so I am not able to determine what needs correcting to make the decimal right. Any help is appreciated.


This first piece of code, if I recall, simply grabs the info, so I do not think the issues is here since there is no place where any decimal or amount is converted, but I provide it since it is part of the feed to GA.


<!-- Google Analytics Ecommerce Portion -->

<script type="text/javascript">// <![CDATA[

_gaq.push(['_addTrans',

'<convio:session param="dc:transactionID" name="120"></convio:session>', // order ID - required

'', // affiliation or store name

'<convio:session param="dc:giftAmount" name="120"></convio:session>', // total - required

'', // tax

'', // shipping

'<convio:session param="dc:donorCity" name="120"></convio:session>', // city

'<convio:session param="dc:donorState" name="120"></convio:session>', // state or province

'<convio:session param="dc:donorCountry" name="120"></convio:session>' // country

]);


_gaq.push(['_addItem',

'<convio:session param="dc:transactionID" name="120"></convio:session>', // order ID - required

'<convio:session param="dc:designeeNames" name="120"></convio:session>', // SKU/code - required

'<convio:session param="dc:designeeNames" name="120"></convio:session>', // product name

'', // category or variation

'<convio:session param="dc:giftAmount" name="120"></convio:session>', // unit price - required

'1' // quantity - required

]);

_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

// ]]></script>


This is the piece that I think may contain something that is causing the issue, and hope someone out there with coding experience may identify a missing slash or something to fix the error. My attention is draw to the line in the third section - 'transactionTotal': amount.value.replace(/\\$/,''), - since it seems to be dealing with the amount.


<script type="text/javascript">



console.log('e_load');

//Url params

var urlParams = function(name) {

var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);

if (results == null) {

return null;

} else {

return results[1] || 0;

}

};



//function to search element into transaction summary entries and return value

var searchFor = function(textToSearch){

result = { label:'',value:'' };

var transactionEle = document.getElementsByClassName('transaction-summary-entry');

for(var i=0; i<transactionEle.length;i++){

var labels = transactionEle[i].getElementsByClassName('entry-label');

for(var j=0; j<labels.length;j++){

//indentify the text into entry label and assign the value if exists

if(textToSearch.toLowerCase().indexOf(labels[j].textContent.toLowerCase())>-1 ){

result.label = textToSearch;

result.value = transactionEle[i].getElementsByClassName('entry-value')[0].textContent;

return result;

}

}

}

return result;

}



var tracking_code = searchFor('Tracking Code:');

var amount = searchFor('Total Gift Amount:');

var formId = urlParams('df_id');

//validate data is filled

if(tracking_code.value && amount.value && formId){

//push transaction

window.dataLayer = window.dataLayer || []

dataLayer.push({

'transactionId': tracking_code.value,

'transactionTotal': amount.value.replace(/\\$/,''),

'transactionTax': 0,

'transactionProducts': [{

'sku': 'df_id='+formId,

'name': 'form-id-'+formId,

'category': 'Donation',

'price': amount.value.replace(/\\$/,''),

'quantity': 1

}]

});

console.log('e_ok');

}


</script>
Tagged:

Comments

  • Most probably the issue is with the lines that pass gift amount:


    <convio:session param="dc:giftAmount" name="120"></convio:session>

    The values for the price and total parameters do not respect any currency formatting. Currency conversions ought to be handled before sending the data to the Google Analytics server. Try replacing above dc:giftAmount tags with this one:


    [[E130:"[[S120:dc:giftAmount]]" number]]

    update:

    To cover all areas, you can also remove currency formatting in the second dataLayer.push call by replacing all:


    amount.value.replace(/\\$/,'')

    With:


    Number(amount.value.replace(/[^0-9\\.-]+/g,""))
  • Is it legitimate for me to simply swap in

    [[E130:"[[S120:dc:giftAmount]]" number]] in place of <convio:session param="dc:giftAmount" name="120"></convio:session>

    with it being the two different code formats? Will there be any conflict, or do I need to convert the rest of the codes to match?
  • Romany Nassief:

    Most probably the issue is with the lines that pass gift amount:


    <convio:session param="dc:giftAmount" name="120"></convio:session>

    The values for the price and total parameters do not respect any currency formatting. Currency conversions ought to be handled before sending the data to the Google Analytics server. Try replacing above dc:giftAmount tags with this one:


    [[E130:"[[S120:dc:giftAmount]]" number]]

    update:

    To cover all areas, you can also remove currency formatting in the second dataLayer.push call by replacing all:


    amount.value.replace(/\\$/,'')

    With:


    Number(amount.value.replace(/[^0-9\\.-]+/g,""))

    So, I went ahead and inserted the text as is, figuring it would work, and it did. But here is what I find. In the initial gathering code, the dc:giftAmount line appears twice. It is in the first half, which is for addTrans, and then again in second half, for addItem. I placed

    [[E130:"[[S120:dc:giftAmount]]" number]]

    in just the bottom section. I ran a test donation through, and viewed the source of the thank you page. The top half, where I left the original code in, got fed '$12.00' and the bottom section where I placed the new code, received '12' which seems opposite of what I had expected. Does that sound right - should it just return an unformatted solid number?
  • Romany Nassief:

    Most probably the issue is with the lines that pass gift amount:


    <convio:session param="dc:giftAmount" name="120"></convio:session>

    The values for the price and total parameters do not respect any currency formatting. Currency conversions ought to be handled before sending the data to the Google Analytics server. Try replacing above dc:giftAmount tags with this one:


    [[E130:"[[S120:dc:giftAmount]]" number]]

    update:

    To cover all areas, you can also remove currency formatting in the second dataLayer.push call by replacing all:


    amount.value.replace(/\\$/,'')

    With:


    Number(amount.value.replace(/[^0-9\\.-]+/g,""))

    I have placed both code tweaks in place, and ran a test donation, but the results were the same. A donation of 1003.32 was sent to GA (I checked the source code of the thank you page and that amount was captured), but GA shows it as $1.00. :(


    Any other ideas?

Categories