Last active
October 25, 2017 10:38
-
-
Save phpivanov/c9a10f2ed55abd71a73585ddee7f3dc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="https://yastatic.net/jquery/3.1.0/jquery.min.js"></script> | |
<script>var jquery_3_1_0 = jQuery;</script> | |
<script type="text/javascript"> | |
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, " ")); | |
} | |
$(function() { | |
var $ = jQuery = jquery_3_1_0; | |
var THANKS_URL = 'http://thanks.positive.bio/?offer_id=75' // url страницы "спасибо" | |
var TOKEN = 'TOKEN' | |
$('form').submit(function() { | |
var form = $(this) | |
$.post({ | |
url: 'http://leads.api.drcash.me/sf', | |
data: { | |
token: TOKEN, | |
name: $('[name="name"]', form).val(), | |
phone: $('[name="phone"]', form).val(), | |
aff_sub: getParameterByName('sub1'), | |
aff_sub2: getParameterByName('sub2'), | |
aff_sub3: getParameterByName('sub3'), | |
aff_sub4: getParameterByName('sub4'), | |
aff_sub5: getParameterByName('sub5'), | |
}, | |
success: function(data) { | |
// редиректим на страницу "спасибо" с параметрами конверсии в URL | |
if (data.response.success == 'true') { | |
var conversion = data.response.conversions[0] | |
THANKS_URL += (THANKS_URL.indexOf('?') >= 0 ? '&' : '?') + $.param(conversion) // добавляем параметры | |
window.location.replace(THANKS_URL); // редирект | |
} else { | |
console.error('При отправке конверсии произошла ошибка: ' + data.response.msg) | |
} | |
}, | |
dataType: 'json' | |
}) | |
return false | |
}) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment