Advertisement
Guest User

email i-shell

a guest
Sep 26th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 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. var utm_source = getUtmSource();
  60.  
  61. console.log(utm_source);
  62.  
  63. if (window.location.pathname == '/contacts') { //на какой странице менять телефон и email
  64. var data = {
  65. phone: null,
  66. email: null
  67. };
  68. // ниже идут соответствия utm_source и подменных номеров и email
  69. if (utm_source == 'yandex') {
  70. data.phone = '+7 (499) 112-32-66';
  71. data.email = 'kp+yd@i-shell.ru';
  72. } else if (utm_source == 'google') {
  73. data.phone = '+7 (499) 112-32-66';
  74. data.email = 'kp+ga@i-shell.ru';
  75. }
  76. // дальше указаны значения по-умолчанию
  77. if (data.phone !== null) {
  78. var $phone = $('span').filter(function() {
  79. return $(this).text() == '+7 (499) 112-32-66' && !$(this).children().length;
  80. });
  81. $phone.text(data.phone);
  82. }
  83.  
  84. if (data.email !== null) {
  85. var $email = $('span').filter(function() {
  86. return $(this).text() == 'kp@i-shell.ru' && !$(this).children().length;
  87. });
  88. $email.text(data.email);
  89. }
  90. }
  91. });
  92. })(jQuery);
  93. </script>
  94. <!-- /Подмена телефона и email по utm_source -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement