-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement user_id and pass it in marketo submission #14440
Merged
+49
−4
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0077283
Implement user_id and pass it in marketo submission
mtruj013 b179417
Fix new cookie bug
mtruj013 32b90c1
Fix undefined error
mtruj013 246e2b0
Fix cookie acceptance value
mtruj013 7628818
Fix enrichment field submission
mtruj013 04424e6
Persist datalayer and apply code review
mtruj013 7b8f854
Persist datalayer and apply code review
mtruj013 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Set a unique user_id if the user has accepted cookies. | ||
If the user has not set their cookie preference, wait for the cookie policy to run first. | ||
*/ | ||
|
||
import { v4 as uuidv4 } from "https://jspm.dev/uuid"; | ||
|
||
const getCookie = (targetCookie) => | ||
document.cookie.match(new RegExp("(^| )" + targetCookie + "=([^;]+)")); | ||
let cookieAcceptanceValue = getCookie("_cookies_accepted"); | ||
|
||
if (cookieAcceptanceValue === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the value is None? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value of that cookie when not set is |
||
cpNs.cookiePolicy(setUserId); | ||
} else { | ||
setUserId(); | ||
} | ||
|
||
function setUserId() { | ||
cookieAcceptanceValue = getCookie("_cookies_accepted"); | ||
if ( | ||
cookieAcceptanceValue?.[2] === "all" || | ||
cookieAcceptanceValue?.[2] === "performance" | ||
) { | ||
// Check if user doesn't already have a user_id | ||
if (!getCookie("user_id")) { | ||
// Generate a universally unique identifier | ||
const user_id = uuidv4(); | ||
document.cookie = "user_id=" + user_id + ";max-age=31536000;"; | ||
|
||
dataLayer.push({ | ||
user_id: user_id, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to install and import
uuidv4
npm package instead. This import looks a bit unusual to me. Is it written somewhere that this is the way it should be done?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't be available client side without a bundler, so I've used a cdn as suggested here