Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Ad network script injecting redirects: how to find and fix it

OPS-206Medium impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

Ad networks, affiliate tags, popups and widgets load JavaScript from servers you do not control. That code runs with the same power as your own. If the network is sloppy, hacked, or sells space to bad advertisers, the script can redirect the page, open a new tab, or replace your page with an ad or scam.

Why it costs you leads or sales

A visitor who is sent away never sees your form, button or checkout. You still paid for the click. Redirects also hurt trust: browsers and security tools can flag your site as unsafe, and visitors who land on a scam page may blame you.

Where a redirect breaks the funnel
  1. Ad clickVisitor arrives from your campaign
  2. Landing page loadsThird-party ad script also loads
  3. Script redirectsVisitor sent to another domain
  4. Form or checkoutNever reached
  5. ConversionNot recorded

The script fires after the landing page loads, so every later step is lost.

Visitors reaching the formExample numbers
Visitors reaching the form (example)Desktop: 62 %; Mobile (redirect active): 38 %; Mobile (fixed): 60 %02448623860DesktopMobile (redirect acti…Mobile (fixed)%

Example: if a script redirects a share of mobile visitors, fewer of them reach the form. Numbers are illustrative.

How to check if your site has it

Reports from customers like "your site sent me somewhere else" are the usual first sign. Another sign is a drop in conversions on one device type or country with no change on your side.

Find the script causing the redirect
  1. Reproduce it

    Open the page in a private window, on a phone if possible, arriving from the same ad or link. Try a few times and with a VPN set to your target countries if your terms allow it.

  2. Record the network

    In Chrome open DevTools, go to Network, tick Preserve log, and reload. Look for the first request to a domain you do not recognise just before the page changes.

  3. Check the initiator

    Click that request and open the Initiator tab. It shows which script started it. That script, or the tag that loads it, is your culprit.

  4. Compare with a clean load

    Block the suspect domain in DevTools (right-click the request, Block request domain) and reload. If the redirect stops, you have found it.

  5. List every tag source

    Check your theme, plugins, Google Tag Manager container and any custom code fields for the script or its loader.

A visitor sent away

The page loads, the script runs, and the visitor ends up somewhere else.

How to fix it

Remove or disable the script first, then work out how it got there. If the redirect came from the ad network itself, contact their support and consider switching. If it came from an account or plugin you did not expect, treat it as a security incident.

Remove the script by platform
  1. Disable suspect plugins

    Under Plugins, deactivate ad, popup and header/footer script plugins one at a time and retest.

  2. Check header and footer code

    Look in Appearance > Theme File Editor (header.php, footer.php) and any Insert Headers and Footers style plugin for unknown script tags.

  3. Scan and update

    Update core, themes and plugins, and run a malware scan with a security plugin you trust.

Then reduce the chance of it returning
  1. Contact or replace the network

    Report the redirect to the ad network with the request details from DevTools. If they cannot stop it, remove them.

  2. Rotate access

    If the script was added without your knowledge, change passwords for your CMS, tag manager and hosting, and remove unused users.

  3. Keep ad scripts off key pages

    Do not load ad network code on landing pages, forms and checkout unless you need it there.

Example: Content Security Policy that limits where scripts can load fromhtml
<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://www.googletagmanager.com https://www.google-analytics.com;">

A Content Security Policy (CSP) tells the browser which domains may run scripts. The snippet is a starting point only: add every domain you genuinely use, or those tools will break. Test in report-only mode first using the Content-Security-Policy-Report-Only header.

How to confirm it's fixed

Confirmation checklist
  • Load the page 10 times on desktop and mobile without being redirected
  • Test from the same ad or link source that showed the problem
  • Check the Network tab shows no requests to the suspect domain
  • Confirm the form submits or checkout loads from start to finish
  • Watch conversions by device and country for a week

How to prevent it happening again

Prevention checklist
  • Keep a written list of approved third-party scripts and their owners
  • Limit who can publish in your tag manager and CMS, and use two-step login
  • Avoid ad networks on lead form and checkout pages
  • Review the tag manager version history monthly
  • Use a CSP in report-only mode to see unexpected domains
  • Re-test key journeys on mobile after every tag or plugin change

How FunnelGuard handles this

FunnelGuard detects this issue only partly. It runs your real customer journeys on a schedule, from the EU or the US. If a script sends the robot away so a step cannot be completed, such as the form not being found or the checkout not loading, the step fails. The failure is re-checked from a second region before one alert goes out with a screenshot and a likely cause.

Questions people ask

Why is my website redirecting visitors to another site?

A common cause is a third-party script, such as an ad network tag, popup or injected malware, that changes the page address. Use browser DevTools with Preserve log on to find the first request to an unknown domain and check its Initiator to see which script started it.

How do I find which script is causing a redirect?

Open DevTools, go to Network, tick Preserve log and reload. Find the request just before the page changes, then open its Initiator tab. Blocking that domain and reloading confirms whether it is the cause.

Why does the redirect only happen on mobile or for some visitors?

Many redirect scripts target specific devices, countries, referrers or first visits to avoid being noticed by site owners. Test on a real phone, arrive from the same ad or link, and try from the affected region where your terms allow it.

Can Google Tag Manager cause redirects?

Yes. A Custom HTML tag in a container can load any script, including one that redirects. Check Preview mode, review the version history and limit who can publish changes.

Is a redirect from an ad script a sign my site was hacked?

Not always. The ad network itself may be serving bad ads. But if you cannot explain how a script got onto your site, treat it as a possible compromise: rotate passwords, remove unused users and check for other changes.

Can FunnelGuard detect redirects from ad scripts?

Partly. It catches cases where the redirect stops a monitored journey step from completing and sends an alert with a screenshot. It does not scan scripts for malicious code and may miss redirects that fire only for certain devices, regions or ad sources.

Will a Content Security Policy stop script redirects?

It can limit which domains scripts may load from, which blocks many unwanted ad scripts. It will not stop a script from a domain you have allowed, and a policy that is too strict can break your own tags, so start in report-only mode.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.