CloakBro
Junior Member
- Nov 30, 2022
- 153
- 50
What's up, guys! Let's talk about Pixel events, why they are important, and how to set them up when you're using a cloaker.
What are Pixel events?
Pixel events are crucial for your Facebook ad campaigns. Facebook uses data from your pixel to optimize your ads and find better audiences, resulting in more conversions and better Return on Ad Spend (ROAS).
Installing a pixel on your website is straightforward under normal conditions, but it becomes a bit tricky when using a cloaker.
Usually, when cloaking, you have two different pages: a white-page (also known as a 'safe' page) and a black-page (also known as a 'money' page). We only want Facebook to know about our white-page and definitely not about our black page.
How do we make Facebook think the Pixel events happen on our white-page?
We are going to send the events from our black-page to our white-page and then send the events from the white-page to Facebook! Let's start.
In this example, I'm going to use two different domains:
- white-page.com is where the cloaker and white-page are installed.
- black-page.com is my black-page where real visitors get redirected to from our white-page. This is also where a purchase/conversion/lead happens.
We're going to add a file to white-page.com called pixel.php and put this code inside of it:
Great! Now all we need to do is add some code to our black-page.com site. Here are some examples:
Example: You want to fire a Page View event.
Simply add this code before the </body> tag of your website:
Example: You want to send a conversion event (Purchase, Lead, etc.).
And that's it! Now our Pixel will receive data and learn from it.
Handy Source
All Pixel events: Facebook Pixel Reference - Standard Events
If there are any unanswered questions, let me know down below!
What are Pixel events?
Pixel events are crucial for your Facebook ad campaigns. Facebook uses data from your pixel to optimize your ads and find better audiences, resulting in more conversions and better Return on Ad Spend (ROAS).
Installing a pixel on your website is straightforward under normal conditions, but it becomes a bit tricky when using a cloaker.
Usually, when cloaking, you have two different pages: a white-page (also known as a 'safe' page) and a black-page (also known as a 'money' page). We only want Facebook to know about our white-page and definitely not about our black page.
How do we make Facebook think the Pixel events happen on our white-page?
We are going to send the events from our black-page to our white-page and then send the events from the white-page to Facebook! Let's start.
In this example, I'm going to use two different domains:
- white-page.com is where the cloaker and white-page are installed.
- black-page.com is my black-page where real visitors get redirected to from our white-page. This is also where a purchase/conversion/lead happens.
We're going to add a file to white-page.com called pixel.php and put this code inside of it:
PHP:
<?php
$px_id = $_GET['px_id']; // Variable to hold the Pixel ID
$px_ev = $_GET['px_ev']; // Variable to hold the event that we want to fire
?>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=<?php echo $px_id; ?>&ev=<?php echo $px_ev; ?>"/>
Great! Now all we need to do is add some code to our black-page.com site. Here are some examples:
Example: You want to fire a Page View event.
Simply add this code before the </body> tag of your website:
JavaScript:
function cloakBroPixelEvent(px_id, px_ev) {
var iframe = document.createElement('iframe');
iframe.src = 'https://white-page.com/pixel.php?px_id=' + px_id + '&px_ev=' + px_ev;
iframe.style.display = 'none';
iframe.referrerPolicy = 'no-referrer';
document.body.appendChild(iframe);
}
// Usage
var pixelId = '0101010101'; // Replace with your pixel ID
cloakBroPixelEvent(pixelId, 'PageView'); // PageView is the name of the Pixel event; you can change this to any other
Example: You want to send a conversion event (Purchase, Lead, etc.).
JavaScript:
// Again, our function to fire the pixel
function cloakBroPixelEvent(px_id, px_ev) {
var iframe = document.createElement('iframe');
iframe.src = 'https://white-page.com/pixel.php?px_id=' + px_id + '&px_ev=' + px_ev;
iframe.style.display = 'none';
iframe.referrerPolicy = 'no-referrer';
document.body.appendChild(iframe);
}
// Find your function that completes the conversion, for example:
function registerLead(name, email, phone) {
fetch('https://your-server.com/register-lead', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, email, phone }),
})
.then(response => response.json())
.then(data => {
var pixelId = '0101010101'; // Replace with your pixel ID
cloakBroPixelEvent(pixelId, 'Lead'); // Lead is registered successfully, so we fire the Pixel event here
})
.catch(error => console.error('Lead registration failed', error));
}
And that's it! Now our Pixel will receive data and learn from it.
Handy Source
All Pixel events: Facebook Pixel Reference - Standard Events
If there are any unanswered questions, let me know down below!