Urls on Spies.dk contain the query parameters of the options people selected when they performed their holiday search.
When a search is performed on Spies.dk the options selected are stored as query parameters in the url.
- Departure Airport
- Destination
- Duration of Holiday
- Departure date
- Adults
- Children
npm install spies-url-parser --save
var spies_url_parser = require('spies-url-parser');
var parsed = spies_url_parser(url); // e.g: document.referrer (if user came from Spies)
console.log(parsed); // see below for sample output
#### In Browser JS (without browserify/webpack)
<script src="https://cdn.rawgit.com/numo-labs/spies-url-parser/master/index.js"></script>
<script>
var parsed = spies_url_parser(document.referrer); // e.g: document.referrer
console.log(parsed); // see below for sample output
</script>
When a user selects the following options:
- From: København
- Where: Anywhere (destination)
- How long: 1 week
- Departure date: 01-07-2016
- Adults: 2
- Children: 2
The url is:
http://www.spies.dk/bestil-pakkerejse?QueryDepID=12678
&QueryCtryID=-1&QueryAreaID=0&QueryResID=-1
&QueryDepDate=20160701&QueryDur=8&CategoryId=2
&QueryRoomAges=|42,42,9,10&QueryUnits=1
Which we parse as:
{
"departure_airport": "København - CPH",
"pax_mix": {
"passengers": [
"1974-4-11",
"1974-4-11",
"2007-4-11",
"2006-4-11"
],
"adults": 2,
"children": 2
},
"duration_weeks": 1,
"departure_date": "2016-07-01"
}
For the following: query in the Spies UI:
and parsed parameters are:
{
"departure_airport": "Billund - BLL",
"pax_mix": {
"passengers": [
"1974-4-11",
"1974-4-11",
"2009-4-11",
"2013-4-11"
],
"adults": 2,
"children": 2
},
"duration_days": "8",
"departure_date": "2016-09-21",
"destination": "4826,8775"
}