Integration of Facebook Pixel and other scripts

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #232688

-- url of the page with the problem -- : travelsat.com.au/shop/satellite-dishes/product/minimax75-dish
-- 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?

Last edit: 8 years 8 months ago by mypetfly.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #232690

Hi,

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.

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #232832

Thank you nicolas,

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #232835

Hi,

4. It's just a standard foreach so it should be easy:

$ids = array();
foreach($this->order->products as $product){
$ids[]=$product->product_id;
}
echo implode(',',$ids);

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.

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #232902

Thank you very much. But how it's possible to debug after_end view file? Checkout is redirecting me to PayPal and I don't understand if my code works or not.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #232903

Hi,

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.

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #232963

But I have set custom return url for payment plugin: travelsat.com.au/thankyou

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #232997

Hi,

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.

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #233076

Ok, thank you for the reply.
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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233086

Hi,

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);

The following user(s) said Thank You: mypetfly

Please Log in or Create an account to join the conversation.

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #233179

Can't get tax value on product display page (show_tabular).

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233183

Hi,

On the product page, the product data already has the price with taxes calculated.
You can easily display it like that:

echo $this->element->prices[0]->price_value_with_tax;

The following user(s) said Thank You: mypetfly

Please Log in or Create an account to join the conversation.

  • Posts: 73
  • Thank you received: 2
8 years 8 months ago #233532

How can I get in after_end.php full price that user paid (including shipping, tax)?
Does $this->order->order_full_price contain shipping?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #233533

Hi,

Yes, it contains everything.

The following user(s) said Thank You: mypetfly

Please Log in or Create an account to join the conversation.

  • Posts: 217
  • Thank you received: 4
8 years 3 months ago #247605

Hello Nicolas,

please, could you explain this more detailed?

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.

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 3 months ago #247607

Hi,

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:

$this->ajax = 'alert(\'test\'); return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')';
will add an alert popup with the text "test" when you click on the add to cart button.

Please Log in or Create an account to join the conversation.

  • Posts: 217
  • Thank you received: 4
8 years 3 months ago #247835

Thank you for reply Nicolas.

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.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 3 months ago #247937

Hi,

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
8 years 2 months ago #248949

Hello,

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 2 months ago #248967

Hi,

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.

Time to create page: 0.108 seconds
Powered by Kunena Forum