Skip to content

Instantly share code, notes, and snippets.

@ai2ik
Created December 28, 2018 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ai2ik/c607113a90a8f156b6c621197c0e85d6 to your computer and use it in GitHub Desktop.
Save ai2ik/c607113a90a8f156b6c621197c0e85d6 to your computer and use it in GitHub Desktop.
After you install the pixel track in-page actions, such as product purchases, by tying events to HTML elements such as buttons. For example:
<button onClick="fbq('track', 'Purchase');">Button Text</button>
Or you could create a function that pushes the event. The advantage is if you have multiple HTML elements, you can call a single function when someone clicks any of them; you don't have to define individual onClick element.
For example, to push the event:
<script>
function onClick() {
fbq('track', 'Purchase');
};
</script>
You can call this function to fire Purchase events from multiple HTML elements. For example:
<button onClick="onClick()">Buy Now</button>
<button onClick="onClick()">Buy as a Gift</button>
Note: Pixel Helper may show multiple pixel events firing from the same page. The Pixel Helper expects pages to fire only on load but by tying events to elements, such as a button, you are using an alternative solution that overturns the expected behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment