F
F
firemark_s2020-05-22 15:48:36
JavaScript
firemark_s, 2020-05-22 15:48:36

How to set 1 unique cookie for a user for multiple sites?

Suppose we have several sites d1.ru \ d2.ru \ d3.ru
and a certain admin panel located on admin.ru there is also a database

how to set a unique cookie for a user from several sites at once through js?
Let's say a user visits d1.ru, we set a userid=JD7d3e cookie, the user fills out an application, leaves
After a while, the user accesses the d2.ru website from the same machine, from the same browser, it is defined as userid=JD7d3e

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Korotenko, 2020-05-22
@firedragon

Read here.
https://learn.javascript.ru/cookie
If you need a shared marker, then create a script on the admin.ru site that adds some string
to localStorage localStorage['SharedKey'] = 'WehjhgjFerL:iopUISh&;';l8jg'; // just use a more random thing,
on sites d1.ru \ d2.ru \ d3.ru
Read it
var key = localStorage['SharedKey'];

O
Odisseya, 2020-05-22
@Odisseya

Previously, this was done through third-party cookies , but now the privacy settings in browsers block this. It is possible to use a shared cookie for subdomains, but not for different domains. You can implement something like a tracking pixel.

K
Karpion, 2020-05-23
@Karpion

It seems that the cookie has a list of sites that can read it.

B
blackdad, 2020-05-23
@blackdad

Approximately how Yandex metric puts its cookie on all sites where it is installed. Upload the js file from the required domains. Delee through them put a cookie. What exactly to put you pass in the parameters.
A little off topic, but maybe it will come in handy for someone: bitrixhub.ru/sozdanie-edinoj-avtorizatsii-v-bitrikse

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question