Created
November 6, 2019 15:41
-
-
Save Gaikanomer9/ed2f0b17cbaaf161b7fb9dc468e6e1ca to your computer and use it in GitHub Desktop.
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
<!-- Script for extracting url params --> | |
<script type="text/javascript"> | |
function setupCookie(cookieName, cookieValue) { | |
var cookiePath = '/' | |
var expirationTime = 2592000 //time the cookie should expire in seconds | |
expirationTime = expirationTime * 1000 //Convert expirationtime to milliseconds | |
var date = new Date() //Create new date | |
var dateTimeNow = date.getTime() //What is the current time in milliseconds | |
date.setTime(dateTimeNow + expirationTime) //Set expiration time | |
var expirationTime = date.toUTCString() //Convert milliseconds to UTC time string | |
document.cookie = | |
cookieName + | |
'=' + | |
cookieValue + | |
'; expires=' + | |
expirationTime + | |
'; path=' + | |
cookiePath //Set cookie | |
} | |
function checkUrl() { | |
var cookieName = 'trivago_pixel' | |
var url = new URL(window.location.href) | |
var cookieValue = url.searchParams.get('utm_source') | |
if (cookieValue === 'Trivago') { | |
setupCookie(cookieName, cookieValue) | |
//extracting hotel id | |
setupCookie('hotel', url.searchParams.get('hotelid')) | |
//extracting dates | |
setupCookie('arrival', url.searchParams.get('datein')) | |
setupCookie('departure', url.searchParams.get('dateout')) | |
} | |
} | |
checkUrl() | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment