0

Is it somehow possible to migrate domains from a cookie? I have a trackingscript witch sets a cookie on the domain of the tracking script(server side, RoR backend) lets say mytracking.com.

The tracking script itself is integrated as javascript on the domain mycustomer.com.

Status quo is, every guest on the website mycustomer.com has now a cookie for the domain mytracking.com.

Can I somehow migrate the cookie domain from mytracking.com to mycustomer.com?

simon
  • 39
  • 1
  • 2
  • 8
  • Possible duplicate of [Cross-Domain Cookies](https://stackoverflow.com/questions/3342140/cross-domain-cookies) – Tom Lord Jun 14 '18 at 12:46
  • Hmm, don't think so. My intention is not to share cookies, but to change the domain from the one of the trackingscript to the customers one. – simon Jun 14 '18 at 13:03
  • Read the top answer there: You can't. – Tom Lord Jun 14 '18 at 13:03

1 Answers1

1

In your client side JavaScript, generate a unique ID. Then create an iframe with a source pointing to a script on mytracking.com and the unique ID as a parameter.

var ifrm = document.createElement('iframe');
ifrm.setAttribute('src', 'mytracking.com/storecookie.rb?uuid=<UUID>');
document.body.appendChild(ifrm);

Now the storecookie.rb script can access the cookie value on the mytracking.com domain and writes it to a database along with the UUID that you generated.

Now, in your client side JavaScript, you fetch() another script, for example mytracking.com/readcookie.rb?uuid=<UUID> that retrieves the matching cookie value from the database. With the value in your client side JS, you can simply create a new cookie with the correct domain.

Unfortunately that process is a bit convoluted, but cross-domain security prevents setting a cookie for another domain.

otherguy
  • 709
  • 6
  • 13
  • 1
    Thanks for your hint with the iframe. When including the iframe, luckily there is no need to store or tunnle the cookie, as the cookie will be sent by the browser. I created a sample code on github https://gist.github.com/simonknoll/877c78f6727114d01b8345b439d8c406 – simon Jul 20 '18 at 10:17