Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 722
awavi Avatar asked Jun 15 '16 15:06

awavi


People also ask

How do I set my Facebook Pixels to track conversions?

In your Facebook Ads Manager, click on the menu button in the top-left corner and click All Tools at the bottom of the menu. Then under the Assets column, click Pixels. This opens the pixels dashboard. Under Conversion Tracking Pixel (Old), click the Create Conversion button.

What is pixel and conversion tracking?

A conversion pixel is a piece of code that is provided to advertisers to place on a website landing page. It allows brands to track and report on the actions of users who visit their page after viewing or clicking on an ad.


1 Answers

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 -->
like image 144
Alejandro Quintanar Avatar answered Sep 28 '22 06:09

Alejandro Quintanar