[Skip to main content](#vessel-content)

#   Google Analytics Plugin - trigger on the last page

##

- **[otx](/forum/user/14566-otx "View otx's Profile")**
- [![otx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/14566-otx "View otx's Profile") Topic Author
- [ Offline](/forum/user/14566-otx)

Less More

- Posts: 53
- Thank you received: 2
-
-

10 years 8 months ago [\#230207](#230207) by [otx](/forum/user/14566-otx "View otx's Profile")  *[Google Analytics Plugin - trigger on the last page](/forum/27-checkout/882353-google-analytics-plugin-trigger-on-the-last-page#230207 "-- url of the page with the problem -- :   www.vitaking.ro/  -- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.5.9-1ubuntu4.14 -- Browser(s) name and version -- : Firefox 44  Hello,  We need a litle help about triggering the Google Analytics Plugin on the last page (thank you page) on the checkout process. Right now the plugin is triggered in the admin page on changing the order status to Confirmed. The problem with his is that we can't track the source of the customers in Analytics, so we want to move this on the last checkout page. In this way we can have the correct source of the customers.  I think the easiest way would be to move some code from the plugin to the /template/html/com&#95;hikashop/checkout/end.php. We have the code as follows:  Of course this doesn't produce any valuable output, as the classes and variables aren't initialized ($order, $product, and so on).  Can you please give us some help in this? Thanks!  Regards, Dezso")* was created by *[otx](/forum/user/14566-otx "View otx's Profile")*

-- url of the page with the problem -- : [ www.vitaking.ro/](http://www.vitaking.ro/)
-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.5.9-1ubuntu4.14
-- Browser(s) name and version -- : Firefox 44

Hello,

We need a litle help about triggering the Google Analytics Plugin on the last page (thank you page) on the checkout process. Right now the plugin is triggered in the admin page on changing the order status to Confirmed. The problem with his is that we can't track the source of the customers in Analytics, so we want to move this on the last checkout page. In this way we can have the correct source of the customers.

I think the easiest way would be to move some code from the plugin to the /template/html/com_hikashop/checkout/end.php. We have the code as follows:
Code:

$js = ' &lt;!-- Google Analytics ecommerce --&gt; &lt;script&gt; (function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]&#124;&#124;function(){ (i[r].q=i[r].q&#124;&#124;[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,"script","//www.google-analytics.com/analytics.js","ga"); ga("create", "' . $account . '", "auto"); ga("send", "pageview");'.$extra_required.' ga("require", "ecommerce", "ecommerce.js"); ga("ecommerce:addTransaction", { "id": "' . $order-&gt;order_id.'", "affiliation": "' . str_replace(array('\\','"'), array('\\\\', '\\\"'), $siteName) . '", "revenue": "' . round($order-&gt;order_full_price, 2) . '", "shipping": "' . round($order-&gt;order_shipping_price, 2) . '", "tax": "' . round($tax, 2) . '" }); '; foreach($order-&gt;products as $product) { $js .= ' ga("ecommerce:addItem", { "id": "' . $order-&gt;order_id . '", "name": "' . str_replace(array('\\','"'), array('\\\\', '\\\"'), strip_tags($product-&gt;order_product_name)) . '", "sku": "' . str_replace(array('\\','"'), array('\\\\', '\\\"'), $product-&gt;order_product_code) . '", "category": "", "price": "' . ($product-&gt;order_product_price + $product-&gt;order_product_tax) . '", "quantity": "' . (int)$product-&gt;order_product_quantity . '" }); '; } $js .= ' ga("ecommerce:send"); &lt;/script&gt; &lt;!-- End Google Analytics --&gt; '; echo $js;

Of course this doesn't produce any valuable output, as the classes and variables aren't initialized ($order, $product, and so on).

Can you please give us some help in this? Thanks!

Regards,
Dezso

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg4MjM1My1nb29nbGUtYW5hbHl0aWNzLXBsdWdpbi10cmlnZ2VyLW9uLXRoZS1sYXN0LXBhZ2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

10 years 8 months ago [\#230251](#230251) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Google Analytics Plugin - trigger on the last page](/forum/27-checkout/882353-google-analytics-plugin-trigger-on-the-last-page#230251 "-- url of the page with the problem -- :   www.vitaking.ro/  -- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.5.9-1ubuntu4.14 -- Browser(s) name and version -- : Firefox 44  Hello,  We need a litle help about triggering the Google Analytics Plugin on the last page (thank you page) on the checkout process. Right now the plugin is triggered in the admin page on changing the order status to Confirmed. The problem with his is that we can't track the source of the customers in Analytics, so we want to move this on the last checkout page. In this way we can have the correct source of the customers.  I think the easiest way would be to move some code from the plugin to the /template/html/com&#95;hikashop/checkout/end.php. We have the code as follows:  Of course this doesn't produce any valuable output, as the classes and variables aren't initialized ($order, $product, and so on).  Can you please give us some help in this? Thanks!  Regards, Dezso")*

Hi,

Here is a thread with some cod you can use to get the data of the order:
[ www.hikashop.com/forum/4-how-to/68733-ge...id-in-after-end.html](http://www.hikashop.com/forum/4-how-to/68733-get-order-total-and-id-in-after-end.html)

The following user(s) said Thank You: [otx](/forum/user/14566-otx "View otx's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg4MjM1My1nb29nbGUtYW5hbHl0aWNzLXBsdWdpbi10cmlnZ2VyLW9uLXRoZS1sYXN0LXBhZ2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[otx](/forum/user/14566-otx "View otx's Profile")**
- [![otx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/14566-otx "View otx's Profile") Topic Author
- [ Offline](/forum/user/14566-otx)

Less More

- Posts: 53
- Thank you received: 2
-
-

10 years 8 months ago [\#230603](#230603) by [otx](/forum/user/14566-otx "View otx's Profile")  Replied by *[otx](/forum/user/14566-otx "View otx's Profile")* on topic *[Google Analytics Plugin - trigger on the last page](/forum/27-checkout/882353-google-analytics-plugin-trigger-on-the-last-page#230603 "-- url of the page with the problem -- :   www.vitaking.ro/  -- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.5.9-1ubuntu4.14 -- Browser(s) name and version -- : Firefox 44  Hello,  We need a litle help about triggering the Google Analytics Plugin on the last page (thank you page) on the checkout process. Right now the plugin is triggered in the admin page on changing the order status to Confirmed. The problem with his is that we can't track the source of the customers in Analytics, so we want to move this on the last checkout page. In this way we can have the correct source of the customers.  I think the easiest way would be to move some code from the plugin to the /template/html/com&#95;hikashop/checkout/end.php. We have the code as follows:  Of course this doesn't produce any valuable output, as the classes and variables aren't initialized ($order, $product, and so on).  Can you please give us some help in this? Thanks!  Regards, Dezso")*

Hi Nicolas,

Thanks for your help, I'm almost done. I will paste the code here just for documentation purposes. This is a working solution for anyone who wants the ecommerce data on the last checkout page.
Code:

$siteName = 'your site name'; $account= 'your analytics account (UA-)'; $app = JFactory::getApplication(); $order_id = $app-&gt;getUserState('com_hikashop.order_id'); $orderClass = hikashop_get('class.order'); $this-&gt;order = $orderClass-&gt;loadFullOrder($order_id); $order_total = round($this-&gt;order-&gt;order_full_price, 2); $shipping_price = round($this-&gt;order-&gt;order_shipping_price, 2); $revenue = $order_total - $shipping_price; $order_total_no_vat = round($this-&gt;order-&gt;order_subtotal_no_vat, 2); $tax = $order_total - $order_total_no_vat; $js = ' &lt;!-- Google Analytics ecommerce --&gt; &lt;script&gt; (function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]&#124;&#124;function(){ (i[r].q=i[r].q&#124;&#124;[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,"script","//www.google-analytics.com/analytics.js","ga"); ga("create", "' . $account . '", "auto"); ga("send", "pageview");'.$extra_required.' ga("require", "ecommerce", "ecommerce.js"); ga("ecommerce:addTransaction", { "id": "' . $order_id .'", "affiliation": "' . str_replace(array('\\','"'), array('\\\\', '\\\"'), $siteName) . '", "revenue": "' . $revenue . '", "shipping": "' . $shipping_price . '", "tax": "' . round($tax, 2) . '" }); '; foreach($this-&gt;order-&gt;products as $product) { $js .= 'ga("ecommerce:addItem", { "id": "' . $order_id . '", "name": "' . str_replace(array('\\','"'), array('\\\\', '\\\"'), strip_tags($product-&gt;order_product_name)) . '", "sku": "' . str_replace(array('\\','"'), array('\\\\', '\\\"'), $product-&gt;order_product_code) . '", "category": "", "price": "' . ($product-&gt;order_product_price + $product-&gt;order_product_tax) . '", "quantity": "' . (int)$product-&gt;order_product_quantity . '" }); '; } $js .= ' ga("ecommerce:send"); &lt;/script&gt; &lt;!-- End Google Analytics --&gt; '; echo $js;

Place this code in the end.php in your template html directory.
There is only one problem with this: it doesn't save the category of the products. Even in the original plugin there is only an empty "" for this. Is there a way to have this information saved and used on the checkout process?

Regards,
Dezso

The following user(s) said Thank You: [Kumigy](/forum/user/32720-kumigy "View Kumigy's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg4MjM1My1nb29nbGUtYW5hbHl0aWNzLXBsdWdpbi10cmlnZ2VyLW9uLXRoZS1sYXN0LXBhZ2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

10 years 8 months ago [\#230611](#230611) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Google Analytics Plugin - trigger on the last page](/forum/27-checkout/882353-google-analytics-plugin-trigger-on-the-last-page#230611 "-- url of the page with the problem -- :   www.vitaking.ro/  -- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.5.9-1ubuntu4.14 -- Browser(s) name and version -- : Firefox 44  Hello,  We need a litle help about triggering the Google Analytics Plugin on the last page (thank you page) on the checkout process. Right now the plugin is triggered in the admin page on changing the order status to Confirmed. The problem with his is that we can't track the source of the customers in Analytics, so we want to move this on the last checkout page. In this way we can have the correct source of the customers.  I think the easiest way would be to move some code from the plugin to the /template/html/com&#95;hikashop/checkout/end.php. We have the code as follows:  Of course this doesn't produce any valuable output, as the classes and variables aren't initialized ($order, $product, and so on).  Can you please give us some help in this? Thanks!  Regards, Dezso")*

Hi,

You would need to load the categories of each product with a MySQL query based on $product-&gt;product_id and on the tables hikashop_product_category and hikashop_category in order to be able to load the category names and then place them there.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg4MjM1My1nb29nbGUtYW5hbHl0aWNzLXBsdWdpbi10cmlnZ2VyLW9uLXRoZS1sYXN0LXBhZ2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.058 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
