Solved

How can I send custom data on click event from code?

  • 21 April 2023
  • 1 reply
  • 79 views

Badge

I am trying to send some custom data and track it when a user clicks a button, but it doesn’t update regularly or doesn’t accept an object as a value to a property. Any suggestions?

Here is a sample of what I am trying to send:
 

window.heap.track("Show Results Click", {

      usedFilters: {      

         has_done_brand_deals: false

        has_instagram: true

        has_link_in_bio: false

        has_merch: false

        has_patreon: false

        has_tiktok: false

        has_twitch: false

        has_youtube: false

     }

 });

 

icon

Best answer by ALabs I Bhupender 21 April 2023, 18:15

View original

1 reply

Userlevel 3
Badge +1

Hi,

It is not recommended to send Heap properties in JSON format, you won’t be able to use it in Heap and also the code would give you errors.

My suggestion for your use case would be to apply one of the following two methods:

  • Send one property “Filter Used” with the comma separated string of the filters that have been used (having value as true). e.g. “has_instagram, has_tiktok”
    window.heap.track("Show Results Click", {"usedFilters": "has_instagram, has_tiktok"});
  • Send each of these properties as separate properties instead of sending them under one property as JSON object. e.g. {“has_intagram”: True, “has_tiktok”: False …...}
    window.heap.track("Show Results Click", {'has_done_brand_deals': 'false', 'has_instagram': 'true', 'has_link_in_bio': 'false', 'has_merch': 'false', 'has_patreon': 'false', 'has_tiktok': 'false', 'has_twitch': 'false', 'has_youtube': 'false'});

Hope this helps!😊

Reply