railslove/rack-tracker

View on GitHub
lib/rack/tracker/facebook/template/facebook.erb

Summary

Maintainability
Test Coverage
<script type="text/javascript">
  (function() {
    var _fbq = window._fbq || (window._fbq = []);
    if (!_fbq.loaded) {
      var fbds = document.createElement('script');
      fbds.async = true;
      fbds.src = '//connect.facebook.net/en_US/fbds.js';
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(fbds, s);
      _fbq.loaded = true;
    }
  })();
  window._fbq = window._fbq || [];

</script>

<% if options[:custom_audience] %>
<script type="text/javascript">
window._fbq.push(["addPixelId", "<%= options[:custom_audience] %>"]);
window._fbq.push(["track", "PixelInitialized", {}]);
</script>

<noscript>
  <img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=<%= options[:custom_audience] %>&amp;ev=PixelInitialized">
</noscript>
<% end %>

<% if events.any? %>
<script type="text/javascript">
<% events.each do |event| %>
window._fbq.push(<%= event.write %>);
<% end %>
</script>

<noscript>
  <% events.each do |event| %>
  <img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=<%= event.id %>&amp;value=<%= event.value %>&amp;currency=<%= event.currency %>">
  <% end %>
</noscript>
<% end %>