i have a situation i have been thinking for a while and cant seem to find logic to solve it. hope you can.
i have a series of buttons that i would like to track, an example of one is this:
when a button is clicked a function is called, sending some strings and an object with a series of attributes. different buttons have different sets of attributes.
$(".btn").on('click', function(ev){
trackFunction("Purchase","apply_promo", { product_code: "product1", last_page: "home", refer: "facebook", promo: "12345" });
});
The track function will then receive this and send it to my analytics software but i need it to be sent in this format
dataToSend = { event_type : eventType, event_value: eventValue, data };
where data is each and every attribute from the object the button is sending. in that example it woud be something like this
dataToSend = { event_type : eventType, event_value: eventValue, data.product_code, data.last_page, data.refer, data.promo };`
here is my tracking function :
function trackFunction(eventType, eventValue, data ) {
dataToSend = { event_type : eventType, event_value: eventValue, data };
analyze(dataToSend);
return true;
}
the problem here is that not every button is sending the same attributes inside the object so i cant hardcode the output.
hope i made myself clear. and thank you so much.