Attach Event to Contact with JavaScript Events API?


#1

When using the HTTP Events API (https://developers.hubspot.com/docs/methods/enterprise_events/http_api), it looks like it's possible to specify an email which attaches the event to a contact. Is it possible to do this with the JavaScript Events API (https://developers.hubspot.com/docs/methods/tracking_code_api/javascript_events_api)?

I tried doing the following, but it didn't work.

  _hsq.push(["trackEvent", {
      id: "User has visited your website",
      value: 0,
      email: 'drichied@njmonthly.com'
  }]);

#2

Hi @dwebrich,

When paired with the Identify a visitor method, the JavaScript event you create can be associated with a contact via email.

For example:

    function getParameterByName(name) {
        var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
        return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
    }

    var _hsq = window._hsq = window._hsq || [];
    _hsq.push(["identify",{
        email: getParameterByName("email")
    }]);
    _hsq.push(["trackEvent", {
        id: "User has visited your website",
        value: 0
    }]);

#4