0

Me and my friend have developed a script that hide the cookie tag for "X" minutes because the whole concept is when a visitor visit my website I don't want to cookied immediately for retargeting proposes but to hide the cookie tag for x seconds so only I can cookied only the visitor that stays more than x seconds.

Check the code below:

<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script>
        function Inject() {
$('body').append(HERE WE PUT THE RETARGETING PIXEL CODE);           
      }
        // run script after 45 sec.
        window.setTimeout(Inject, 45000);
    </script>

As you can see the retargeting pixel code goes between ( ) but the problem I am facing this moment is that when I place the retargeting pixel from Facebook inside the ( ) it seems that it doesn't work correctly. Check the image below to see how it looks like in my website: https://i.stack.imgur.com/z1KtE.png

As you can see something in the code is missing but I don't know what. Any help will be appreciated. Thanks.

3
  • 1
    What does 'I don't want to cookied immediately ...' Is that even a verb ? What does 'retargeting pixel code' mean ? PS: you could simply place the error code instead of that spam image.
    – user458577
    May 16, 2015 at 18:57
  • 2
    @WernerVanBelle - one of the great things about English is that any noun can be verbed.
    – andrewsi
    May 16, 2015 at 19:03
  • In that case, you might want to consider adding an auxiliary verb such as 'to be'. E.g: 'I don't want to to be cookied'. (Whatever that means).
    – user458577
    May 16, 2015 at 19:57

2 Answers 2

0

Put a document.cookie assignment inside your timeout, no need for other functions:

 setTimeout(function(){
     document.cookie = "key=value;path=/;expires="+someDateFunc();
 }, 45000);
0

The screenshot tells me that you are closing the string in your append()-statement too soon. This is due a mismatch in your ' and " signs.

Try this while being careful of my '-sign:

function Inject() {
    var img = new Image(1,1); // width, height values are optional params 
    img.src = 'http://www.your_facebook_img_link.com';
    document.body.appendChild(img);
}

window.setTimeout(Inject, 45000);

This is pure JS and does not require jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.