Example 2: Send purchase event when a button is clicked
You can set up the purchase event in a few ways so it triggers when someone clicks a "Purchase" button. One way is to add an ID to the "Purchase" button and then place the event code in an event listener. In the below example, the event is only sent when someone clicks a button with the ID purchase.
Sample code