# Attach Event to Contact with JavaScript Events API?

**URL:** <https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635>\
**Category:** APIs & Integrations\
**Tags:** events\
**Created:** [September 4, 2018, 7:07pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635 "2018-09-04T19:07:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 4, 2018, 7:07pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/1 "2018-09-04T19:07:57Z")

</div>

When using the HTTP Events API ([https://developers.hubspot.com/docs/methods/enterprise\_events/http\_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](https://developers.hubspot.com/docs/methods/tracking_code_api/javascript_events_api))?

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

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

```

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [September 5, 2018, 5:59pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/2 "2018-09-05T17:59:13Z")

</div>

Hi [@dwebrich](https://community.hubspot.com/u/dwebrich),

When paired with the [Identify a visitor](https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor) method, the [JavaScript event](https://developers.hubspot.com/docs/methods/tracking_code_api/javascript_events_api) you create can be associated with a contact via email.

For example:

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

```

---

<div class="post-metadata">

**Author:** ![sanjaydojo](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sanjaydojo/32/100500_2.png) [@sanjaydojo](https://community.hubspot.com/u/sanjaydojo)\
**Post date:** [July 25, 2019, 2:00am UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/3 "2019-07-25T02:00:55Z")

</div>

@IsaacTakushi

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

Thanks,

Sanjay

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [July 25, 2019, 2:34pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/4 "2019-07-25T14:34:53Z")

</div>

Hi, @sanjaydojo.

There is an [HTTP Events API](https://developers.hubspot.com/docs/methods/enterprise_events/http_api). Is that what you’re looking for?

---

<div class="post-metadata">

**Author:** ![sanjaydojo](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sanjaydojo/32/100500_2.png) [@sanjaydojo](https://community.hubspot.com/u/sanjaydojo)\
**Post date:** [July 25, 2019, 6:33pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/5 "2019-07-25T18:33:06Z")

</div>

Hi @IsaacTakushi ,

Thank you for your great help.

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

Thanks,

Sanjay

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [July 25, 2019, 10:07pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/6 "2019-07-25T22:07:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sanjaydojo](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sanjaydojo/32/100500_2.png) [@sanjaydojo](https://community.hubspot.com/u/sanjaydojo)\
**Post date:** [July 31, 2019, 6:36pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/7 "2019-07-31T18:36:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [July 31, 2019, 9:59pm UTC](https://community.hubspot.com/t/attach-event-to-contact-with-javascript-events-api/11635/8 "2019-07-31T21:59:17Z")

</div>

Hi, @sanjaydojo.

It’s not possible to stop event details from being passed to HubSpot after [this method](https://developers.hubspot.com/docs/methods/tracking_code_api/javascript_events_api) is called, so you’ll have to implement JavaScript logic around the `trackEvent` function to only fire it when you want it.
