Created
January 12, 2018 15:33
-
-
Save framingeinstein/073fe490d8c4709d2aac6ad0ef54ac5b to your computer and use it in GitHub Desktop.
Add To URL
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
function parseQuery(href){ | |
var qo = {}; | |
var parts = href.split('?'); | |
var query = []; | |
if(parts.length > 1){ | |
query = parts[1].split('&'); | |
} | |
if(query.length > 0){ | |
if(query[0] == ""){ | |
query.shift(); | |
} | |
for(var i = 0; i < query.length; i++){ | |
var kv = query[i].split('=') | |
qo[kv[0]] = ''; | |
if(kv.length > 1){ | |
qo[kv[0]] = kv[1]; | |
} | |
} | |
} | |
return qo; | |
} | |
function serializeObjectToQueryString(obj, prefix) { | |
var str = [], p; | |
for(p in obj) { | |
if (obj.hasOwnProperty(p)) { | |
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; | |
str.push((v !== null && typeof v === "object") ? | |
serialize(v, k) : | |
encodeURIComponent(k) + "=" + encodeURIComponent(v)); | |
} | |
} | |
return str.join("&"); | |
} | |
var exclusions = [ | |
'www[.]tallpaulscampers[.]com', | |
//'www[.]campingworld', | |
//'rv[.]campingworld', | |
//'campingworld[^.]*[.]com', | |
//'olingertravelhomes' | |
]; | |
var excludedDealers = [ | |
844950 | |
,823170 | |
,737500 | |
,731852 | |
,729036 | |
,3031946 | |
,2995868 | |
,2977626 | |
,2961874 | |
,2933526 | |
,2929502 | |
,2925586 | |
,2919884 | |
,2890098 | |
,2831614 | |
,3044512 | |
// Ride Now exclusions | |
,2797556 | |
,735720 | |
,781718 | |
,740322 | |
,2896316 | |
,2656688 | |
,2925998 | |
,2797840 | |
,2925990 | |
,2915950 | |
,2900076 | |
,2925996 | |
,3000630 | |
,2997786 | |
,3039106 | |
,2997788 | |
,3003916 | |
//Berks Mont Camping Center | |
,729202 | |
]; | |
// | |
var forcedDealers = [ | |
706763 // CAMPING WORLD RV SALES - SAVANNAH | |
]; | |
var skip = false; | |
var forced = false; | |
var dealerid; | |
if(trk.dealerid){ | |
dealerid = parseInt(trk.dealerid); | |
skip = excludedDealers.indexOf(dealerid) >= 0; | |
//console.log('SKIP: ', skip); | |
forced = forcedDealers.indexOf(dealerid) >= 0; | |
if(forced){ | |
skip = false; | |
} | |
} | |
(function($){ | |
$('a#itemWebsite, a.dealerWebsiteLink, a[data-track="Gallery-Seller Website Link"]').each(function(){ | |
var link = $(this); | |
//link = $(this).parents('a'); | |
//if(!parentLink) link = $(this); | |
var regex = new RegExp('(' + exclusions.join(')|(') + ')', 'ig'); | |
var href = link.attr('href'); | |
//console.log('HREF: ', href); | |
//console.log(regex, href, regex.test(href), !/https:/ig.test(href) && !regex.test(href)); | |
if(forced || (!skip && (!/https:/ig.test(href) && !regex.test(href)))){ | |
//console.log('I should not be here', /https:/ig.test(href), regex.test(href), (!/https:/ig.test(href) && !regex.test(href))); | |
var qo = parseQuery(href); | |
var utms = ['utm_campaign', 'utm_medium', 'utm_source', 'utm_content']; | |
//parts[0] = parts[0].replace(/https?:[/][/]/, ''); | |
if(!qo.utm_source || qo.utm_source == '') | |
qo.utm_source = document.location.hostname; | |
if(!qo.utm_medium || qo.utm_medium == '') | |
qo.utm_medium = document.location.pathname;//.replace(/https?:[/][/]/, ''); | |
//qo.utm_medium = qo.utm_medium.replace(/www[^/]*/, ''); | |
var sp = qo.utm_medium.split("/"); | |
sp.shift() | |
var last = sp.pop(); //last element of path | |
last = last.replace(/[ ]+/g, '-'); | |
last = last.replace(/[+]/g, '-'); | |
sp.push(last) | |
qo.utm_medium - sp.join('-'); | |
//query.push('utm_medium=' + document.location.href.replace(/https?:[/][/]/, '')); | |
if(!qo.utm_campaign || qo.utm_campaign == '') | |
qo.utm_campaign = 'dealer-click'; | |
//query.push('utm_campaign=Referral'); | |
if(!qo.utm_content || qo.utm_content == ''){ | |
if(link.data('track') == 'Gallery-Seller Website Link'){ | |
qo.utm_content = 'view-website-link-gallery'; | |
} else if (link.data('track') == 'Detail-Seller Box-Website Link'){ | |
qo.utm_content = 'view-inventory-link'; | |
} else { | |
qo.utm_content = 'view-website-link'; | |
} | |
} | |
//if(dealerid && dealerid == 2986346){ | |
// qo.utm_medium = 'referral'; | |
//} | |
qo.utm_medium = 'referral'; | |
var parts = href.split('?'); | |
if(parts.length == 1){ | |
parts.push(serializeObjectToQueryString(qo)); | |
} else { | |
parts[1] = serializeObjectToQueryString(qo); | |
} | |
link.attr('href', parts.join('?')); | |
} | |
}); | |
})(jQuery); | |
/* | |
GALLERY: | |
http://www.ridenowcraig.com/--cycletrader? | |
utm_campaign=dealer-click | |
utm_source=cycletrader.com | |
utm_medium=referral | |
utm_content=view-website-link-gallery | |
utm_source=www.cycletrader.com | |
utm_medium=www.cycletrader.com/dealers/detail/Ridenow+Las+Vegas+on+Craig-2797840?sort=featured:asc | |
AD Detail - Seller Info Detail-Seller Website Link | |
http://www.ridenowcraig.com/--cycletrader? | |
utm_campaign=dealer-click | |
utm_source=cycletrader.com | |
utm_medium=referral | |
utm_content=view-website-link | |
utm_source=www.cycletrader.com | |
utm_medium=www.cycletrader.com/dealers/Ridenow-Las-Vegas-on-Craig-2797840/listing/2017-Yamaha-FJ-09-120944089 | |
Ad Detail - More From Detail-Seller Website Link | |
http://www.ridenowcraig.com/--cycletrader? | |
utm_campaign=dealer-click | |
utm_source=cycletrader.com | |
utm_medium=referral | |
utm_content=view-website-link-inventory-detail | |
utm_source=www.cycletrader.com | |
utm_medium=www.cycletrader.com/dealers/Ridenow-Las-Vegas-on-Craig-2797840/listing/2017-Yamaha-FJ-09-120944089 | |
Ad Detail - Inventroy Direct Detail-Seller Box-Website Link | |
http://www.ridenowcraig.com/--xInventoryDetail?id=2896904& | |
utm_source=www.cycletrader.com | |
utm_medium=www.cycletrader.com/dealers/Ridenow-Las-Vegas-on-Craig-2797840/listing/2017-Yamaha-FJ-09-120944089 | |
utm_content=view-inventory-link | |
utm_campaign=dealer-click | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment