Skip to content

Commit

Permalink
Encode and decode utm params
Browse files Browse the repository at this point in the history
  • Loading branch information
britneywwc committed Jan 14, 2025
1 parent 65f4dc2 commit ba96342
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion static/js/src/cookie-policy-with-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function setUtmCookies(urlParams) {
if (utmParams.endsWith("&")) {
utmParams = utmParams.slice(0, -1);
}
document.cookie = "utms=" + utmParams + ";max-age=86400;path=/;";
document.cookie = "utms=" + encodeURIComponent(utmParams) + ";max-age=86400;path=/;";
}
}

Expand Down
7 changes: 4 additions & 3 deletions webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from geolite2 import geolite2
from requests import Session
from requests.exceptions import HTTPError
from urllib.parse import quote
from urllib.parse import quote, unquote

from canonicalwebteam.search.models import get_search_results
from canonicalwebteam.search.views import NoAPIKeyError
Expand Down Expand Up @@ -993,8 +993,9 @@ def marketo_submit():
],
}

utms = flask.request.cookies.get("utms")
if utms:
encoded_utms = flask.request.cookies.get("utms")
if encoded_utms:
utms = unquote(encoded_utms)
utm_dict = dict(i.split(":", 1) for i in utms.split("&"))
approved_utms = [
"utm_source",
Expand Down

0 comments on commit ba96342

Please sign in to comment.