top of page
logo

The 2 Second Java Script Fix That Saved My Facebook Ads

  • admin67410
  • May 22
  • 5 min read

Let's be honest here. Facebook Ads are not what they used to be. If you look at the dedicated subreddits on advertising and Facebook Groups for authors, they are filled with the same complaints. Previously high-performing ads suddenly die. They get flooded with bot traffic and go from being highly profitable to burning money. Authors end up constantly duplicating their ads, hoping for another 7 to 14-day burst of high-intent traffic before the bots find them all over again.


I know the pain well. I've been having similar issues with my own ads. In early 2025, my return on ad spend (ROAS) went off a cliff and never really recovered. I did course after course after course. I read all of the forums and threads. And yet, my ad account continued to hemorrhage money. By December 2025, I stopped running them altogether and watched my sales slow to a trickle.


In March of this year, tired of watching the dwindling figures in my bank account, I decided to build a technical solution to the problem.


The Facebook Ad Death Spiral


The problem we face is that the Facebook Ads AI inherently wants to serve your ads to get the highest number of clicks possible. A couple of years ago, standard pay-per-click traffic ads worked well, but those died in a big way last year. The conventional wisdom now is to use Sales campaigns pointing to a dedicated landing page on your website that has the Facebook Pixel set up on it. In theory, this sends better conversion data back to Facebook's system, allowing it to deliver better targeting.

And it works. For a short time.


Eventually, the bots track you down. What happens next is a silent budget killer: a ton of automated bots click your ad, land on your page, and immediately click your outbound links. You spend the money, but you get zero actual sales.


Worse yet, because Facebook's algorithm thinks it did a great job finding people who click your links, it optimizes your campaign to find more of those exact profiles. It actively trains itself to hunt down bot traffic instead of real readers.


The 2-Second Javascript Solution


My solution to breaking this cycle was pretty simple. Bots are configured for high-volume, rapid clicks. They want to hit a page, click the main calls to action instantly, and move on to the next site to scrape data or simulate activity. They rarely linger.

So, I wrote a small bit of Javascript for my landing page that does one simple thing: it prevents link clicks from registering with the Facebook Pixel until the page has been loaded for a full two seconds.


If a bot lands on the page and clicks the Amazon button within 1.5 seconds, the link still opens normally so the site doesn't feel broken, but the conversion pixel never fires. To Facebook's AI, that junk click never happened.

After setting this up, I launched a clean Sales campaign:

  • Structure: 1 campaign, 1 ad set, 1 ad creative

  • Testing: 3 variations of the primary text, headline, and description

  • Budget: £15 a day

  • Rule: Leave it completely alone for ten weeks.


The Hard Data


At first, the campaign just ticked over nicely, performing more or less how you would expect a fresh ad to run. But because the pixel was only allowed to record data from visitors who lingered for more than two seconds, the long-term trends completely changed.


Look at the massive discrepancy between the raw clicks and the qualified human clicks over that ten-week period:

  • Total Raw Link Clicks: 4,973

  • Actual Landing Page Views: 3,428

  • Qualified Human Results (Clicks after the 2-second delay): 1,357


Over 1,500 clicks were stripped away by the gatekeeper. Because the pixel was completely shielded from those artificially inflated bot strikes, the algorithm spent the last two months learning exclusively from real human behavior. It got better at finding actual readers who buy books, rather than bots that burn budgets.



As a result, the ad isn't decaying. In fact, it's performing better the longer it runs. My sustained ROAS for the current week is up around 3.92.


I made some mistakes early on, like routing the buttons to a universal link aggregator (which just added another layer of click friction). Moving forward, I am linking straight to direct Amazon URLs and building a dedicated landing page for each target country.

And it's important to remember that your advert creatives have to work, your landing page needs to make the reader want the book even more, and your amazon product page needs to seal the deal. This workaround won't solve those problems, but at least it should put you back on a level playing field.



The Code (Do It Yourself)

⚠️ Important Note for Authors: If you copy and paste the HTML block below, make sure to replace the placeholder Amazon URL (https://www.amazon.com/dp/B0068NOYM8) and the image source URL with your own book link and button graphics. Otherwise, you will be paying to advertise my books!

Paste this global script block into the header or top section of your custom landing page code:

HTML

<script>
  // 1. Initialize the Humanity Check immediately
  window.isHumanVisitor = false;
  
  // 2. Start the 2-second countdown
  setTimeout(function() { 
      window.isHumanVisitor = true; 
  }, 2000);

  // 3. The Shared Function (Used by ALL buttons)
  function safePixelFire(contentName) {
      if (window.isHumanVisitor) {
          fbq('track', 'Purchase', {
              value: 3.00, 
              currency: 'GBP', 
              content_name: contentName
          });
      }
      return true; // Always allow the link to open normally
  }
</script>

Then, use this structure for your actual on-page buttons and text links further down the body:

HTML

<!-- Image Button Example -->
<div style="text-align: center; margin: 20px 0;">
  <a href="https://www.amazon.com/dp/B0068NOYM8" target="_blank" onclick="return safePixelFire('Book Launch - Top Image');">
    <img src="YOUR_BUTTON_IMAGE_URL_HERE.png" alt="Get it on Amazon" style="max-width: 100%; height: auto; display: inline-block;">
  </a>
</div>

<!-- Text Link Example -->
<h2 style="text-align: center; font-weight: bold; margin-top: 15px;">
  <a href="https://www.amazon.com/dp/B0068NOYM8" target="_blank" style="color: #000000; text-decoration: underline; cursor: pointer;" onclick="return safePixelFire('Book Launch - Top Text');">
    Available to read for FREE on Kindle Unlimited
  </a>
</h2>

Taking Control of Your Data

Plugging the leaks in your advertising account requires taking absolute ownership of your data stream. When you stop letting automated platforms dictate your metrics, your campaigns become predictable, scalable business assets.


If you want that exact same level of granular control, transparency, and data ownership over your backend operations—without handing your financials over to recurring cloud subscriptions—take a look at what we are building at Imprint Royalties. It's a completely offline desktop accounting engine designed specifically to help independent authors and small presses eliminate spreadsheet chaos, automate multi-author splits, and handle accurate P&L tracking.


Stop guessing on your front-end marketing, and stop stressing over your back-end royalties

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page