Custom event to pass datalayer data to contact property


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);

addHUBSpotIdentity(email,'000005654914',property) ;

function addHUBSpotIdentity(emailAddress, eventName,dataValue) {
try {
var _hsq = window._hsq = window._hsq || [];
email: emailAddress,
tboatname: dataValue[1],
tbase: dataValue[10],
tdepartdate: dataValue[7],
tpaxtotal: dataValue[13],
tamount: dataValue[4],
tholidaytype: dataValue[11],


    _hsq.push(["trackEvent", {
        id: eventName,
        value: 20.00
} catch (e) {


Any suggestion is appreciated .


Hi @Pooja,

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.