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?
Asked
Active
Viewed 4,960 times
8

Vahid Farahmandian
- 6,081
- 7
- 42
- 62

awavi
- 837
- 3
- 11
- 23
2 Answers
1
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 -->

Alejandro Quintanar
- 858
- 12
- 23
-
1But how will Facebook know the user comes from a Facebook ad? – awavi Dec 15 '16 at 15:50
-
Replace the XXXXXX with your Pixel code generated by your Ad that is a unique id. – Alejandro Quintanar Dec 15 '16 at 22:01
-
2Ok. But Facebook should know who actually the user is to optimize the campaign right?. Also where do I dynamically get the pixel code generated by the Ad from. – awavi Dec 16 '16 at 13:59
-
2how will be urls tracked while opening different pages on app ? @AlejandroQH – SagarPPanchal Aug 13 '18 at 06:02
-
The www/index.html is replaced every build, it should be on src/index.html – Juan Angel Oct 27 '20 at 19:13
0
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

SagarPPanchal
- 9,839
- 6
- 34
- 62