[GUIDE] How to fire Pixel Event when using a Cloaker

CloakBro

Junior Member
Joined
Nov 30, 2022
Messages
153
Reaction score
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:
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!
 
is there anyway i can do this within wordpress?


When they submit there email i need it to count as a lead by clicking a button
 
It can be definitely be done in WordPress, you just need to figure out the part of your code where it sends form-data and call cloakBroPixelEvent(pixelId, 'Lead').
 
It can be definitely be done in WordPress, you just need to figure out the part of your code where it sends form-data and call cloakBroPixelEvent(pixelId, 'Lead').
How i do it with wordpress

Setup pixel with PixelCat
Setup custom conversion events for the buttons or pages i need
When i setup the AD i select the pixel
Enter my cloaked url
Collect leads on blackpage

Ads live for weeks if not months like this


But your method is interesting because i have never seen someone do it like that.
 
How i do it with wordpress

Setup pixel with PixelCat
Setup custom conversion events for the buttons or pages i need
When i setup the AD i select the pixel
Enter my cloaked url
Collect leads on blackpage

Ads live for weeks if not months like this


But your method is interesting because i have never seen someone do it like that.
I guess Pixel Cat has a similar approach as the code I've provided. Probably using the conversions API?
 
How i do it with wordpress

Setup pixel with PixelCat
Setup custom conversion events for the buttons or pages i need
When i setup the AD i select the pixel
Enter my cloaked url
Collect leads on blackpage

Ads live for weeks if not months like this


But your method is interesting because i have never seen someone do it like that.
Could you explain more thoroughly how to setup for tiktok as well? Is pixel cat installed on the black page? How do you setup the custom conversion events with pixel cat?
 
The article provides specific instructions and clear examples. Great job, man.
 
It is even simpler to create a 'thank you' page and place the following trimmed code there:

<img height="1" width="1" src="https://www.facebook.com/tr?id=IDpixel&ev=Lead&noscript=1"/>

In this case, after a purchase, the user will be redirected to the 'thank you' page, where the 'lead' event will trigger and be sent directly to Facebook.

You can also use a code that will automatically insert the pixel ID. That is, you want to run ads from 10 accounts on one website, but each account has a different pixel. In this case, your link will look like this: http://www.yoursite.com?/pixel=idpixel. You just need to replace idpixel with the required pixel ID, and it will automatically be extracted from the link and inserted into the code.
 
Back
Top