# Creating custom behavioural event for button click

**URL:** <https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636>\
**Category:** APIs & Integrations\
**Tags:** events, forms\
**Created:** [October 3, 2024, 4:43pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636 "2024-10-03T16:43:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrafey](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@Mrafey](https://community.hubspot.com/u/Mrafey)\
**Post date:** [October 3, 2024, 4:43pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/1 "2024-10-03T16:43:57Z")

</div>

Hello!  
I am trying to create a CBE for a button on our prefernces page. Essentially the CBE is created for the “Resubscribe” button.  
The issue I am facing is my CBE not being able to store the button click. When the button is clicked it loads up a thank you page not giving enough time for the \_hsq.push method to push the data onto HS.

This is what I have so far for the CBE:

```lia-code-sample
 const resubPrefBtn = document.getElementById('globalresub2');

 if (resubPrefBtn) {
 resubPrefBtn.addEventListener('click', () => {
 console.log('clicked...');
 _hsq.push([
 'trackCustomBehavioralEvent',
 {
 name: 'pe20052921_resubscribe_email_preferences_button_click',
 properties: {
 // give each property a value so we know what they mean
 },
 },
 ]);
 });
 }

```

What can I do to ensure that the execution of the CBE happens before the thank you page is shown?  
Thank you!

---

<div class="post-metadata">

**Author:** ![MrJustinGivens](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mrjustingivens/32/49537_2.png) [@MrJustinGivens](https://community.hubspot.com/u/MrJustinGivens)\
**Post date:** [October 3, 2024, 5:11pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/2 "2024-10-03T17:11:22Z")

</div>

@Mrafey,

You would need to use the preventDefault to “block” the event from completing, then continue it after the hsq push.  
See the [preventDefault MDN](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault).

---

<div class="post-metadata">

**Author:** ![Mrafey](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@Mrafey](https://community.hubspot.com/u/Mrafey)\
**Post date:** [October 3, 2024, 6:07pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/3 "2024-10-03T18:07:40Z")

</div>

Hello @MrJustinGivens !  
How can I continue after the hsq push function is executed?

---

<div class="post-metadata">

**Author:** ![MrJustinGivens](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mrjustingivens/32/49537_2.png) [@MrJustinGivens](https://community.hubspot.com/u/MrJustinGivens)\
**Post date:** [October 3, 2024, 9:06pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/4 "2024-10-03T21:06:17Z")

</div>

Depend on the button.

If the button has an href attribute then grab the event.target.href and then use window.location = event.target.href;

---

<div class="post-metadata">

**Author:** ![Mrafey](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@Mrafey](https://community.hubspot.com/u/Mrafey)\
**Post date:** [October 3, 2024, 9:13pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/5 "2024-10-03T21:13:28Z")

</div>

Unfortunetly it does not have an href attribute. It actually is a input type of “submit”

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/0/c0ae7aa65f7d8605bf0bd8a782cb23695370cbb7.png)

---

<div class="post-metadata">

**Author:** ![MrJustinGivens](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mrjustingivens/32/49537_2.png) [@MrJustinGivens](https://community.hubspot.com/u/MrJustinGivens)\
**Post date:** [October 4, 2024, 2:56pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/6 "2024-10-04T14:56:51Z")

</div>

Then you just need to trigger the .submit() event for the form.

---

<div class="post-metadata">

**Author:** ![Mrafey](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@Mrafey](https://community.hubspot.com/u/Mrafey)\
**Post date:** [December 2, 2024, 3:58pm UTC](https://community.hubspot.com/t/creating-custom-behavioural-event-for-button-click/117636/7 "2024-12-02T15:58:31Z")

</div>

Hello @MrJustinGivens  
I figured out that essentially you cannot create CBE’s for preference pages. The HS team told me those pages dont support it.
