Has anyone in here successfully set up a FB pixel to fire from inside of Cake and also been able to pass the revenue back dynamically?
My pixel appears to be set up correctly, and it's firing leads back no problem...but revenue is only being passed when I hard code the amount. If I use the #price # variable, it breaks the whole thing.
Any ideas?
Can you show the exact code you have placed? Just replace your pixel ID with XXX.
Chances are its injecting #price # in some way that breaks the JS syntax. There will be ways around it with basic JS if that's the case but its hard to advise without seeing the exact existing situation.
Ok, so the best thing you could do here is actually go through the conversion process yourself and inspect the code that gets injected on the thank you page. This will be the easiest way to technically debug this.
You could also look at the Facebook event debugger to see if any hints come through.
Aside from that, the likely problem is #price # is simply breaking syntax -- not getting replaced, or getting replaced but mangling things. Cake is great.
You could add some JS here to set price to some variable before the FB code, then use that variable insted.
E.g.
<script>
var cake_revenue = #price#;
!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(argum ents)};
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', 'XXXXXXXXX');
fbq('track', 'Lead', {content_name: 'XXXXXXXXX', content_category: 'XXXXXXXXX'});
fbq('trackCustom', 'XXXXXXXXX');
fbq('track', 'Lead-Revenue', {value: cake_revenue, currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
Can you suggest a good site or method for verifying my JS syntax?
In case you can't tell, I'm not a developer lol.
You can use something like http://beautifytools.com/javascript-validator.php
In the case above, you can paste the entire code but remove the <script> tags and all the <noscript> part.
A few things to keep in mind:
- The #price # is going to cause errors, so just replace it with 1 when validating. The JS checker can't understand that "#price #" is a token that would be replaced by a real value before the JS processes the code
- The FB JS (starting with !function(f,b,e,v,n,t,s)) is also going to cause issues, since the JS checker can't check and understand this code that is pulling in JS from an external source
So, the actual code you would put in the JS validator is:
var cake_revenue = 1;
fbq('init', 'XXXXXXXXX');
fbq('track', 'Lead', {content_name: 'XXXXXXXXX', content_category: 'XXXXXXXXX'});
fbq('trackCustom', 'XXXXXXXXX');
fbq('track', 'Lead-Revenue', {value: cake_revenue, currency: 'USD'});
var cake_revenue = 1;
fbq('init', 'XXXXXXXXX');
fbq('track', 'Lead', {
content_name: 'XXXXXXXXX',
content_category: 'XXXXXXXXX'
});
fbq('trackCustom', 'XXXXXXXXX');
fbq('track', 'Lead-Revenue', {
value: cake_revenue,
currency: 'USD'
});