{% load wagtailsettings_tags %}
{% get_settings %}
{% if settings.core.SiteSettings.fb_analytics_app_id %}
  <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId      : {{settings.core.SiteSettings.fb_analytics_app_id}},
        cookie     : true,
        xfbml      : true,
        version    : 'v2.10'
      });
      FB.AppEvents.logPageView();
    };

    (function(d, s, id){
       var js, fjs = d.getElementsByTagName(s)[0];
       if (d.getElementById(id)) {return;}
       js = d.createElement(s); js.id = id;
       js.src = "//connect.facebook.net/en_US/sdk.js";
       fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));
  </script>
{% endif %}
