javascript - How to implement Facebook conversion tracking onclick or when there's no separate 'Thank you' page -


Trying to implement Facebook conversion tracking in the Facebook tab, you can see this page here that once the form is submitted After doing the problem is not a separate page. Can I make a part of the javascript run, but click the submit button, I think it has been injected into the head of the HTML doctor. I found this answer to run JavaScript from a link or click - can I call on a tracking / conversion code from a different JS Doctor?

Any help would be greatly appreciated - thanks!

"I have to agree to the comments given above, that you can not call a file, but you can load a JS file like this, I'm sure if it answers your question , But it can help ... Oh and I have used a link instead of a button in my example ...

  & lt; a href = 'linkhref.html' Id = 'mylink' & gt; click me & lt; / a & gt; script type = "text / javascript" & gt; var myLink = document.getElementById ('mylink'); myLink.o Nclick = function () {var script = document.createElement ("script"); script.type = "text / javascript"; script.src = "public / scripts / filename.js. "; Document.getElementsByTagName (" head ") [0] .appendChild (script); return;}    

I tried to use Nicole's solution but the conversion was never verified.

However I immediately described a technique that uses the URL & lt; noscript & gt; & lt; img src = "..." />

Place an element on your page such as:

  
< / Pre>

Then your conversion Announce these CSS rules for your own tracking code, background-image to and & lt; noscript & gt; URLs.

  #fb_pixel {display: none;} .fb_conversion {background-image: url ('https://www.facebook.com/offsite_event.php?id=33333333333&value=0¤cy=USD');} < / Code>  

When you want to get tracking (like on AJAX form submissions), you can change the fb_conversion class to & lt; Div & gt; using javascript. For example, with jQuery:

  $ ("# fb_pixel"). AddClass ("fb_conversion");   

This will load the image to the browser, thus keeping track of your conversion.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -