Last active
August 2, 2024 09:47
-
-
Save luongngocminh/ba583ca53a8697193b5c1f11331bcd82 to your computer and use it in GitHub Desktop.
Hijack Engagebay form redirection to add external params like UTM
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
// Hijacking Engagebay HTML form submission redirection | |
// By: Luong Ngoc Minh | |
// Usage: Replace the original form submit function, for custom form with dedicated Submit button, not for embeded form | |
function onSubmit(e, t) { | |
e.preventDefault(); | |
window.EhForm.redirect_to_url = function(a, f, i, b) { | |
var g = f; | |
try { | |
g = JSON.parse(f); | |
} catch (h) { | |
console.log(h); | |
} | |
var j = { | |
subscriber_data: JSON.stringify(g), | |
}; | |
var c = a; | |
c = eh_mustache_fill_Subscriber_Data(g, c); | |
if (i) { | |
c = EhSync.prepareURL(c, j); | |
} | |
var d = window.open(c + document.location.search, b ? "_blank" : "_self"); | |
d.location; | |
}; | |
window.EhForm.submit_form(e, t); | |
} |
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
// Hijacking Engagebay HTML form submission redirection | |
// By: Luong Ngoc Minh | |
// Usage: For embed form, copy the following code to your EngageBay install script, inside EhAPI.after_load function | |
... | |
window.EhSync.prepareURL = function (a, c) { | |
if (c) { | |
c.callback = "?"; | |
} | |
var e = ""; | |
for (var b in c) { | |
var d = c[b]; | |
if (d && typeof d != "string") { | |
continue; | |
} | |
d = b == "callback" ? d : encodeURIComponent(d); | |
e += b + "=" + d + "&"; | |
} | |
// a hack try to keep the query string | |
let inject = document.location.search.replace("?", ""); | |
e += inject; | |
// ----------------------------------- | |
console.log('hack', e); | |
a = (a.indexOf("?") == -1 ? a + "?" : a + "&") + e; | |
return a.lastIndexOf("&") != a.length - 1 | |
? a | |
: a.slice(0, a.length - 1); | |
}; | |
... | |
/// For example | |
<script type="text/javascript"> | |
var EhAPI = EhAPI || {}; | |
EhAPI.after_load = function () { | |
EhAPI.set_account("...", "..."); | |
EhAPI.execute("rules"); | |
// Hack to fix the form | |
console.log("EhAPI.after_load hook ran"); | |
window.EhSync.prepareURL = function (a, c) { | |
.... | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment