Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. <!-- Подмена телефона и email по utm_source -->
  2. <script type="text/javascript">
  3. (function($){
  4. $(document).ready(function() {
  5. function urlParam(name) {
  6. var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
  7. if (results && results[1]) {
  8. return results[1];
  9. }
  10. return null;
  11. };
  12.  
  13. function getCookie(name) {
  14. var matches = document.cookie.match(new RegExp(
  15. "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  16. ));
  17. return matches ? decodeURIComponent(matches[1]) : undefined;
  18. }
  19.  
  20. function setCookie(name, value, options) {
  21. options = options || {};
  22.  
  23. var expires = options.expires;
  24.  
  25. if (typeof expires == "number" && expires) {
  26. var d = new Date();
  27. d.setTime(d.getTime() + expires * 1000);
  28. expires = options.expires = d;
  29. }
  30. if (expires && expires.toUTCString) {
  31. options.expires = expires.toUTCString();
  32. }
  33.  
  34. value = encodeURIComponent(value);
  35.  
  36. var updatedCookie = name + "=" + value;
  37.  
  38. for (var propName in options) {
  39. updatedCookie += "; " + propName;
  40. var propValue = options[propName];
  41. if (propValue !== true) {
  42. updatedCookie += "=" + propValue;
  43. }
  44. }
  45.  
  46. document.cookie = updatedCookie;
  47. }
  48.  
  49. function getUtmSource() {
  50. var value = urlParam('utm_source'); //подмена работает по значению utm_source
  51. if (value === null || !value.length) {
  52. value = getCookie('utm_source');
  53. } else {
  54. setCookie('utm_source', value, {expires: 60 * 60 * 24 * 7}); //срок хранения значения utm_source в куках браузера пользователя
  55. }
  56. return value;
  57. }
  58.  
  59. if (window.location.pathname == '/contacts') { //на какой странице менять телефон и email
  60. var data = {
  61. phone: null,
  62. email: null
  63. };
  64.  
  65. var id = parseInt(getCookie('roistat_visit'));
  66. if (isNaN(id)) {
  67. return false;
  68. }
  69.  
  70. data.email = 'kp+' + id + '@i-shell.ru';
  71.  
  72. // ниже идут соответствия utm_source и подменных номеров и email
  73. /*
  74. var utm_source = getUtmSource();
  75. if (utm_source == 'yandex') {
  76. data.phone = '+7 (499) 112-32-66';
  77. data.email = 'kp+yd@i-shell.ru';
  78. } else if (utm_source == 'google') {
  79. data.phone = '+7 (499) 112-32-66';
  80. data.email = 'kp+ga@i-shell.ru';
  81. }*/
  82. // дальше указаны значения по-умолчанию
  83. if (data.phone !== null) {
  84. var $phone = $('span').filter(function() {
  85. return $(this).text() == '+7 (499) 112-32-66' && !$(this).children().length;
  86. });
  87. $phone.text(data.phone);
  88. }
  89.  
  90. if (data.email !== null) {
  91. var $email = $('span').filter(function() {
  92. return $(this).text() == 'kp@i-shell.ru' && !$(this).children().length;
  93. });
  94. $email.text(data.email);
  95. }
  96. }
  97. });
  98. })(jQuery);
  99. </script>
  100. <!-- /Подмена телефона и email по utm_source -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement