TurkeyFish Posted July 5, 2017 Share Posted July 5, 2017 (edited) I'm having trouble getting the order ID on the order-confirmation page. I need it for Adwords conversion tracking in Google Tag Manager. I entered the code for a data layer for Google Tag Manager as follows. <!-- Google Tag Manager data layer --> <script> {literal} dataLayer = [{ {/literal} 'orderID': '{$order->id}', 'orderValue': '{$order->total_paid|number_format:2}', 'currency': '{$currency->iso_code}' {literal} }]; {/literal} </script> I've tried all of these, and they're empty: $order->id $order->id_order $order->order_id $reference_order $order_reference $order_id $id_order $reference What else can I try? Is there some list of variables I can use? I'm getting the currency and order total fine using the above. Only the order ID is a mystery. Order reference should be fine too, as I have code that turns the order reference into the order ID everywhere. Maybe the problem is that this is executed in the head tag of the page, where the google tag manager is supposed to be? Is the order ID not available until later on down the page? Edited July 5, 2017 by TurkeyFish (see edit history) Link to comment Share on other sites More sharing options...
kokonauta Posted July 18, 2017 Share Posted July 18, 2017 (edited) I'll try to give an aproach of how to get this to work. I could not achieve to get the 'affiliation', 'brand', 'category', 'variant' and 'coupon' fields dynamic values, but maybe this could help you. Vars are in spanish, but you can change them to any other names (assign it in php and then use the same name in tpl file).This code use the "pageview" instead of the event method to retrieve data in tag manager. IMPORTANT: This code is for enharced ecommerce. Normal ecommerce should not work. If you want normal eccomerce follow this link:http://www.initcoms.com/blog/como-utilizar-google-tag-manager-en-prestashop/(This could be usefull also if you don't know where are the files or how to make the override)In php file (override OrderConfirmationController.php or submit.php in paypal module):$order = new Order($this->id_order); $cart = new Cart($order->id_cart); $productos = $cart->getProducts(); $this->context->smarty->assign(array( 'id_pedido'=> $this->id_order, 'total_a_pagar'=> $order->total_paid_tax_incl, 'gastos_envio'=> $order->total_shipping_tax_excl, 'impuestos'=> ($order->carrier_tax_rate/100) + 1, 'cupones' => $cupones, 'productos' => $productos )); In tpl file (yourtheme/order-confirmation.tpl or modules\paypal\views\templates\front in paypal module): {literal}<script>dataLayer.push({ 'ecommerce': { 'purchase': { 'actionField': { 'id': '{/literal}{$id_pedido}{literal}', 'affiliation': '', 'revenue': '{/literal}{$total_a_pagar}{literal}', 'tax':'{/literal}{$impuestos}{literal}', 'shipping': '{/literal}{$gastos_envio}{literal}', 'coupon': '' }, 'products': [{/literal}{foreach from=$productos item=producto name=productos}{literal} { 'name': '{/literal}{$producto.name}{literal}', 'id': '{/literal}{$producto.id_product}{literal}', 'price': '{/literal}{$producto.price_wt}{literal}', 'brand': '', 'category': '', 'variant': '', 'quantity': {/literal}{$producto.quantity}{literal}, 'coupon': '' }{/literal}{if $smarty.foreach.productos.iteration != $productos|@count}{literal},{/literal}{/if}{literal} {/literal}{/foreach}]{literal} } }});</script> {/literal}I'll apreciate any improve to my code with the empty dynamic variables. Also I'll post any improvement.(Sorry about my broken english) Edited July 18, 2017 by kokonauta (see edit history) Link to comment Share on other sites More sharing options...
perrygupta Posted July 12, 2019 Share Posted July 12, 2019 On 7/4/2017 at 7:22 PM, TurkeyFish said: I'm having trouble getting the order ID on the order-confirmation page. I need it for Adwords conversion tracking in Google Tag Manager. I entered the code for a data layer for Google Tag Manager as follows. <!-- Google Tag Manager data layer --> <script> {literal} dataLayer = [{ {/literal} 'orderID': '{$order->id}', 'orderValue': '{$order->total_paid|number_format:2}', 'currency': '{$currency->iso_code}' {literal} }]; {/literal} </script> I've tried all of these, and they're empty: $order->id $order->id_order $order->order_id $reference_order $order_reference $order_id $id_order $reference What else can I try? Is there some list of variables I can use? I'm getting the currency and order total fine using the above. Only the order ID is a mystery. Order reference should be fine too, as I have code that turns the order reference into the order ID everywhere. Maybe the problem is that this is executed in the head tag of the page, where the google tag manager is supposed to be? Is the order ID not available until later on down the page? Hi Where did you add this code? Link to comment Share on other sites More sharing options...
Mathew Nwaneri Posted March 19, 2022 Share Posted March 19, 2022 On 3/17/2022 at 4:44 PM, Pablus said: With the information of this post I have made it works, finally the data layer is receiving the information needed, thank you! Hello Pablus, can you share how you got to make it work? I mean, what variables did you use? Thanks for sharing. Link to comment Share on other sites More sharing options...
Mathew Nwaneri Posted March 21, 2022 Share Posted March 21, 2022 12 minutes ago, Pablus said: Override OrderConfirmationController.php and create your variables before the line: $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl'); in the example, my vars are: /* GOOGLE TAG MANAGER – TRANSACCIONES */ $order = new Order($this->id_order); $cart = new Cart($order->id_cart); $productos = $cart->getProducts(); $this->context->smarty->assign(array( 'id_pedido'=> $this->id_order, 'total_a_pagar'=> $order->total_paid_tax_incl, 'gastos_envio'=> $order->total_shipping_tax_excl, 'impuestos'=> ($order->carrier_tax_rate/100) + 1, 'productos' => $productos )); /* GOOGLE TAG MANAGER – TRANSACCIONES */ then add the script in your theme order-confirmation.tpl between {literal} {/literal} <script> window.dataLayer = window.dataLayer || []; dataLayer.push({ 'transactionId': '{/literal}{$id_pedido}{literal}', 'transactionTotal': {/literal}{$total_a_pagar}{literal}, 'transactionTax': {/literal}{$impuestos}{literal}, 'transactionShipping': {/literal}{$gastos_envio}{literal}, 'transactionProducts': [{/literal}{foreach from=$productos item=producto name=productos}{literal} { 'sku': '{/literal}{$producto.id_product}{literal}', 'name': '{/literal}{$producto.name}{literal}', 'price': {/literal}{$producto.price_wt}{literal}, 'quantity': {/literal}{$producto.quantity}{literal} }{/literal}{if $smarty.foreach.productos.iteration != $productos|@count}{literal},{/literal}{/if}{literal} {/literal}{/foreach}],{literal} 'event': 'transactionComplete' }) </script> Variables names can be changed, only kep the same mane in both files Thanks a lot. One last questions, I see the variables are in Spanish, will it work if my site is in English? If not, can you do me the huge favour of giving the variables in English. Wi really do appreciate. Thanks once again. Link to comment Share on other sites More sharing options...
Mathew Nwaneri Posted March 21, 2022 Share Posted March 21, 2022 9 minutes ago, Pablus said: Variable names can be changed, use your own name only keeping in mind to use the same name in both codes (php and tpl) Awesome, Thanks a lot. Have a great day. Link to comment Share on other sites More sharing options...
BS TEAM Posted March 22, 2022 Share Posted March 22, 2022 (edited) On 3/21/2022 at 10:11 AM, Mathew Nwaneri said: Awesome, Thanks a lot. Have a great day. Matthew I hope you have received the solution of your problem, because my main account was banned for helping you with your doubt and my messages erased. That's how things works here Edited March 22, 2022 by BS TEAM (see edit history) Link to comment Share on other sites More sharing options...
Mathew Nwaneri Posted March 22, 2022 Share Posted March 22, 2022 1 minute ago, BS TEAM said: Matthew I hope you have received the solution of your problem, because my main account was banned for helping you with your doubt and my messages erased. That's how things works That be crazy, I don't even think your solution was against the community policy. I can still see your messages and solutions, also you are able to post so it seems very strange. If this is the case, I feel so very sorry for this mishap, its not normal somebody should be banned when contributing to the community. Yes once agin, thanks so much for your assistance. Wish you the best. Link to comment Share on other sites More sharing options...
Mathew Nwaneri Posted March 22, 2022 Share Posted March 22, 2022 5 minutes ago, BS TEAM said: Matthew I hope you have received the solution of your problem, because my main account was banned for helping you with your doubt and my messages erased. That's how things works yes you are Right, I see now you posted with another account and your previous account is no longer in the thread. I am sure this must be an error and I do hope it will be resolved soonest. I will also write the forum admin to understand why you were banned for contributing to the community. Keep you posted as soon as I receive (if) their response. Have a great. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now