# What's the best way to build a referral attribution system with "cookie" period? How long do local storage variables in Weweb last, would that be enough?

**URL:** <https://community.weweb.io/t/whats-the-best-way-to-build-a-referral-attribution-system-with-cookie-period-how-long-do-local-storage-variables-in-weweb-last-would-that-be-enough/4070>\
**Category:** Ask us anything\
**Created:** [August 28, 2023, 4:03pm UTC](https://community.weweb.io/t/whats-the-best-way-to-build-a-referral-attribution-system-with-cookie-period-how-long-do-local-storage-variables-in-weweb-last-would-that-be-enough/4070 "2023-08-28T16:03:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raelyn](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raelyn/32/2803_2.png) [@raelyn](https://community.weweb.io/u/raelyn)\
**Post date:** [August 28, 2023, 4:03pm UTC](https://community.weweb.io/t/whats-the-best-way-to-build-a-referral-attribution-system-with-cookie-period-how-long-do-local-storage-variables-in-weweb-last-would-that-be-enough/4070/1 "2023-08-28T16:03:07Z")

</div>

Trying to create a referral program in Weweb.

What’s the best way to build a referral attribution system? For instance, use URL query param with referrer ID, then set a local variable with that ID so that if that user comes back to sign up, I can read the local variable to see who originally referred them?

Is there an expiry time for local variables? Can I set that somewhere?

OR is it better to “set a cookie”, what’s the difference? And how do I set this?

Basically, I have the same question as this thread here:

> [@Read a cookie on page load](https://community.weweb.io/t/read-a-cookie-on-page-load/1740/5):
>
> Thanks Alexis, If I can describe the use case further, when an existing user makes a return visit to my website after closing the browser, I wanted to be able to know (on page load) that this is an existing user and apply some conditional logic. Are variables in local storage automatically initialized on page load?

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [August 28, 2023, 5:01pm UTC](https://community.weweb.io/t/whats-the-best-way-to-build-a-referral-attribution-system-with-cookie-period-how-long-do-local-storage-variables-in-weweb-last-would-that-be-enough/4070/2 "2023-08-28T17:01:56Z")

</div>

It entirely depends on the user.

> **[Window: localStorage property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)**
>
> The localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.

 ![Screenshot 2023-08-28 at 19.00.39](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e81dc8141d1443d17a664f88490634c11c96bf33.jpeg)

---

<div class="post-metadata">

**Author:** ![raelyn](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raelyn/32/2803_2.png) [@raelyn](https://community.weweb.io/u/raelyn)\
**Post date:** [August 29, 2023, 9:15am UTC](https://community.weweb.io/t/whats-the-best-way-to-build-a-referral-attribution-system-with-cookie-period-how-long-do-local-storage-variables-in-weweb-last-would-that-be-enough/4070/3 "2023-08-29T09:15:54Z")

</div>

Looks like I need the cookie expiry time so it’s cookies, does anyone have any idea how to “set a cookie” from a refID in the URL?

And then how do I get this “cookie” to talk to variables in Weweb?

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [August 29, 2023, 9:31am UTC](https://community.weweb.io/t/whats-the-best-way-to-build-a-referral-attribution-system-with-cookie-period-how-long-do-local-storage-variables-in-weweb-last-would-that-be-enough/4070/4 "2023-08-29T09:31:58Z")

</div>

> **[cookies - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies)**
>
> Enables extensions to get and set cookies, and be notified when they change.

Would require some js, this and copilot might help
