-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14440 from mtruj013/marketo-user
Implement user_id and pass it in marketo submission
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
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) { | ||
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
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