1

We are using Google Tag Manager to manage Java scripts for 3rd party services like Facebook retargeting pixel. In China, Facebook is blocked as a service so whenever a user opened the site it would try to work the script but eventually go into timeout because the firewall blocks the script from loading.

Is there an ability to exclude Facebook pixel script by condition? What is the best solution to define if Facebook is blocked for the current user?

vovakh
  • 93
  • 1
  • 1
  • 4

1 Answers1

0

You need a trigger which checks the value of a variable. This variable must return true/false whether facebook can be loaded or not.

You could try this code as your variable (custom JS code in GTM interface). Replace the facebookUrl value according.

function (){
    var facebookUrl = "..." // your facebook ressource URL 

    var http = new XMLHttpRequest();

    http.open('HEAD', facebookUrl);
    http.send();

    return http.status < 500;

}
michaelsinner
  • 376
  • 1
  • 2
  • 10
  • That's a working solution, but every user from countries where FB is allowed, will be making an extra request. – Gustavo G. Aug 22 '17 at 20:35