Connect Facebook Pixel to BigCommerce Cookie Consent Form - facebook

I wonder if someone may be able to help.
Recently, we realised we had to get consent for using the Facebook pixel on our site. I have looked at the developer information on Facebook on how to do this, and I can stop the pixel from sending data to Facebook...
What I need help with is allowing the data to be sent if the visitor accepts the cookies in the BigCommerce cookie bar (say for either the analytics or Targeting; Advertising category) ... the code I have so far in script manager to stop sending the data is this (to note I removed our FB pixel ID and replaced with 0's for this example) I tried to connect it to the BigCommerce cookie banner but failed (I was trying to use tag manager but this failed also):
<!-- 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('consent', 'revoke');
fbq('init', '000000000000000');
fbq('track', 'PageView');
</script>
<!-- End Facebook Pixel Code -->
As you can see I added the fbq('consent', 'revoke'); to the code
More info from Facebook here regarding the codes to use: https://developers.facebook.com/docs/facebook-pixel/implementation/gdpr/
Thank you for any help you can offer with this 😃 our site is https://www.wolftucker.co.uk

The BigCommerce consent banner sets a cookie (bc_consent) with details on what the user has consented to. You can use that to decide if you need to do the revoke command.
Alternatively you can add your code using the script manager and set the script category to "Targeting; Advertising". This will remove the script if consent is not given.

Related

Match Facebook pixel pageviews with Offline Event set?

I would like to use offline conversion data to build a custom audience that I can match against visitors to my site.
I am currently trying to do this by:
Using the Facebook pixel (fbevents.js) to track users, passing extern_id with our unique user ID during the init call and then tracking pageviews like so:
fbq('init', '1234567890', {extern_id: UNIQUE_USER_ID});
fbq('track', 'PageView');
Later uploading offline event data with the associated extern_id of people that have made purchases
But Facebook is giving me a 0% record match rate for the offline event set (I have ~150,000 pageviews and a couple thousand purchases, if that matters). Has anybody succeeded in matching only on extern_id, or does Facebook require more user data?
I spent hours on this and from what I can gather, the offline events only work in conjunction with Facebook ads. So, your uploaded data is matched only against ads in your account and not the Facebook pixel.
You should be passing external_id instead of extern_id in the fbq init event.
fbq('init', '1234567890', {extern_id: UNIQUE_USER_ID}); // Incorrect
fbq('init', '1234567890', {external_id: UNIQUE_USER_ID}); // Correct
You can check the doc here:
https://developers.facebook.com/docs/facebook-pixel/advanced/advanced-matching

Cannot find/advertise to custom audiences created with Facebook's Tag API

I've followed Facebook's Tag API guide to create "Custom Audiences" by using "Custom Events": https://developers.facebook.com/docs/ads-for-websites/tag-api#remarketing
The final code reads:
!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','//connect.facebook.net/en_US/fbevents.js');
fbq('init', 1234567890); //Of course, I'm using my own Pixel ID ;)
fbq('track', 'PageView');
fbq('trackCustom', 'Facebook Test Audience');
The above code seems to work just fine and the custom event is being triggered (GET requests are sent and cookies "datr" + "fr" + "lu" set).
However, I cannot find "Facebook Test Audience" in the Ads Manager in order to advertise to it.
Does it take time to finally show up?
Any other ideas?
It turned out that it simply takes some time and page views for the event to show up in Facebook Ad Manager - patience is a virtue.
And voilà, I'm able now to create a new "Custom Audience", which is based upon a "Custom Combination" of my website traffic, and select the "Event" that has been triggered by my code (named "Facebook Test Audience"):
Issue "solved"!

Logout methods doesn't work

I integrated FB regisration into a WP site. Test site is here: http://teszt.avea.hu/blog/
I can manage Registration user account merge/creation and Login well but I can't loguot FB users from FB so FB.getLoginStatus always remains 'connected'.
I tried the following methods:
PHP SDK: $facebook->getLogoutUrl(); generates a well formed URL (https, token, etc.). It redirects well, but FB.getLoginStatus remains connected
JS SDK: FB.logout(function(){ window.location = 'http://teszt.avea.hu/';}); doesn't log out the user.
Cookie solution: $facebook->destroySession(); setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', '.avea.hu'); also doesn't log out the user. I can create othes cookies, but can't replace FB cookie.
I run out os ideas. Do you have any idea why can't manage logout? Is it a permission problem?
Ok I found the problem. I Used both PHP and JS SDK on same website. This cause different token and malfunctions.
thanks

Is there any easy way to "provide" more permissions for my facebook connect app, using sfFacebookConnect

From what I see now, it seems that the plugin provides me only authenticated facebook user's email address.I need the first name, last name, and other data.
With my plugin (few month ago) the facebook_connect setting in app.yml did not work.
So, I've put this for the fb login button :
<img src="/images/fb_dark_medium_short.gif" alt="Facebook Connect" style="width:100px"/>
You can add in the scope GET parameter your permissions.
Hope this can help
by setting:
facebook_connect:
user_permissions: []
you can request some of those permission: http://developers.facebook.com/docs/authentication/permissions/

Facebook Oauth Logout

I have an application that integrates with Facebook using Oauth 2.
I can authorize with FB and query their REST and Graph APIs perfectly well, but when I authorize an active browser session is created with FB. I can then log-out of my application just fine, but the session with FB persists, so if anyone else uses the browser they will see the previous users FB account (unless the previous user manually logs out of FB also).
The steps I take to authorize are:
Call [LINK: graph.facebook.com/oauth/authorize?client_id...]
This step opens a Facebook login/connect window if the user's browser doesn't already have an active FB session. Once they log-in to facebook they redirect to my site with a code I can exchange for an oauth token.
Call [LINK: graph.facebook.com/oauth/access_token?client_id..] with the code from (1)
Now I have an Oauth Token, and the user's browser is logged into my site, and into FB.
I call a bunch of APIs to do stuff: i.e. [LINK: graph.facebook.com/me?access_token=..]
Lets say my user wants to log out of my site. The FB terms and conditions demand that I perform Single Sign Off, so when the user logs out of my site, they also are logged out of Facebook. There are arguments that this is a bit daft, but I'm happy to comply if there is any way of actually achieving that.
I have seen suggestions that:
A. I use the Javascript API to logout: FB.Connect.logout(). Well I tried using that, but it didn't work, and I'm not sure exactly how it could, as I don't use the Javascript API in any way on my site. The session isn't maintained or created by the Javascript API so I'm not sure how it's supposed to expire it either.
B. Use [LINK: facebook.com/logout.php]. This was suggested by an admin in the Facebook forums some time ago. The example given related to the old way of getting FB sessions (non-oauth) so I don't think I can apply it in my case.
C. Use the old REST api expireSession or revokeAuthorization. I tried both of these and while they do expire the Oauth token they don't invalidate the session that the browser is currently using so it has no effect, the user is not logged out of Facebook.
I'm really at a bit of a loose end, the Facebook documentation is patchy, ambiguous and pretty poor. The support on the forums is non-existant, at the moment I can't even log in to the facebook forum, and aside from that, their own FB Connect integration doesn't even work on the forum itself. Doesn't inspire much confidence.
Ta for any help you can offer.
Derek
ps. Had to change HTTPS to LINK, not enough karma to post links which is probably fair enough.
I was having the same problem. I also login using oauth (I am using RubyOnRails), but for logout, I do it with JavaScript using a link like this:
Logout
This first calls the onclick function and performs a logout on facebook, and then the normal /logout function of my site is called.
Though I would prefer a serverside solution as well, but at least it does what I want, it logs me out on both sites.
I am also quite new to the Facebook integration stuff and played around the first time with it, but my general feeling is that the documentation is pretty spread all over the place with lots of outdated stuff.
This works as of now - and is documented on facebook's site # http://developers.facebook.com/docs/authentication/. Not sure how recently it was added to the documentation, pretty sure it wasn't there when I checked Feb-2012
You can programmatically log the user our of Facebook by redirecting
the user to
https://www.facebook.com/logout.php?next=YOUR_REDIRECT_URL&access_token=USER_ACCESS_TOKEN
This solution no longer works with FaceBook's current API (seems it was unintended to begin with)
http://m.facebook.com/logout.php?confirm=1&next=http://yoursitename.com;
Try to give this link on you signout link or button where "yoursitename.com"
is where u want to redirect back after signout may be ur home page.
It works..
I can programmatically log user out Facebook by redirecting user to
https://www.facebook.com/logout.php?next=YOUR_REDIRECT_URL&access_token=USER_ACCESS_TOKEN
The URL supplied in the next parameter must be a URL with the same base domain as your application as defined in your app's settings.
More details: https://developers.facebook.com/docs/authentication
You can do this with the access_token:
$access_array = split("\|", $access_token);
$session_key = $access_array[1];
You can use that $session key in the PHP SDK to generate a functional logout URL.
$logoutUrl = $facebook->getLogoutUrl(array('next' => $logoutUrl, 'session_key' => $session_key));
This ends the browser's facebook session.
With PHP I'm doing:
logout.
if(isset($_GET['action']) && $_GET['action'] === 'logout'){
$facebook->destroySession();
header(WHERE YOU WANT TO REDIRECT TO);
exit();
}
Works and is nice and easy am just trying to find a logout button graphic now!
Here's an alternative to the accepted answer that works in the current (2.12) version of the API.
Logout
<script>
FB.init({
appId: '{your-app-id}',
cookie: true,
xfbml: true,
version: 'v2.12'
});
function logoutFromFacebookAndRedirect(redirectUrl) {
FB.getLoginStatus(function (response) {
if (response.status == 'connected')
FB.logout(function (response) {
window.location.href = redirectUrl;
});
else
window.location.href = redirectUrl;
});
}
</script>
the mobile solution suggested by Sumit works perfectly for AS3 Air:
html.location = "http://m.facebook.com/logout.php?confirm=1&next=http://yoursitename.com"
For Python developers that want to log user out straight from the backend
At the moment I'm writing this, the trick with m.facebook.com no longer works (at least for me) and user is redirected to the mobile FB login page which obviously is not good for UX.
Fortunately, FB PHP SDK has a semi-documented solution (in case the link doesn't lead to getLogoutUrl() function, just search look for it on that page). This is also mentioned in at least one other on StackOverflow: Facebook php SDK getLogoutUrl() problem.
BTW I've just noticed that Zach Greenberg got it right in this question, but I'm adding my answer as a summary for Python developers.
A note for Christoph's answer:
Facebook Oauth Logout
The logout function requires a callback function to be specified and will fail without
it, at least on Firefox. Chrome works without the callback.
FB.logout(function(response) {});
#Christoph: just adding someting . i dont think so this is a correct way.to logout at both places at the same time.(Logout).
Just add id to the anchor tag . <a id='fbLogOut' href="/logout" onclick="FB.logout();">Logout</a>
$(document).ready(function(){
$('#fbLogOut').click(function(e){
e.preventDefault();
FB.logout(function(response) {
// user is now logged out
var url = $(this).attr('href');
window.location= url;
});
});});
Update: This solution works and just a call to 'FB.logout()' doesn't work because browser wants a user interaction to actually call this function, so that it knows - it is a user not a script.
Logout
it's simple just type : $facebook->setSession(null); for logout