4

To track the efficacy of a Facebook ad campaign, my users want to insert a Conversion Pixel to some (but NOT all) contribution confirmation pages. What's an effective way to do this?

3

You could override the Thank-you smarty template. Copy the one from templates/CRM/Contribute/Form/Contribution/ThankYou.tpl. Then you could do something like this:

{if $contributionPageID == 20}

    <script type="text/javascript">
    {literal}

      function doFacebookStuff(){
      };

    {/literal}
    </script>
{/if}
  • 1
    Thanks Nicholai! I upvoted this because it got me on the right track. I wanted to add that a better approach would be a .extra.tpl file (more maintainable on upgrade) or an extension (easier to share). I did the latter, see my answer. – Jon G - Megaphone Tech Apr 21 '15 at 15:58
3

I ended up taking Nicholai's idea, but instead implemented it as an extension for better maintainability across upgrades - and for sharing. Folks can see the extension here: https://github.com/PalanteJon/civicrm-facebook-conversion-pixel

  • You may get more value from an extra tpl file, which would let you use the $amount variable to get actual conversion amount (vs. always reporting back to FB as $0). – Nicholai Apr 21 '15 at 16:42
  • Thank you for creating the extension Jon G - in your .php code you may want to check for example if 'ga.js' exists and in that case, you need to insert the pixel image only, not the FB javascript function. If Google Analytics or DoubleClick are installed on a site the FB code isn't 'smart' enough to deal with that, you need to just use the pixel – Lesley Evensen Jul 8 '15 at 13:41
  • Thanks for creating this. How do I make sure it only applies to specific contribution pages? – Christia Oct 31 '17 at 20:34
  • @Christia You'd have to customize the extension, or have someone else do it for you. I wrote this up very quickly for a client and shared it - I never intended to make it more generally usable. I can give a quote to make this more functional if you like! Find me on chat.civicrm.org: Username is junglebird. – Jon G - Megaphone Tech Oct 31 '17 at 20:48
1

In Drupal, if you use an alias for the page, you could check for that alias in a preprocess_html hook and insert some FB Conversion Pixel javascript if it's the right alias.

Example:

function MYTHEME_preprocess_html(&$vars) {
  $path = drupal_get_path_alias();
    if ($path == 'special-fb-contribpage-alias') {
    drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/js/facebook-conversion-pixel.js', 'file');
  }
}
  • Thanks for the tip - but I need to add this to the confirmation page, not the contribution page. I don't think there's a way to use an alias for the confirmation page? – Jon G - Megaphone Tech Apr 7 '15 at 15:23
  • Ah, got it. It wouldn't be ideal, but can you wedge it into the 'thank you' header or footer for that particular page? – Laryn - CEDC.org Apr 7 '15 at 15:27
  • I think that Facebook gives you Javascript to insert - I don't think I can put JS into the header/footer. I hope not! But this gives me some good ideas, thank you. – Jon G - Megaphone Tech Apr 7 '15 at 15:33
  • I think they also give a <noscript> option (an image), but as I said, not ideal. Curious to see what you come up with. :) – Laryn - CEDC.org Apr 7 '15 at 16:21
  • I'd be interested to know what your solution was/is, Jon G, thanks – Lesley Evensen Jul 6 '15 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.