How To Migrate Cookie Domain And Retain The Value
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 mytrac
Solution 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.
Post a Comment for "How To Migrate Cookie Domain And Retain The Value"