Variables to Populate Data Layer

WPPizza – A Restaurant Plugin for WordPress Support General Support Variables to Populate Data Layer

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #28403
    David Cantidio
    Participant

      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
      }]
      });`

      #28404
      Olly
      Admin & Mod

        wppizza 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>";
        }
      Viewing 2 posts - 1 through 2 (of 2 total)
      • The topic ‘Variables to Populate Data Layer’ is closed to new replies.