APIs & Integrations

janik
Participant

Instantly identify users via _hsq.push

Hi,

I’m building a landing page where new website visitors who arrive on our page via a custom url shall be identified so that their data such as name and e-mail address can be accessed.
The process is as follows:

  1. User enters his customs url (website.com/firstname-lastname)
  2. 301 Redirect to a blank landingpage with javascript code to identify the user
    (website.com/welcome?email=lastname@company.com&fwd_url=website.com/landingpage)
  3. Email address is used to identify user via _hsq.push, followed by a custom event and window.location to forward user to the final landingpage (website.com/landingpage)
  4. All user data can be accessed via http data on the final landingpage

Here’s the code which is executed on the blank landingpage:
var _hsq = window._hsq = window._hsq || [];

_hsq.push(["identify",{
	email: '<?php echo($email); ?>'
}]);

_hsq.push(["trackEvent", {
    id: "Outbound Mail Test"
}]);

/*setTimeout(function () {
   window.location = '<?php echo($fwd_url) ?>';
}, 2000);*/

window.location = '<?php echo($fwd_url) ?>';

The problem I’m facing is that if the window.location function forwards the user, data has not succesfully been pushed to Hubspot. When I’m making use of a 2 second delay (as you can see being commented out) however it works.

I understand that the _hsq.push function runs asynchronously. Is there a way to trigger the window.location forward once the data has been pushed to hubspot successfully and can be used on the final landing page?

Best,
Janik

0 Upvotes
3 Replies 3
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Instantly identify users via _hsq.push

Hi @janik.parcellab,

Just to make sure that we’re on the same page, you’re pushing the contact info to HubSpot using the identify method, and then pulling the info from HubSpot using your PHP script on the final landing page? You could try passing the contact info to the final landing page via some other method (e.g. query parameters) so that you could customize the page content and call the identify method on the final page.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Instantly identify users via _hsq.push

Hi @janik.parcellab,

You’re correct that the tracking code methods are run asynchronously; there isn’t currently any way to force these methods to be synchronous, or otherwise delay the page forwarding until the methods are called. Would it be possible for you to call the tracking code methods on the final landing page, instead of using a blank intermediary page?

0 Upvotes
janik
Participant

Instantly identify users via _hsq.push

Hi Derek,

thanks for your reply. Yes it would be possible to call those methods on the final landing page. However we’re using php script to access the identified visitors information (name, email address, company url) on the final landing page to customize the page. Therefore the call tracking code methods have to be called on the intermediary page already. As for now I created a 3 seconds js delay on the intermediary page which works fine in most cases but of course isn’t convenient for the user. Would be great if we could figure out a workaround.

Best, Janik

0 Upvotes