0

I am trying to make it so that whenever anybody clicks on a button with a specific ID this jQuery script fires the Facebook Pixel's 'Add to Cart' event. Here's the code I have so far:

// add to cart
$('#offerbutton').click(function(e){
    fbq('track', 'AddToCart');
});

How can I make this script globally accessible so I don't have to go through my Wordpress website page my page to paste the code in manually?

Thanks!

3
  • 1
    Do you have access to the template/theme files? Commented Apr 29, 2020 at 22:17
  • @disinfor I do, yes Commented Apr 29, 2020 at 22:54
  • You only want to track add to cart for one item, or for many? How will you determine which items you want to track? Commented Apr 30, 2020 at 9:54

1 Answer 1

1

I'd probably suggest just using a plugin to do it, as it allows you to easily add/remove it, completely decoupled from any theme you're using. You can always just add the js in the header/footer, but this way is very low-overhead and is dead easy.

https://www.ostraining.com/blog/wordpress/custom-js/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.