Help parsing URL capturing value for cookie

Hello all. Brand new here and new to WebFlow. I am at the limits of my knowledge here so please forgive any lapses with terminology. I’m going to forgo the details here as they are lengthy and get straight to the challenge at hand. In advance thank you for any input. I have the following use case.

  1. I am hosting a site on WebFlow.
  2. We have a system that generates dynamic URL “referral links” that we track via cookies on a backend sales platform. We have solved for setting and tracking the cookies, however we are unable to yet solve for the structure of the dynamic URL’s we are receiving.
  3. The URL’s are structured as follows:
    www.domain/ref/dynamicvalue1
    www.domain/ref/dynamicvalue2
    www.domain/ref/dynamicvalue3, etc.
  4. These URL’s are in the thousands and continue to be generated daily (i.e. new URL’s generated). This makes setting up a true “directory” structure of the URL’s and/or database on the WebFlow side unsustainable.
  5. When these URL’s are visited we set a cookie with the “Value” = dynamicvalueX and then redirect the user to our homepage.
  6. Since we can not sustainably create a directory structure for each URL. We need a way to allow any variation of these dynamic URL’s capturing the “dynamicvalue” (at the end of the string) and then redirecting to our homepage.

The only bit we can not solve for is the ability to test for the last part of the URL string /dynamicvalueX. In our current environment this has been solved by some server side Python scripting on our current AWS servers. Now with our move to WebFlow we have lost this ability. That’s my best shot at a description :slight_smile: Any help, direction, input is appreciated.


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

You should switch to a query param, in this way you don’t need to redirect back to the homepage and the links will be all already intercepted, transform www.domain/ref/value to www.domain?ref=value

@pietrofalco thank you for that. Yes I wish we had the params to work with. Currently I’m handcuffed with the structure as is. Appreciate the input.

Then… your only solution is a reverse proxy you have to spin up a nginx instance that reverses the whole webflow site on all urls but the ones that start with /ref/* that will need to be sent to your function script to set the cookie and get redirect

@pietrofalco thank you. That’s beyond my level of understanding but I get the gist of it after a quick google of nginx. I have some engineers/developers working on this as well so I will share this information. Again thank you.

Here’s the easiest way I can think of;

  1. Setup a 301 redirect wildcard pattern that redirects www.domain/ref/(.*) to e.g. www.domain/ref?%1. Check that syntax, I’m not reading the docs atm.
  2. Build a static page on your site named /ref. No UI needed probably, it just has a script that pulls the querystring, e.g. dynamicvalue1 and sticks it in a cookie, and then redirects.

Should work fine, but cookies and script are a bit of a pain.
Of course this breaks if the user has script disabled, but most of the site would break anyway.

A second option is a bit more work, but sidesteps client script with a second “tracking” server;

  1. Setup a separate tracking page which handles the URL parsing and cookie creation. Host that wherever you want, and build it using whatever tech you want, Python is fine. It does not need a UI. Its job is to parse the URL, create the cookie, and redirect.
  2. Host it and assign a subdomain of your main site, e.g. referral.domain.
  3. Here’s where you have to get creative. HTTP has allowances for cookie access between subdomains, as long as you specify the base domain in the cookie creation, e.g. Set-Cookie: name=value; domain=example.com
  4. Redirect the user back to the main site, who now has access to that cookie ( and no client-script was needed ).
  5. Setup your 301 redirects from www.domain/ref/(.*) to e.g. referral.domain/?%1.

@memetican thank you for that. We’ve decided to change the incoming URL structure and use params so my original question is no longer an issue. Thanks to all for the responses.

Thanks @DanM , I was curious how that was going.

I’ve written this up as a general referral-tracking approach for anyone else looking to do this on Webflow.

Hi @memetican thanks for sharing that. Very interesting read. In our particular use case we have the referral URL’s being generated externally. We are generating these in a custom-coded SAAS platform (our product). On the WebFlow side we have solved for the ability to accept these custom/dynamic referral URL’s using the format below. We then set two cookies “reg_method” and “ref_src” then when users make an enrollment action on our WebFlow site they go back to the “custom-coded” environment where we test for the cookies and parse the information that is then assigned to the account. I’m only handling the WebFlow side of the equation so my scope is limited.

www.oururl.io/?reg_method=referral&ref_src=msaccountname