We use social login (Google, GitHub and Microsoft as Identity Providers) and we wanna understand users that signup where they came from. The flow looks like this
- User lands on the website for example from a campaign (
utm
params in the url) - User accepts the hubspot tracking banner
- User clicks on the signup button
- User is redirected to our "developer portal" where we trigger a social login with their selected provider. We have the hubspot tracking code running also on our developer portal.
- User finishes the signup and lands on our internal console dashboard
We are pushing a new contact to Hubspot on step 5
but at that point we lose all the information about how the user landed in first place on our website, if it was direct traffic or ads campaign etc because we are creating the contact from our backend calling the Hubspot API.
We noticed that when someone would send a form from the website with their email, Hubspot would create a contact and automatically capture a lot of information (probably thanks to the tracking script)
We decided to send a "hidden form" via the legacy Forms API endpoint. https://legacydocs.hubspot.com/docs/methods/forms/submit_form
const hutk = Cookies.get("hubspotutk");
await fetch(
"https://api.hsforms.com/submissions/v3/integration/submit/8403675/7448d6fd-a54d-4969-a6c5-49cda797448d",
{
headers: {
"content-type": "application/json"
},
method: "post",
body: JSON.stringify({
fields: [
{
name: "email",
value: email
}
],
context: {
hutk: hutk,
pageUri: window.location.href,
pageName: document.title
}
})
}
);
Once we send this, we can see a new contact in Hubspot and sometimes this has the correct informations about the source, which ad campaign lead them to the website etc, but sometimes this doesn't work and we don't know why.
We send this temporary email anonymous-{uuid}@tru.id
param to our backend when the user signup and on step 5
we reconcile by PATCHING the user contact on Hubspot replacing the temporary email with the correct user email.