APIs & Integrations

mikehutchinson
参加者

Trying to pull Email into GTM DataLayer

解決

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 いいね!
1件の承認済みベストアンサー
WendyGoh
解決策
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

解決

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 いいね!
7件の返信
WendyGoh
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

解決

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 いいね!
mikehutchinson
参加者

Trying to pull Email into GTM DataLayer

解決

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

 

{{ contact.email }}

{{ contact.geographic_territory_hubspot_combined }}

 

0 いいね!
WendyGoh
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

解決

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 いいね!
mikehutchinson
参加者

Trying to pull Email into GTM DataLayer

解決

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 いいね!
WendyGoh
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

解決

Hey @mikehutchinson,

 

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

0 いいね!
mikehutchinson
参加者

Trying to pull Email into GTM DataLayer

解決

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

0 いいね!
WendyGoh
解決策
HubSpot Employee
HubSpot Employee

Trying to pull Email into GTM DataLayer

解決

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 いいね!