<?php
/**
* Send a server-side event to the FB Conversions API when a Gravity Forms form is submitted using the Conversion Pixels addon.
*
* @param array $entry The entry data.
* @param array $form The form data.
*/
add_action( 'gform_after_submission', function ( $entry, $form ) {
// Run this only for a specific form id.
if ( 1 !== rgar( $form, 'id' ) ) {
return;
}
if ( function_exists( 'wpcode_pixel' ) ) {
// Send event for FB Pixel.
// Find the auto-insert type for fb.
$pixel_types = wpcode_pixel()->auto_insert->types;
foreach ( $pixel_types as $pixel_type ) {
if ( $pixel_type instanceof WPCode_Pixel_Auto_Insert_Facebook ) {
$pixel_type->send_server_event(
array(
'event_name' => 'Lead', // This can be changed to "Contact" or "CompleteRegistration" or any other event name.
'event_time' => time(),
'custom_data' => array(),
'user_data' => $pixel_type->get_user_data( array() ),
)
);
}, 10, 2 );