Skip to content

Instantly share code, notes, and snippets.

@raujohn
Created December 30, 2017 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raujohn/0a1379219d0acd6b244f6f88ac705872 to your computer and use it in GitHub Desktop.
Save raujohn/0a1379219d0acd6b244f6f88ac705872 to your computer and use it in GitHub Desktop.
// SEND DATA TO HUBSPOT
// Hubspot form endpoint
var endpoint = "https://forms.hubspot.com/uploads/form/v2/547412/c939999e-fbf7-47e9-a7a0-69506320dcde";
// Get Hubspot tracking id from cookie
var hutk = Cookies.get('hubspotutk');
// Get Page URL and Title
var pageUrl = $(location).attr('href');
var pageTitle = $(document).attr('title');
// Get User IP and submit to hubspot on success
$.get( "http://ipinfo.io", function(response) {
// Load up hs_context json
var userIp = response.ip;
var hs_context = {
"hutk": hutk,
"ipAddress": userIp,
"pageUrl": pageUrl,
"pageName": pageTitle,
"redirectUrl": ""
}
// Load up str_post data to send
var data = {
"email": email,
"calculator_average_product_price": $("#fb-saascalc-input-average-product-price").val(),
"calculator_number_of_customers": $("#fb-saascalc-input-number-of-customers").val(),
"calculator_customers_gained_prev_mo_": $("#fb-saascalc-input-customers-gained").val(),
"calculator_customers_lost_prev_mo_": $("#fb-saascalc-input-customers-lost").val(),
"hs_context": hs_context
}
console.log( data );
// Send data to Hubspot
$.post( endpoint,
data,
function( response) {
// Nothing to do here
});
}, "jsonp");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment