APIs & Integrations

dwebrich
Member

Attach Event to Contact with JavaScript Events API?

SOLVE

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'
  }]);
0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Attach Event to Contact with JavaScript Events API?

SOLVE

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

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
7 Replies 7
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Attach Event to Contact with JavaScript Events API?

SOLVE

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

Isaac Takushi

Associate Certification Manager
0 Upvotes
sanjaydojo
Contributor

Attach Event to Contact with JavaScript Events API?

SOLVE

@IsaacTakushi 

 

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

 

Thanks,

Sanjay

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Attach Event to Contact with JavaScript Events API?

SOLVE

Hi, @sanjaydojo.

 

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

Isaac Takushi

Associate Certification Manager
sanjaydojo
Contributor

Attach Event to Contact with JavaScript Events API?

SOLVE

Hi @IsaacTakushi ,

 

Thank you for your great help.

 

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

 

Thanks,

Sanjay

 

 

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Attach Event to Contact with JavaScript Events API?

SOLVE

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.

Isaac Takushi

Associate Certification Manager
0 Upvotes
sanjaydojo
Contributor

Attach Event to Contact with JavaScript Events API?

SOLVE

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

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Attach Event to Contact with JavaScript Events API?

SOLVE

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.

Isaac Takushi

Associate Certification Manager
0 Upvotes