Custom event to pass datalayer data to contact property
Hi,
I am trying to pass dataLayer data to existing contacts using custom javascript event on HUbspot .
I checked script on my local editor its working fine logically however I didn't see anything working on hubspot side.
I wondering what I am doing wrong here .
$(window).load(function() {
var path = window.location.pathname;
var dest = path.indexOf("booking");
var property;
var email;
if(email === 'undefined' || email === '') {
email = $("#hubemail").val();
}
if (dest !== -1) {
var x = dataLayer;
var data;
for(var i = 0 ; i < x.length ;i++) {
var y = (x[i]).pageType;
if (y === 'Booking Process') {
data = x[i];
}
}
property = Object.values(data);
At first glance, I don't see any issues with that code, except perhaps where you're setting the email? It seems like that if statement should always succeed, but is it necessary since you're defining email on the previous line? I'm wondering if the value for email isn't being set correctly for some reason, leading to the whole identify call to fail. Can you try replacing the if statement with something like this instead?
var email = $("#hubemail").val();
If that doesn't work, could you give me a link to a page with this script so that I can do some testing? It's tough to say exactly what's wrong without looking at a live example.