Created
July 31, 2018 18:23
-
-
Save camaleaun/84464860aa3da60ffbcdddfc1b5d1f3b to your computer and use it in GitHub Desktop.
Hsform hack to redirects to HypnoBx chat
This file contains 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
<!--[if lte IE 8]> | |
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script> | |
<![endif]--> | |
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script> | |
<script> | |
hbspt.forms.create({ | |
portalId: "PORTAL_ID_HERE", | |
formId: "FORM_ID_HERE" | |
}); | |
var chatData = {}; | |
window.addEventListener('message', event => { | |
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') { | |
event.data.data.forEach(function (field) { | |
chatData[field.name] = field.value; | |
}); | |
} | |
}); | |
window.addEventListener('message', event => { | |
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') { | |
var params = { | |
'controle': 'Atendimento', | |
'acao': 'index', | |
'produto': 2, | |
'midia': 'MIDIA_HERE', | |
'nome': chatData.firstname, | |
'email': chatData.email, | |
'telefone': chatData.phone, | |
}; | |
var paramsStr = Object.keys(params).map(function(key) { | |
return key + '=' + params[key]; | |
}).join('&'); | |
var chatUrl = encodeURI('http://CLIENT_HERE.hypnobox.com.br/?'+paramsStr); | |
window.location = chatUrl; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment