troubleshooting Question

Load tracking pixel and JS on form submit

Avatar of daniel_spiri
daniel_spiri asked on
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") {


Open in new window

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';
  var fpw = document.createElement('script');
  fpw.async = true;
  fpw.src = '//';
  var ref = document.getElementsByTagName('script')[0];
  ref.parentNode.insertBefore(fpw, ref);
<noscript><img height="1" width="1" alt="" style="display:none" src="" /></noscript>

Open in new window

How can I fire this code inside the thank_you conditional?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
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