0

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

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.