Title: Data layer variable
Last modified: October 12, 2020

---

# Data layer variable

 *  Resolved [alezucchi](https://wordpress.org/support/users/alezucchi/)
 * (@alezucchi)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/data-layer-variable/)
 * Hello, can you tell me the php variable to push the brand into data layer?
 * I tried something like
 *     ```
       <script>
       	window.dataLayer = window.dataLayer || [];
             dataLayer.push({
                 'event' : 'acquisto',
       		  'ecommerce': {
                   'currencyCode': '<?php echo $order->get_order_currency(); ?>',
                   'purchase': {
                     'actionField':{
                       'id': '<?php echo $order->get_order_number(); ?>',
                       'affiliation': 'WooCommerce',
                       'revenue': <?php echo number_format($order->get_subtotal(), 2, ".", ""); ?>,
                       'tax': <?php echo number_format($order->get_total_tax(), 2, ".", ""); ?>,
                       'shipping': <?php echo number_format($order->calculate_shipping(), 2, ".", ""); ?>,
                       <?php if($order->get_used_coupons()): ?>
                           'coupon': '<?php echo implode("-", $order->get_used_coupons()); ?>'
                       <?php endif; ?>
                     },
                     'products': [
                         <?php
                           foreach($order->get_items() as $key => $item):
                             $product = $order->get_product_from_item( $item );
                             $variant_name = ($item['variation_id']) ? wc_get_product($item['variation_id']) : '';
                         ?>
                             {
                               'name': '<?php echo $item['name']; ?>',
                               'id': '<?php echo $item['product_id']; ?>',
                                'price': '<?php echo number_format ($product->get_sale_price(), 2, ".", ""); ?>',
                               'variant': '<?php echo ($variant_name) ? implode("-", $variant_name->get_variation_attributes()) : ''; ?>',
       						   'brand': '<?php echo $brands['name']; ?>',
                               'quantity': <?php echo $item['qty']; ?>
                             },
                         <?php endforeach; ?>
                       ]
                   }
                 }
             });
           </script>
       ```
   
 * but i gut empty field in data layer.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdata-layer-variable%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [alezucchi](https://wordpress.org/support/users/alezucchi/)
 * (@alezucchi)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/data-layer-variable/#post-13552481)
 * hello, can you help me?
 * more specifically i’m trying to insert tis line to get brand in data layer
 *  ‘brand’: ‘<?php echo $brands[‘name’]; ?>’,
 * thank you
 * AZ
 *  Thread Starter [alezucchi](https://wordpress.org/support/users/alezucchi/)
 * (@alezucchi)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/data-layer-variable/#post-13643657)
 * Hello
    please, help me grabbing the brand value and send it to data layer..
 *  Thread Starter [alezucchi](https://wordpress.org/support/users/alezucchi/)
 * (@alezucchi)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/data-layer-variable/#post-13704238)
 * HELLO, AGAIN, PLEASE HELP
 * I need to find with metakey is applied to a product when a brand is applied.
 * I need to get the brand value to read it and send it to Google Analytics.
 * Thank’s

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Data layer variable’ is closed to new replies.

 * ![](https://ps.w.org/perfect-woocommerce-brands/assets/icon-256x256.jpg?rev=2912506)
 * [Perfect Brands for WooCommerce](https://wordpress.org/plugins/perfect-woocommerce-brands/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/perfect-woocommerce-brands/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/perfect-woocommerce-brands/)
 * [Active Topics](https://wordpress.org/support/plugin/perfect-woocommerce-brands/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/perfect-woocommerce-brands/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/)

## Tags

 * [data layer](https://wordpress.org/support/topic-tag/data-layer/)
 * [gtm](https://wordpress.org/support/topic-tag/gtm/)

 * 3 replies
 * 1 participant
 * Last reply from: [alezucchi](https://wordpress.org/support/users/alezucchi/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/data-layer-variable/#post-13704238)
 * Status: resolved