WPPizza – A Restaurant Plugin for WordPress › Support › General Support › Variables to Populate Data Layer
- AuthorPosts
- 13 June, 2017 at 10:26 pm #28403
Hello Olly,
I need to populate a Data Layer (a java script code that sends information to google analytics) with dynamic information such as the order total value, delivery charge, product ID’s etc.
I have searched the templates and browser inspector for the variables that store those information, but couldn’t quite make it work.
Could you tell me what variable I should “echo” in my .js code to output the total value of the order, for example?
—-
For example, in the data layer code below ‘transactionTotal’ is a key with a value of 38.26. Since every transaction has a different value, I need to insert the variable that stores the transactionTotal of the order so it outputs the correct order value to my data layer.`
window.dataLayer = window.dataLayer || []
dataLayer.push({
‘transactionId’: ‘1234’,
‘transactionAffiliation’: ‘Acme Clothing’,
‘transactionTotal’: 38.26,
‘transactionShipping’: 5,
‘transactionProducts’: [{
‘sku’: ‘DD44’,
‘name’: ‘T-Shirt’,
‘category’: ‘Apparel’,
‘price’: 11.99,
‘quantity’: 1
},{
‘sku’: ‘AA1243544’,
‘name’: ‘Socks’,
‘category’: ‘Apparel’,
‘price’: 9.99,
‘quantity’: 2
}]
});`13 June, 2017 at 10:56 pm #28404wppizza v2x only- something like this perhaps:
add_action('wppizza_gateway_do_order_details', 'my_js_output', 10, 2); function my_js_output($orderDetails,$id){ print"<script>/* echo your js */</script>"; }
- AuthorPosts
- The topic ‘Variables to Populate Data Layer’ is closed to new replies.