APIs & Integrations

mikehutchinson
Participante

Trying to pull Email into GTM DataLayer

resolver

I need to get a user's email address into the DataLayer when they load the website, so that, depending on what they engage with, I can use the Hubl API to push them into the proper automation (and I am doing this because I could not find a way to directly add a person into automation with a command from the executed from the DataLayer).  It feels like I am missing a piece of code in this, but I am not sure where.

 

 

	<script>
  dataLayer = [];
</script>
	
<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/12345678.js"></script>
<!-- End of HubSpot Embed Code -->	
	
	

<script>
  var dataLayer = [{
    email: "{{ contact.email }}",
    hsgeo: "{{ contact.geographic_territory_hubspot_combined }}",
  }]
</script>
	<!-- Google Tag Manager -->

 

 

0 Me gusta
1 Soluciones aceptada
WendyGoh
Solución
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

resolver

Hey @mikehutchinson,

 

This page: https://sopheon.staging.wpengine.com/ looks like an external page and in this case, it looks like you're pulling contact email and geogrpahic details via the personalized token: {{ contact.email }} and {{ contact.geographic_territory_hubspot_combined }}. Currently, it is not possible to use personalized toke on external page and hence this is likely why you're not seeing the value populated on the page.

Ver la solución en mensaje original publicado

0 Me gusta
7 Respuestas 7
WendyGoh
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

resolver

Hey @mikehutchinson,

 

Digging further into this, it looks like the recommended method to put data in the dataLayer is something like this:

 

<script>
window.dataLayer.push({
 'formLocation': 'footer',
 'event': 'new_subscriber'
 });
</script>

Referencing this article: GTM Guide: dataLayer.push with examples - Analytics Mania

 

Based on your code, it looks like you're missing out the .push and it is also reocmmended to use the "window" prefix (window.dataLayer.push).

 

Could you try and see if this works?

0 Me gusta
mikehutchinson
Participante

Trying to pull Email into GTM DataLayer

resolver

Same thing, it still just shows the values as follows:

 

{{ contact.email }}

{{ contact.geographic_territory_hubspot_combined }}

 

0 Me gusta
WendyGoh
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

resolver

Hey @mikehutchinson,

 

Could you share with me the HubSpot page in question?

 

I'd like to dig into this deeper on how you're setting the contact token. 

0 Me gusta
mikehutchinson
Participante

Trying to pull Email into GTM DataLayer

resolver

I am not pulling this from a HubSpot page, I am trying to pull it from my home page which should also be covered by the HubSpot code and cookie

0 Me gusta
WendyGoh
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

resolver

Hey @mikehutchinson,

 

Thank you for the clarification. Could you share with me the page url in question? 

0 Me gusta
mikehutchinson
Participante

Trying to pull Email into GTM DataLayer

resolver

Wendy,  I currently am doing my testing here:  https://sopheon.staging.wpengine.com/

0 Me gusta
WendyGoh
Solución
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

resolver

Hey @mikehutchinson,

 

This page: https://sopheon.staging.wpengine.com/ looks like an external page and in this case, it looks like you're pulling contact email and geogrpahic details via the personalized token: {{ contact.email }} and {{ contact.geographic_territory_hubspot_combined }}. Currently, it is not possible to use personalized toke on external page and hence this is likely why you're not seeing the value populated on the page.

0 Me gusta