Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Gravity forms Facebook pixel advanced matching WordPress

  • SOLVED

I need code to go in functions.php and my theme file to pass customer data to the facebook pixel.

https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/

Using gform_after_submission

https://docs.gravityforms.com/gform_after_submission/

Answers (3)

2018-01-16

Austin answers:

Solution - add to functions.php

add_filter( 'gform_confirmation', 'custom_confirmation_message', 10, 3 );

function custom_confirmation_message($confirmation, $form, $entry) {
$confirmation = "<!-- Facebook Pixel Code -->";
$confirmation .= "<script>";
$confirmation .= "!function(f,b,e,v,n,t,s)";
$confirmation .= "{if(f.fbq)return;n=f.fbq=function(){n.callMethod?";
$confirmation .= "n.callMethod.apply(n,arguments):n.queue.push(arguments)};";
$confirmation .= "if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';";
$confirmation .= "n.queue=[];t=b.createElement(e);t.async=!0;";
$confirmation .= "t.src=v;s=b.getElementsByTagName(e)[0];";
$confirmation .= "s.parentNode.insertBefore(t,s)}(window, document,'script',";
$confirmation .= "'https://connect.facebook.net/en_US/fbevents.js');";
$confirmation .= "fbq('init', '<FB PIXEL>', {";
$confirmation .= "em: '".rgar($entry, 3)."',";
$confirmation .= "fn: '".rgar($entry, 1)."',";
$confirmation .= "ln: '".rgar($entry, 2)."',";
$confirmation .= "ph: '".rgar($entry, 4)."',";
$confirmation .= "});";
$confirmation .= "fbq('track', 'PageView');";
$confirmation .= "</script>";
$confirmation .= "<noscript><img height='1' width='1' style='display:none'";
$confirmation .= "src='https://www.facebook.com/tr?id=<FB PIXEL>&ev=PageView&noscript=1'";
$confirmation .= "/></noscript>";
$confirmation .= "<!-- End Facebook Pixel Code -->Thank you for submitting your form.";

return $confirmation;
}


If the hook is gform_confirmation it will work for any form.

Use gform_confirmation_1 for form with id 1

$entry, 1 = field 1 in the form

2018-01-15

Jeremy answers:

What specific customer data?

Which method are you seeking to implement? Javascript or the IMG tag?


Austin comments:

Hi Jeremy - we would want email, firstname, lastname and phone number.

We are using both javascript and img tag.


Austin comments:

Jeremy - I will only need the javascript method.

2018-01-16

Bob answers:

can you please show us your current code?


Austin comments:

There is no code yet.


Austin comments:

Jeremy - I will only need the javascript method.


Bob comments:

can we see your gravity form?