troubleshooting Question

Load tracking pixel and JS on form submit

Avatar of daniel_spiri
daniel_spiri asked on
JavaScriptHTMLAJAXAnalytics
7 Comments1 Solution1552 ViewsLast Modified:
Hello Experts,

I have a form that on submit redirects to the same page but with the added #thank_you in the url.

Then I have this JS that checks if the form was submitted, and shows the thank you text:

var currentValue = window.location.hash.substr(1);
$(document).ready(function() {

  if(currentValue == "thank_you") {
    $(".takskrev").addClass("visible");
	$(".form").addClass("hidden");

}

This works fine, but what I need to do next is add tracking pixel to the thank_you.

This is the code I have to add:
<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = 'xxxxxx';
fb_param.value = '0.00';
fb_param.currency = 'currency';
(function(){
  var fpw = document.createElement('script');
  fpw.async = true;
  fpw.src = '//connect.facebook.net/en_US/fp.js';
  var ref = document.getElementsByTagName('script')[0];
  ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=xxxx" /></noscript>

How can I fire this code inside the thank_you conditional?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros