skip to Main Content

Situation:

  • I’m the owner of the website example.com
  • I want to give my customers the possibility (pixel/iframe/sth?) to check if current visitor of their website was on my website (example.com) in the last 30 days
  • If she/he was on my website in the last 30 days, the dataLayer event should be fired.

Tried Iframe and embeded JS to read cookies but no success.

2

Answers


  1. Chosen as BEST ANSWER

    I've found a solution, but I'm afraid won't work when Chrome will disable 3rd party cookies:

    1. I'm setting up 30 days cookie on my site (example.com)

    2. I've prepared a simple endpoint on my site (example.com/check):

      $content = isset($_COOKIE["xxx"]) && $_COOKIE["xxx"] ? 1 : 0;
      $response = new JsonResponse(['response' => $content]);
      $response->headers->set('Access-Control-Allow-Origin', $_SERVER['HTTP_ORIGIN']);
      $response->headers->set('Access-Control-Allow-Credentials', 'true');
      return $response;
      
    3. my customers can use this code to check it:

       <script>
           (function() {
               var xhr = new XMLHttpRequest();
               xhr.open('GET', 'https://example.com/check', true);
               xhr.withCredentials = true; 
               xhr.onreadystatechange = function() {
                   if (xhr.readyState === 4 && xhr.status === 200) {
                       var response = JSON.parse(xhr.responseText);
      
                       if(response.response)
                       {
                           window.dataLayer = window.dataLayer || [];
                           window.dataLayer.push({
                               'event': 'visited_otodom'
                           });
                       }
                   }
               };
               xhr.send();
           })();
       </script>
      

  2. I think you can try to set Same-Site: None to your cookie on your website (eg somecookie). Then your requests from anotherwebsitecom to websitecom should use it. Then you can check if request contains somecookie.

    If you want to limit the cookie’s lifetime to 30 days you can use expires property.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search