在cookie协议之后使用Facebook Pixel设置页面重新加载

时间:2017-06-02 08:19:23

标签: javascript facebook reload

我已经获得了cookie协议的代码:

 <script type="text/javascript">
$(document).ready(function(){

var cookieState = Cookies.get('fbAllowed');

if (cookieState == null) {
    $('#fbCookie').fadeIn(1000);
}
else {
    document.getElementById("fbCookie").style.display = "none";
} 


$('#agree').click(function() {
    Cookies.set('fbAllowed', '1', { expires: 3650, path: '/'});
    $('#fbCookie').fadeOut(1000);
    window.location.reload(true);

    $('#disagree').click(function() {
        Cookies.set('fbAllowed', '2', { expires: 3650, path: '/'});
        $('#fbCookie').fadeOut(1000); 
     });

});   

通过重新加载,Facebook Pixel脚本应该包含在头

    <script>
    !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
   n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
   n.push=n;n.loaded=!0;n.version='2.0';n.queue=
   [];t=b.createElement(e);t.async=!0;
   t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}
    (window,
    document,'script','https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', 'XYZ'); // Insert your pixel ID here.
    fbq('track', 'PageView');
    </script>
   <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=XYZ&ev=PageView&noscript=1"
    /></noscript>

由于德国法规,像素代码只能在用户同意后设置。

我该如何实现? 谢谢你的帮助! alexinge

0 个答案:

没有答案