- Posts: 73
- Thank you received: 2
Integration of Facebook Pixel and other scripts
-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.3.29
-- Browser(s) name and version -- : Firefox 41.0.2
-- Error-message(debug-mod must be tuned on) -- : No message
Hello, I am integrating hikashop with facebook pixel and Google Analytics Dynamic Remarketing and need your help with setting this up.
1. How to get price on product page (view show_tabular). I need to insert this variable into Google Analytics Dynamic Remarketing script.
And how to get product ID? Is it $this->element->main->product_id ?
2. How to add onlick event to add to cart button?
In the file administrator/components/com_hikashop/helpers/cart.php I see this line:
$html= '<input type="'.$type.'" class="'.$class.' button hikashop_cart_input_button'.$classname.'" name="'.$map.'" value="'.$name.'" '.$ajax.$options.'/>';
I need to add custom script for onclick event. This code is:
<script>
var dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'fireRemarketingTag',
'google_tag_params': {
'ecomm_pagetype': 'cart',
'ecomm_prodid': '',
'ecomm_totalvalue':
}
});
</script>
ecomm_prodid is product id
ecomm_totalvalue is price*quantity (there is a quantity box on the page)
I see currently there is alredy exist onclick event for add to cart button (I see script in browser). But when I add change mentioned line in cart.php to smth like this:
$html= '<input onclick='my script goes here' type="'.$type.'" class="'.$class.' button hikashop_cart_input_button'.$classname.'" name="'.$map.'" value="'.$name.'" '.$ajax.$options.'/>';
this erases previous script for add to cart button and this button doesn't work well. How to combine my script with the script, that I see in browser currently:
<input class="btn button hikashop_cart_input_button" name="add" value="Add to cart" onclick="var field=document.getElementById('hikashop_product_quantity_field_1');if(hikashopCheckChangeForm('item','hikashop_product_form')){ return hikashopModifyQuantity('137',field,1,0,'cart'); } else { return false; }" type="submit">
3. Also how i can get values mentioned in question (2) in cart.php?
ecomm_prodid is product id
ecomm_totalvalue is product_price*quantity (there is a quantity box on the page)
4. I need to insert this code on after_end view file:
<script>
var dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'fireRemarketingTag',
'google_tag_params': {
'ecomm_pagetype': 'purchase',
'ecomm_prodid': '',
'ecomm_totalvalue':
}
});
</script>
Here is ecomm_prodid is array of products IDs, like: 'ecomm_prodid': [123, 456, 789],
'ecomm_totalvalue' - order price (sum of all prices for products in the order)
How can I get values for ecomm_prodid and ecomm_totalvalue?
Please Log in or Create an account to join the conversation.
1. The price is available like this:
echo $this->element->prices[0]->price_value;
The product id is available like this:
echo $this->element->product_id;
However, if you have variants, that will give you the id of the default variant. If you want the id of the main product, you'll have to use this in that case:
echo $this->element->main->product_id;
2. You need to add your javascript code to the beginning of the $this->ajax variable in the file "quantity" of the view "product". That way, your javascript will be added automatically to the onclick code of the button.
3. In the file "quantity" of the view "product", where you should add your javascript, the product price and the product id can be retrieved as explained in point 1.
4. You can add a foreach on the array $this->order->products. Each element of that array will have an attribute "product_id" that you'll be able to use for your ecomm_prodid parameter.
The order total price can be found in $this->order->order_full_price
Please Log in or Create an account to join the conversation.
1-3 are successfully done with your help.
4. Could you please help me to create foreach command for getting product_id for all products in the order?
Also I see your answer here: www.hikashop.com/forum/checkout/875406-f...onversion-pixel.html
You recommended to use following structure in order to get order:
$app =JFactory::getApplication();
$order_id = $app->getUserState('com_hikashop.order_id');
$orderClass = hikashop_get('class.order');
$order = $orderClass->get($order_id);
So, will $this->order->order_full_price work, Or it's better to use mentioned code and then code $order->order_full_price?
Please Log in or Create an account to join the conversation.
4. It's just a standard foreach so it should be easy:
5. You can use either that code or directly $this->order. Both would contain the same thing.
The method from the other thread was given because I didn't know the version of that user as he didn't provide it and $this->order is only available in recent versions of HikaShop. So I gave him the solution with $order just to be sure it would work, but the version with $this->order is more efficient so I gave you this one since I know you're using the latest version of HikaShop.
You see: That's why it's important to always provide the version of HikaShop you're using when asking a question, like you did. If everyone would provide the information we ask in the new thread form of the forum, it would make our life easier
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
The after_end view file is displayed after the payment, when the customer comes back on the website and see the "thank you for your purchase" message of HikaShop.
So when you reach that page, just look at the source of the page and you should find your generated code in there.
Please Log in or Create an account to join the conversation.
Will after_end file run my code at this case?
If no - I guess I can remove return url in payment plugin options and make redirect to thank you page at the end of after_end file?
Please Log in or Create an account to join the conversation.
In that case no the after_end view file is skipped to go to your return URL.
So yes, if you want to redirect to a specific page, you should remove the return URL from your payment method, and instead, add a javascript redirect in the after_end view file. Make sure that you set a timer on the redirect so that the browser has the time to run the facebook javascript before starting the redirection.
Don't use the Joomla redirect as it would redirect the page before the facebook javascript would run.
Please Log in or Create an account to join the conversation.
Also I've noticed that all variables contain price without GST (tax). How can I add tax to all variables mentioned 1-4. It is constant tax cerruntly (10%) and I can add them manually to this variables, but if there is a way to get all variables with GST - i'd like to do it this way.
Please Log in or Create an account to join the conversation.
The price of each product in the order is stored with two variables. One for the price without tax and one for the taxes.
So if you want the price with taxes, you just have to sum both, like that:
echo ($product->order_product_price+$product->order_product_tax);
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
On the product page, the product data already has the price with taxes calculated.
You can easily display it like that:
Please Log in or Create an account to join the conversation.
Does $this->order->order_full_price contain shipping?
Please Log in or Create an account to join the conversation.
Yes, it contains everything.
Please Log in or Create an account to join the conversation.
- Posts: 217
- Thank you received: 4
please, could you explain this more detailed?
On what line and how can I add javascript?
I tried this
line 35
$this->ajax = '<script> example</script>' + return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')';
But it is probably wrong
Thank you in advance
Filip
Please Log in or Create an account to join the conversation.
That's indeed wrong. As I said, this code will be added in the onclick attribute of your add to cart button.
So you only need to add your javascript.
For example, the code:
Please Log in or Create an account to join the conversation.
- Posts: 217
- Thank you received: 4
I tried it at first with alert, it didn't show.
After that I tried it with fbq function, what is defined in my index.php, but page with product says that it is undefined. Can I force loading it for product / quantity view?
Thank you
Please Log in or Create an account to join the conversation.
Here a screenshot from your website:
pasteboard.co/abzdtbUxB.png
As you can see, the custom JS is right included and will be called on the "onclick" event.
I dynamically modify the content of the "onclick" to add an alert and I right got the alert by clicking on the button.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
- Posts: 217
- Thank you received: 4
sorry but I don't see this code here. I really doesn't work for me. I tried to clean website cache and browser cache but there's still default onclick code.
F.
Please Log in or Create an account to join the conversation.
What do you mean by "I don't see this code here" ?
How come you say that you still see the default onclick code ?
Please provide a screenshot for what you're saying because I too, like Jerome, see your code in the onclick of the add to cart buttons on your own website: take.ms/W4APC
So we can't help for something that already works...
Please Log in or Create an account to join the conversation.