title: How to make a Facebook pixel fire on a rails controller action
body: <p>I have a ruby on rails app. I followed the facebook instructions to add a pixel. </p>
  
  <p>However, to track a conversion, facebook requires you to put the page in the conversion that will appear when the desired result is reached. i.e if I want to show a customer has signed up, I would put the page you go to after signing up as the success object to track.</p>
  
  <p>My issue is that in my application when a customer signs up, there is no landing page. The app takes the user back to the homepage. It shows a message on the homepage so I am trying to see if there is a way to track conversions from controller actions instead of actual pages.</p>
  
  <p>The actions I need to count don't have pages, they are controller actions. Is there a gem, documentation, or a best practice on how to do this that anyone is aware of?</p>
  
  <p>Here is the pixel that goes into the layouts file...</p>
  
  <pre><code>&lt;!-- Facebook Pixel Code --&gt;
        &lt;script&gt;
        !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
        n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
        n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
        t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
        document,'script','https://connect.facebook.net/en_US/fbevents.js');
        fbq('init', '18027724*****', {
        em: 'insert_email_variable,'
        });
        fbq('track', 'PageView');
        &lt;/script&gt;
        &lt;noscript&gt;&lt;img height="1" width="1" style="display:none"
        src="https://www.facebook.com/tr?id=180277241*****&amp;ev=PageView&amp;noscript=1"
        /&gt;&lt;/noscript&gt;
    &lt;!-- DO NOT MODIFY --&gt;
  &lt;!-- End Facebook Pixel Code --&gt;
  </code></pre>
  
  <p>However I need it to fire here in the controller...</p>
  
  <pre><code>def create
      @reportapproval = current_user.reportapprovals.create(authorization_params)
        if @reportapproval.valid?
          if @reportapproval.manager_paying_report == true
            flash[:notice] = "Please make payment before proceeding"
            redirect_to new_managers_charge_path(id: @reportapproval.id)
          else
            flash[:notice] = "You have requested a report from #{@reportapproval.tenant_last_name}."
            redirect_to managers_dashboard_path
            @reportapproval.save
          end
       &lt;----PIXEL FIRES HERE IN THE PROCESS -----&gt;
        else
          flash[:error] = @reportapproval.errors.full_messages.to_sentence
          redirect_to managers_dashboard_path
        end
  end
  </code></pre>