digitalwithyou / craft-facebook-conversion

Craft CMS plugin to send web events directly to Facebook
https://digitalwithyou.com/en/plugins/facebook-conversion/getting-started
Other
0 stars 3 forks source link

Call Track inside javascript event #34

Closed dellanesta closed 1 year ago

dellanesta commented 1 year ago

hi @Diewy , how can I track an event that should be called inside a javascript event like Click, scroll,...

Diewy commented 1 year ago

Hi,

It works just the same as you would on any other project implementing the Facebook / Meta Pixel.

Just make sure you don't send the same event on both Client and Server side. E.g. The Purchase Event only on the server side. Or, create a unique Event ID and send it with both Client and Server events.

Kind regards

dellanesta commented 1 year ago

hi @Diewy but i try to implement a custom event inside a click event and send the Server event immediatly and the client event correctly after the click...

{% js%}
document.getElementById("testbutton").addEventListener("click", function() {
  //Client event      
  fbq('track', 'clickEvent', {  content_name: 'Click'},{eventID:'123456789' });

 //Server event
 {{ fbEvent('clickEvent',{},{'content_name': 'Click'},'123456789') }}
})
{% endjs %}