This topic has 16 replies, 3 voices, and was last updated 6 years, 4 months ago ago by Rose Tyler
Hello,
I need to set up events for my Facebook pixel tracking. I need to fill variables for each event.
Could you tell me what are variables from your theme for these events:
Search event:
<script>
fbq(‘track’, ‘Search’, {
search_string: ‘?????????’
});
</script>
Add to cart event:
<script>
fbq(‘track’, ‘AddToCart’, {
value: ?????,
currency: ‘?????’
});
</script>
View content event:
<script>
fbq(‘track’, ‘ViewContent’, {
value: ??????,
currency: ‘?????’
});
</script>
Purchase event:
<script>
fbq(‘track’, ‘Purchase’, {
value: ???????,
currency: ‘???????’
});
</script>
Hello,
You need write the following:
value: product price,
currency: currency you’re using (write it with code, like USD)
search_string: tags for searching
Also refer to the documentation:
https://developers.facebook.com/docs/marketing-api/audiences-api/pixel#parameters
Regards,
Eva Kemp.
Ok thank you, could you tell me where I have to put each piece of this code? In what file and where ?
Thank you.
Hello,
Please refer to the answers below:
1)http://prntscr.com/e5yxpw
2)If you want to add for separate products, you can add it in the text editor of the product http://prntscr.com/e5yyj5
3)If you want to add for all products, go to royal/woocommerce/content-single-product.php and write http://prntscr.com/e5z3yx
4) For checkout, edit the file royal/woocommerce/checkout/form-checkout.php and add the following http://prntscr.com/e5z5tw
5) Search event goes here http://prntscr.com/e5z6vv in the file royal/searchform.php
and royal/woosearchform.php
6) Add to Cart event goes here royal/woocommerce/single-product/add-to-cart/simple.php
and royal/woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php http://prntscr.com/e5z8tq
Make all changes in the child theme to prevent losing them after theme update.
Regards,
Eva Kemp.
Hello,
Thank you for this.
1) Could you explain to me this code?
2) Ok
3) Ok
4) Could you please take a screenshot with php file as you did in 3)
5) In search_string: ” , does I have to put something in ” ?
6) Does I have to put something in value and currency?
Thank you.
Hello,
1) The code is for initialization. Please read the documentation:
https://developers.facebook.com/docs/marketing-api/audiences-api/pixel#parameters
4) Please take a look http://prntscr.com/e8iff0
<script>
fbq('track', 'ViewContent', {
value: <?php echo WC()->cart->get_cart_subtotal(); ?>,
currency: '<?php echo get_option('woocommerce currency'); ?>'
});
</script>
5) No need.
6) Yes, it’s required.
Regards,
Eva Kemp.
Hello,
1) Ok
4) Ok
5) Ok
6) What php variable does I have to put in value and currency? This one? Other?
value: <?php echo WC()->cart->get_cart_subtotal(); ?>,
currency: ‘<?php echo get_option(‘woocommerce currency’); ?>’
Thank you.
Hello,
6. Yes, you need use this code:
value: <?php echo WC()->cart->get_cart_subtotal(); ?>,
currency: <?php echo get_option('woocommerce currency'); ?>
Regards,
Eva Kemp.
Ok thank you. Please find enclosed a screenshot of my php file variation-add-to-cart-button. My script is ok? At the right position in the file?
Thank you.
Hello,
I add to my previous message this message.
I have many errors in my console browser, please find them on screenshot and url.
How can I fix that?
Thank you.
Hello,
Could you please help me?
Thank you.
Hello,
Sorry, for a delay.
You should fix these values:
– add a value here http://prnt.sc/ebx20v , for example http://prntscr.com/ebxnin
– add a comma here http://prnt.sc/ebx3iv
– for add to cart a comma is also needed http://prnt.sc/ebxks5
Also these scripts should be tied with some buttons, like:
<button onClick="fbq('track', 'Purchase');">Button Text</button>
<script>
function onClick() {
fbq('track', 'Purchase');
};
</script>
Regards,
Eva Kemp.
Ok thank you. Could you tell me if:
– My script has a right position (message #154927)?
– I want to put my search script only on search result page, how can I do this (in what php file)?
– I have an error for my add to cart script, I get html code… Please find screenshot.
– What’s the goal of this script, how to use it, for what?
Thanks a lot.
Hello,
1. Could you please resend the screenshot?
2. You need to add in the file woocommerce/archive-product.php:
http://prntscr.com/edwpz2
<?php if ( is_search() ) : ?>
<script>
fbq(‘track’, ‘Search’, {
search_string: ‘your search string’
});
</script>
<?php endif; ?>
3. It should look like this http://prntscr.com/edx03i
<script>
fbq('track', 'AddToCart', {
value: <?php echo $product->get_price(); ?>,
currency: '<?php echo get_option('woocommerce currency'); ?>'
});
</script>
4. You need read the documentation.
Regards,
Eva Kemp.
Thank you, problem solved, you can close.
You’re welcome!
Regards
The issue related to '‘FB Pixel variable’' has been successfully resolved, and the topic is now closed for further responses