我正在建立一个推广其他网站的网站。现在,我想检查我的推荐人是否在我推广的网站上进行销售。有没有办法做到这一点?我认为Google和Facebook已经在做这样的事情,我想知道他们的做法。我已经写了一些JS代码,但是我不认为这是实现此目的的最佳方法。
const host = window.location.host;
const path = window.location.pathname;
const search = window.location.search.split('&');
// Set cookie if the site is entered via my site
search.forEach(query => {
if (query == 'ref=test' || query == '?ref=test') {
document.cookie = 'comingFromRef=true';
}
})
// When we are at the checkout page, check for cookie
if (host.includes('checkout.') || path.includes('checkout')) {
document.cookie.split('; ').forEach(cookie => {
if (cookie == 'comingFromRef=true') {
// Do things here, as the sale comes from my platform
}
})
}
由于我是新来的,所以真的很感谢任何帮助,并且真的不知道如何进一步进行。预先感谢。
最好的问候 标记