Skip to content

Commit

Permalink
fix: added changes to cookie msc click id (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuran-deriv authored Jan 29, 2024
1 parent b6efa7c commit 8a2c4fe
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions public/scripts/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const toISOFormat = (date) => {

const shouldOverwrite = (new_utm_data, current_utm_data) => {
// If we don't have old utm data, the utm_source field is enough for new utm data
const valid_new_utm_source = new_utm_data.utm_source && new_utm_data.utm_source !== "null"
const valid_new_utm_source =
new_utm_data.utm_source && new_utm_data.utm_source !== "null";
if (!current_utm_data && valid_new_utm_source) {
return true;
}

// If we have old utm data, 3 fields are required for new utm data to rewrite the old one
const required_fields = ["utm_source", "utm_medium", "utm_campaign"];
const has_new_required_fields = required_fields.every(
Expand Down Expand Up @@ -92,10 +92,13 @@ const shouldOverwrite = (new_utm_data, current_utm_data) => {
"utm_click_id",
"utm_adgroup_id",
"utm_campaign_id",
"utm_msclk_id",
];

let utm_data = {};
const current_utm_data = JSON.parse(decodeURIComponent(getCookie("utm_data")));
const current_utm_data = JSON.parse(
decodeURIComponent(getCookie("utm_data"))
);

// If the user comes to the site for the first time without any URL params
// Only set the utm_source to referrer if the user does not have utm_data cookies stored
Expand All @@ -108,9 +111,7 @@ const shouldOverwrite = (new_utm_data, current_utm_data) => {
// If the user has any new UTM params, store them
utm_fields.forEach((field) => {
if (searchParams.has(field)) {
utm_data[field] = searchParams
.get(field)
.substring(0, 100); // Limit to 100 supported characters
utm_data[field] = searchParams.get(field).substring(0, 100); // Limit to 100 supported characters
}
});

Expand Down

0 comments on commit 8a2c4fe

Please sign in to comment.