awavi
awavi

Reputation: 847

How to install Facebook Pixel and track a conversion in an app using Cordova?

How do you set the Facebook Pixel using an app that is made on Cordova. I need to track conversions in the app so I can better target the ads made in Facebook Ads. Normally it will be easy to do this task in an HTML page by copy pasting it and executing a JavaScript command, or in an app by installing the Facebook SDK and running a command using JAVA, Swift or Objective-C. However Ionic opens a web view where the user is not connected to Facebook, so it does not track it. So what is the way to go?

Upvotes: 8

Views: 5217

Answers (2)

Alejandro Quintanar
Alejandro Quintanar

Reputation: 878

Add the Javascript from Facebook SDK Pixel into www/index.html (for permanent changes edit src/index.html)

<!-- Facebook Pixel Code -->
<script>
!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', 'XXXXXXXXX'); 
fbq('track', 'PageView');
</script>
<noscript>
 <img height="1" width="1" 
src="https://www.facebook.com/tr?id=XXXXXXX&ev=PageView
&noscript=1"/>
</noscript>
<!-- End Facebook Pixel Code -->

Upvotes: 1

SagarPPanchal
SagarPPanchal

Reputation: 10111

We can add code for web only in index file.

Here is the useful doc

https://developers.facebook.com/docs/ads-for-websites/pixel-events/v3.1

Upvotes: 0

Related Questions