Skip to content

Instantly share code, notes, and snippets.

@shawncreed
Last active March 18, 2019 18:37
Show Gist options
  • Select an option

  • Save shawncreed/152cfa739f1ba0f2a6ee32d1f804895d to your computer and use it in GitHub Desktop.

Select an option

Save shawncreed/152cfa739f1ba0f2a6ee32d1f804895d to your computer and use it in GitHub Desktop.
Example of page using image pixel to send data to another server to be set in a cookie
<html>
<head>
<title>Set cookie example</title>
</head>
<body>
<h1>Set cookie example</h1>
This is a page on the site where the cookie is already available.
<script language="javascript">
/* This is where our data layer is being set */
digitalData = {
user: {
userid: 'a3cceba83235dc95f750108d22c14731'
}
};
</script>
<script language="javascript">
/* This is where we can pull the value from the data layer to populate
* a pixel to set the cookie on the other domain
*/
var img = document.createElement('img');
img.height = 1;
img.width = 1;
img.src = 'https://www.mybank.com/setcookie.php?userid=' + digitalData.user.userid;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment