Skip to content

Instantly share code, notes, and snippets.

@xrem
Created August 19, 2016 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xrem/5af9966147b53ba90d6457be56339d7c to your computer and use it in GitHub Desktop.
Save xrem/5af9966147b53ba90d6457be56339d7c to your computer and use it in GitHub Desktop.
blog.radario.ru
var days = 7; // Количество дней хранения в cookie. (Сейчас 7)
var utmSource = getParameterByName('utm_source');
var set = false;
var attr;
if (utmSource) {
attr = utmSource; // Дополнительный параметр для кнопопк data-utm-source
$.cookie('utm', utmSource, { expires: days });
set = true;
} else if ($.cookie('utm')){
utmSource = $.cookie('utm');
attr = utmSource; // Дополнительный параметр для кнопопк data-utm-source
set = true;
}
if (set) {
jQuery(document).ready(function($) {
$(".utmbutton").find('script').attr('data-utm-source', attr);
});
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment