Created
July 12, 2021 02:50
-
-
Save LucasGorgal/1352a475aae1c1590e55c53953bdb963 to your computer and use it in GitHub Desktop.
Redirecionador com Conversion API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$userIP = $_SERVER['REMOTE_ADDR']; | |
$userAgent = $_SERVER['HTTP_USER_AGENT']; | |
$fbclid = $_GET['fbclid']; | |
$fbc_cookie = "fb.1." .round(microtime(true) * 1000) ."." .$fbclid; | |
$page_url = "https://site.com/redirecionamento.php"; //endereço onde está localizado o script | |
$pixelId = 11111111111; //Id do pixel | |
$access_token = 'aaaaaaa'; //Token de acesso | |
$event_time = time(); | |
header("Location: https://site.com/endereco-que-voce-quer-mandar-a-pessoa"); | |
facebook_conversion_api_curl($pixelId, $access_token, $event_time, $userIP, $userAgent, $fbc_cookie, $page_url); | |
function facebook_conversion_api_curl($pixelId, $access_token, $event_time, $userIP, $userAgent, $fbc_cookie, $page_url) { | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => "https://graph.facebook.com/v11.0/$pixelId/events", | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => '', | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 0, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => 'POST', | |
CURLOPT_POSTFIELDS => array('access_token' => $access_token,'data' => '[ | |
{ | |
"event_name": "Lead", | |
"event_time":' .$event_time .', | |
"client_ip_address": "' .$userIP .'", | |
"client_user_agent": "' .$userAgent .'", | |
"fbc": "' .$fbc_cookie .'", | |
}, | |
"event_source_url": "' .$page_url .'", | |
"action_source": "website" | |
} | |
]'), | |
)); | |
$response = curl_exec($curl); | |
curl_close($curl); | |
echo $response; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment