I have this javascript code for google analytics;
<script>
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '3417327',
'affiliation': '',
'revenue': '59.90',
'shipping': '99.00',
'tax': '0'
});
ga('ecommerce:addItem', {
'id': '3417327',
'name': 'Sample',
'sku': '86454',
'category': '',
'price': '59.90',
'quantity': '1'
});
ga('ecommerce:send');
</script>
Please note that I can not modify the above code at all. Its is a template section that is hard coded, and I will be adding the required code in the footer section to get the output.
What I need is to use javascript or jquery to read the values of id, name, sku, affliation, revenue all and print it say in console.log. I tried by best to get some code but it all failed for me.
Can anyone help me I will highly appreciate
asked Sep 11, 2015 at 15:41
user3550203
7291 gold badge10 silver badges15 bronze badges
1 Answer 1
Try using intermediate variables for your parameters :
var myObject = {
'id': '3417327',
'name': 'Sample',
'sku': '86454',
'category': '',
'price': '59.90',
'quantity': '1'
};
ga('ecommerce:addItem', myObject);
console.log(myObject)//will print the object in the console.
answered Sep 11, 2015 at 15:46
Lauromine
1,48310 silver badges19 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
user3550203
Well the thing is I can not modify anything from the code that I added. So whatever code that I need to be used will go below this code and than I can use any function. So based on this your code will not work correct?
lang-js