Attach Event to Contact with JavaScript Events API?

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'
 }]);

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

@IsaacTakushi

Is there generic API version or in python for sending events to Hubspot ?

Thanks,

Sanjay

Hi, @sanjaydojo.

There is an HTTP Events API. Is that what you’re looking for?

Hi @IsaacTakushi ,

Thank you for your great help.

Is it possible to associate it with the property other than email?

Thanks,

Sanjay

Hey, @sanjaydojo.

You can pass other contact property values by appending &{property}={value} to the request URL, but you do need email to identify the contact.

Per the documentation, you can use an external ID in the id parameter, but you will need an email value in at least one call to associate this external ID with a contact. Once that happens, you can use only the id value going forward.

Hi @IsaacTakushi,

Thank you again for your great help.

Is there a way of preventing the pixel on Website from sending custom events to Hubspot?

Thanks,

Sanjay

Hi, @sanjaydojo.

It’s not possible to stop event details from being passed to HubSpot after this method is called, so you’ll have to implement JavaScript logic around the trackEvent function to only fire it when you want it.