FB Pixel variable - by jeremy - on WordPress WooCommerce support

This topic has 16 replies, 3 voices, and was last updated 6 years, 3 months ago ago by Rose Tyler

  • Avatar: tlgv
    jeremy
    Participant
    February 6, 2017 at 15:18

    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>

    15 Answers
    Avatar: Eva
    Eva Kemp
    Support staff
    February 7, 2017 at 10:18

    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.

    Avatar: tlgv
    jeremy
    Participant
    February 7, 2017 at 16:30

    Ok thank you, could you tell me where I have to put each piece of this code? In what file and where ?

    Thank you.

    Avatar: Eva
    Eva Kemp
    Support staff
    February 8, 2017 at 17:00

    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.

    Avatar: tlgv
    jeremy
    Participant
    February 10, 2017 at 18:28

    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.

    Avatar: Eva
    Eva Kemp
    Support staff
    February 14, 2017 at 16:29

    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.

    Avatar: tlgv
    jeremy
    Participant
    February 14, 2017 at 19:46

    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.

    Avatar: Eva
    Eva Kemp
    Support staff
    February 15, 2017 at 14:54

    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.

    Avatar: tlgv
    jeremy
    Participant
    February 16, 2017 at 01:08

    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.

    Please, contact administrator
    for this information.
    Avatar: tlgv
    jeremy
    Participant
    February 16, 2017 at 16:21

    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.

    Please, contact administrator
    for this information.
    Avatar: tlgv
    jeremy
    Participant
    February 22, 2017 at 16:16

    Hello,

    Could you please help me?

    Thank you.

    Avatar: Eva
    Eva Kemp
    Support staff
    February 22, 2017 at 17:43

    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.

    Avatar: tlgv
    jeremy
    Participant
    February 22, 2017 at 18:50

    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.

    Please, contact administrator
    for this information.
    Avatar: Eva
    Eva Kemp
    Support staff
    February 27, 2017 at 15:42

    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.

    Avatar: tlgv
    jeremy
    Participant
    July 24, 2018 at 10:37

    Thank you, problem solved, you can close.

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    July 24, 2018 at 10:38

    You’re welcome!

    Regards

  • Viewing 16 results - 1 through 16 (of 16 total)

The issue related to '‘FB Pixel variable’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.