javascript - Add FB pixel event code into button - Squarespace -


i new squarespace. client wants track page views this, have injected base pixel code header of pages , worked perfect,

but wants track , if user click on buy button on this page

i have no idea how inject facebook pixel code button in squarespace, idea or reference highly appreciated . thanks

it sounds want add "event code" either:

  • a) page user sees after clicking button, or
  • b) button itself.

if you're going prior option (a), you'd want make sure page upon user lands in fact indicate event you're tracking , users not arrive page other purpose. why lean towards latter option (b).

you can read more adding event code here, , here, in summary:

events actions happen on website, either result of facebook ads (paid) or organic reach (unpaid). event code lets track actions , leverage them in advertising.

there 2 types of events can send:

  • standard events. 9 events we're able track , optimize ads without additional actions...
  • custom events. actions important business, can’t use tracking , optimization without additional action...

...

enter image description here

if consider these buttons "add cart" type-of-action, you'd use addtocart event. so, use javascript similar following:

<script>     (function() {         var btns = document.getelementsbyclassname("sqs-block-button-element");         var i, i;          (i=0, i=btns.length; i<i; i++) {             btns[i].addeventlistener("click", function() {                 fbq("track", "addtocart");             });         }     })(); </script> 

you inject code using per-page code injection or via site-wide code injection. recommend prior, otherwise buttons on site execute fbq event code, undesirable.

regardless of whether use site-wide or per-page injection, may want better target buttons using more specific selector. example, use queryselectorall , target href attribute. however, if use per-page injection, code supplied should work; apply every button on page.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -