Creating custom behavioural event for button click
SOLVE
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:
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?