Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Подмена телефона и email по utm_source -->
- <script type="text/javascript">
- (function($){
- $(document).ready(function() {
- function urlParam(name) {
- var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
- if (results && results[1]) {
- return results[1];
- }
- return null;
- };
- function getCookie(name) {
- var matches = document.cookie.match(new RegExp(
- "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
- ));
- return matches ? decodeURIComponent(matches[1]) : undefined;
- }
- function setCookie(name, value, options) {
- options = options || {};
- var expires = options.expires;
- if (typeof expires == "number" && expires) {
- var d = new Date();
- d.setTime(d.getTime() + expires * 1000);
- expires = options.expires = d;
- }
- if (expires && expires.toUTCString) {
- options.expires = expires.toUTCString();
- }
- value = encodeURIComponent(value);
- var updatedCookie = name + "=" + value;
- for (var propName in options) {
- updatedCookie += "; " + propName;
- var propValue = options[propName];
- if (propValue !== true) {
- updatedCookie += "=" + propValue;
- }
- }
- document.cookie = updatedCookie;
- }
- function getUtmSource() {
- var value = urlParam('utm_source'); //подмена работает по значению utm_source
- if (value === null || !value.length) {
- value = getCookie('utm_source');
- } else {
- setCookie('utm_source', value, {expires: 60 * 60 * 24 * 7}); //срок хранения значения utm_source в куках браузера пользователя
- }
- return value;
- }
- if (window.location.pathname == '/contacts') { //на какой странице менять телефон и email
- var data = {
- phone: null,
- email: null
- };
- var id = parseInt(getCookie('roistat_visit'));
- if (isNaN(id)) {
- return false;
- }
- data.email = 'kp+' + id + '@i-shell.ru';
- // ниже идут соответствия utm_source и подменных номеров и email
- /*
- var utm_source = getUtmSource();
- if (utm_source == 'yandex') {
- data.phone = '+7 (499) 112-32-66';
- data.email = 'kp+yd@i-shell.ru';
- } else if (utm_source == 'google') {
- data.phone = '+7 (499) 112-32-66';
- data.email = 'kp+ga@i-shell.ru';
- }*/
- // дальше указаны значения по-умолчанию
- if (data.phone !== null) {
- var $phone = $('span').filter(function() {
- return $(this).text() == '+7 (499) 112-32-66' && !$(this).children().length;
- });
- $phone.text(data.phone);
- }
- if (data.email !== null) {
- var $email = $('span').filter(function() {
- return $(this).text() == 'kp@i-shell.ru' && !$(this).children().length;
- });
- $email.text(data.email);
- }
- }
- });
- })(jQuery);
- </script>
- <!-- /Подмена телефона и email по utm_source -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement