var b_gps=option.GPS;
var commaPos=b_gps.indexOf(',');
var coordinatesLat=parseFloat(b_gps.substring(0,commaPos));
var coordinatesLong=parseFloat(b_gps.substring(commaPos+1,b_gps.length));
PlacemarkB=new ymaps.Placemark([coordinatesLat,coordinatesLong],{
https://gist.github.com/chrislkeller/3553967
Для всех ссылок которые начинаются с tel:
$("a[href^='tel']").on('click',function(){
//
});
По аналогии для ссылок которые заканчиваются на:
$("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.png'],a[href$='.gif']").on('click',function(){
//
});
Также в случае отсутствия gclid и utm определять источник по document.referrer
учитывая домены поисковых систем.
document.addEventListener("DOMContentLoaded",function(event){
var seo_params=new Array('ga_cid','gclid','utm_source','utm_medium','utm_campaign','utm_content','utm_term');
var seo_cookies=new Array();
var seo_cookies_default=new Array();
var params=new URLSearchParams(location.search);
seo_params.forEach((sp)=>{
switch(sp){
case 'gclid':
seo_cookies_default[sp]='NULL';
break;
case 'utm_source':
seo_cookies_default[sp]='direct';
break;
default:
seo_cookies_default[sp]='none';
break;
}
});
var update_cookies=false;
if(params.has('gclid')&¶ms.get('gclid')!=''&¶ms.get('gclid')!='none'){
update_cookies=true;
seo_params.forEach((sp)=>{
switch(sp){
case 'gclid':
seo_cookies[sp]=params.get(sp);
break;
case 'utm_source':
seo_cookies[sp]='google';
break;
case 'utm_medium':
seo_cookies[sp]='cpc';
break;
default:
if(sp.indexOf('utm_')!=-1&¶ms.has(sp)&¶ms.get(sp)!=''){
seo_cookies[sp]=params.get(sp);
}
else{
seo_cookies[sp]='none';
}
break;
}
});
}
else{
var is_utm=false;
seo_params.forEach((sp)=>{
if(sp.indexOf('utm_')&¶ms.has(sp)&¶ms.get(sp)!=''){
seo_cookies[sp]=params.get(sp);
is_utm=true;
update_cookies=true;
}
else{
seo_cookies[sp]='none';
}
});
if(!is_utm){
var referer=document.referrer;
if(referer!=''){
var referer_domain=referer.split('/')[2];
if(referer_domain!=''&&referer_domain!=location.hostname){
update_cookies=true;
var organics=new Array('google','yandex','ya.','bing');
var is_organic=false;
organics.forEach((organic)=>{
if(referer_domain.indexOf(organic)!=-1){
if(organic=='ya.'){
organic='yandex'
}
is_organic=true;
seo_params.forEach((sp)=>{
switch(sp){
case 'utm_source':
seo_cookies[sp]=organic;
break;
case 'utm_medium':
seo_cookies[sp]='organic';
break;
default:
if(sp.indexOf('utm_')){
seo_cookies[sp]='none';
}
break;
}
});
}
});
if(!is_organic){
seo_params.forEach((sp)=>{
switch(sp){
case 'utm_source':
seo_cookies[sp]=referer_domain;
break;
case 'utm_medium':
seo_cookies[sp]='referral';
break;
default:
if(sp.indexOf('utm_')!=-1){
seo_cookies[sp]='none';
}
break;
}
});
}
}
}
}
}
var ga_cookie=document.cookie.match(new RegExp('(^| )_ga=([^;]+)'));
if(ga_cookie[2]){
var ga_cookie_split=ga_cookie[2].split(".");
var ga_cid=ga_cookie_split[2]+'.'+ga_cookie_split[3];
seo_cookies['ga_cid']=ga_cid;
}
seo_params.forEach((sp)=>{
var sp_cookie=document.cookie.match(new RegExp('(^| )local_'+sp+'=([^;]+)'));
if(update_cookies||!sp_cookie||sp=='ga_cid'){
var cv=(seo_cookies[sp]!='')?seo_cookies[sp]:seo_cookies_default[sp];
document.cookie=encodeURIComponent('local_'+sp)+'='+encodeURIComponent(cv);
}
});
var links=document.getElementsByTagName("a");
for(i=0;i<links.length;i++){
var href=links[i].href;
if(href.includes(document.domain)&&!(href.includes('#'))){
seo_params.forEach((sp)=>{
var sp_cookie=document.cookie.match(new RegExp('(^| )local_'+sp+'=([^;]+)'));
if(sp_cookie[2]){
href+=(href.includes('?'))?"&":"?";
href+=sp+"="+sp_cookie[2];
}
})
links[i].href=href;
}
}
const url=new URL(window.location.href);
seo_params.forEach((sp)=>{
var sp_cookie=document.cookie.match(new RegExp('(^| )local_'+sp+'=([^;]+)'));
if(sp_cookie[2]&&!params.has(sp)){
url.searchParams.append(sp,sp_cookie[2]);
}
});
window.history.pushState(null,null,url);
});