Capture data from page and pass to LeadsHook


Is it possible to capture data from my web page - a session id for the visitor - and capture it in a LeadsHook field?

Here’s a brief video, showing what I’m trying to accomplish:



Just saw the new Tracking functionality available in the node.

I’m wondering if I can use that to pass page data into LeadsHook?

Here’s a brief video, showing what I’m trying with it:


Hi @Wynne_Pirini,

Great thinking on using exit.

Spot on. That’s exactly what you’d be doing. Click the custom field and it will add {custom_field} wherever you want it to add it.

You’ll see an example here:

I’m assuming you’re already loading the tracking script using GTM or from Tracking section.

Lastly please test by activating first. I think we fire 3rd party scripts only when activated.



Hi Nik,

Thanks for the info. I had a read of the knowledge base article.

I’m still not clear, though, on how to achieve my goal.

Here’s what I mean…

The LeadsHook DT is displayed on my webpage, via an iframe.

But, the sessionID is in the parent container.

Once stored in a Javascript variable, I need to pass it back into LeadsHook, and store the data in a custom variable named session_id.

Then, I’ll be able to send the sessionID to my system, along with contact info and other decision tree data, via a webhook POST request - e.g. {session_id} .

How do I do accomplish this?



Hi @Wynne_Pirini,

Let me get back to you on this.

One solution could be via GTM.

Let me think about this and chat with the devs to see how this can be achieved.

Are you using GTM?



Pushing the session var into LH is not the issue. It’s how to capture into a custom field.

Interesting problem. :slight_smile:



Have you added the tracking to GTM and fired same container on parent page and LH.

Since session var is issued by AutoPilot, depending on how good the their tracker is can sometimes work out it’s the same browser and person (like FB). No cross domain issues for AutoPilot since its dropping cookies from the same domain.




Here’s a good article on what you need to do…

Push session var into dataLayer
Grab sessein var from dataLayer

I’ll get info on how to save into custom field.



The other method which I think might be better is using PostMessage.

This is similar to what we’ve doing by passing client id from issued by GA on parent page and passing to LH embed.



Hi Nik,

I’m using GTM (the cross domain one, set up using LH), and it’s the same container fired on container and LH.

As you say, Autopilot’s documentation says they use session ID to reconcile a visitor with their unique id in the system.

I’ll have a play with both methods, and see if I can get one working.

Many thanks,


I see this snippet on the datarunsdeep article, and wonder if it causes issues on some iOS devices?

However it’s worth mentioning that this approach is still not desired mainly due to restrictions in IOS that prevent the setting of 3rd party cookies when using iframes with different domains.


First party or 3rd party depends on how the cookie is being dropped by AutoPilot.

GA drops 1st party cookies even in an iframe. They drop the cookie from not Google moved to 1st party cookies when apple did their iOS change.

So not an issue from the tech standpoint. I’d be surprised if AutoPilot drops 3rd party oookies.



Hi Nik

On the container side, I’m able to push the sessionId into the datalayer, and store in a GTM variable.

To extract, on the iframe side, I’m thinking of checking the dataLayer object and extracting the value of the custom sessionId variable I created in GTM.

  var LHsessionId = dataLayer[3].autopilotSessionId);

Here’s a video showing what I’ve experimented with:



Brilliant mate. :slight_smile:

Yes the next issue is to retrieve and to add it into a custom field.

Alternatively you could override the session id in the autopilot script that fires inside LH so then perhaps there is no need to save session id into a custom field. You’re simply override the session id in GTM. I’m guessing then there is nothing to do inside LH.

What do you think? Perhaps give that a try. Once less point of failure.

This basically means adding condition to replace session id with the one the data layer instead of generating a new one.

Hope I’m making sense.



Apologies for the delay. Been thinking about your issue and seeing if there is an easier way.

There is no need to pass the info back to LH. If LH was a checkout or if you wanted to display the session id on screen then it makes sense to bring it back into LH.

But if the sole purpose if to ensure session id sync between your parent page and LH, then I don’t see any need to bring it into LH.

Unless I’m missing something with this logic.



Alternatively please invite me (use leadshook @ g mail . com to your GTM account and I’ll have one of my front end devs have a look and make sure everything is working well.



Hi Nik,

Thanks :slight_smile:

And, thanks for the info on cookies. I’ve checked with Autopilot support. They said the cookie is 3rd party.

I’m not 100% sure what you mean by saying to overriding session id inside LH.


You comments have given me an idea. You’re right, I don’t actually need the data to be pulled back into LH, to send the data via webhook.

Since the variable is now available in GTM datalayer - both in the container, and now in the iframe - I should be able to retrieve the variable, and send it via the webhook POST request.

I’ll experiment with this approach.



Hi Nik,

Just realised what you’re saying with regards to bringing the sessionId from container to iframe.

So, the reason I would do it, is because the visitor builds up a history of visits on the parent container, by visiting various blog posts, landing pages, etc.

Autopilot keeps a log of all of this behaviour via the sessionId.

Once the visitor provides their email, Autopilot associates all previous, trackable behaviour with their new email address - which improves analytics and goal tracking.

With this in mind, I’m not 100% certain, but I think it’s preferable to pass the sessionId through, so it can be sent in the webhook POST request.

(I’ve prevented Autopilot web tracking tag, in GTM, from firing on iframe side)

This morning, I’ve done quite a bit of experimenting, retrieving sessionId on LH side. I can do it while working in the console (via the iframe). But, so far, I’ve been unable to actually display it in a test node, using Javascript. Here’s an example of what I tried:

<p id="test1"></p>

	var LHsessionId = dataLayer[3].autopilotSessionId;
	document.getElementById('test1').textContent = "sessionId is " + LHsessionId;


Hi Wynne,
Did you checked that the var dataLayer[3] has the right content. Just so we be 100% sure it’s a rendering issue.
If you can please try console.log(dataLayer[3]) and see if it has the appropriate data.



Hi Hamza,

Yes, I’ve checked, dataLayer[3] contains the desired data.

Console.log(dataLayer[3]); contains 4 objects - of which, one is the autopilot sessionId.

It’s value is identical in both the parent container, and the iframe.