Skip to content

Instantly share code, notes, and snippets.

@Gaikanomer9
Created November 6, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gaikanomer9/ed2f0b17cbaaf161b7fb9dc468e6e1ca to your computer and use it in GitHub Desktop.
Save Gaikanomer9/ed2f0b17cbaaf161b7fb9dc468e6e1ca to your computer and use it in GitHub Desktop.
<!-- 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