Skip to content

Commit

Permalink
fix: overwriting with null object
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad-hashemi-deriv committed Mar 17, 2023
1 parent 92bc80a commit 82d5eb4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions public/scripts/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ 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
if (!current_utm_data && 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(
(field) => new_utm_data[field] !== "null"
(field) => new_utm_data[field]
);
if (has_new_required_fields) {
return true;
Expand Down

0 comments on commit 82d5eb4

Please sign in to comment.