In order to transform first time visitors into fans it is good practice to show them a different welcome page with e.g. an incentive to click "Like". Drupal for FB only makes the distinction to show different pages for users who have already authorized the app or not.
Is there a possibility to administer different pages in D4FB:
1. a welcome tab page for non fans
2. another welcome page for fans
(In general D4FB already makes a great job (@Dave Cohen: Thx!!!))
Comments
Comment #1
Dave Cohen commentedThere is a similar notion for canvas pages, showing a different page depending on whether user has authorized the app.
Agreed this is a worthwhile addition. In the older FBML tabs, it used an FBML tag to display content to fans. I'm actually not sure what the mechanism is for new iframe tabs.
Comment #2
Störtebeker commented@Dave: I googled a "cheat code" to determine whether a visitor is already a fan or not (it worked hard-coded in my page.tpl.php):
/**
* Reveal / Fan-Gate / Like-Gate Facebook iframe tab:
*/
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}
}
/**
* Tasks to implement:
* replace the following
*
* echo "This content is for Fans only!"
*
* with a 1st custom entry form field for content types (e.g. story) to insert the iframe URL to call (fan tab)
*
* replace the following
* echo "Please click on the Like button to view this tab!"
* with a 2nd custom entry form field for content types (e.g. story) to insert the alternative iframe URL to call (non-fan tab)
*/
Is that of any help?
:-)
Comment #3
Dave Cohen commentedThat's of help. Eventually fb_tab.module may could offer configuration for this. Until then, you could use code like the following (although it should not be in page.tpl.php).
Comment #4
Störtebeker commented@Dave:
thx a lot!
Unfortunately being more of a "code adaptor" than anything else (when it comes to PHP/modules) should I use your code above together with the "FB fan cheat code" in one custom module?
Something like this as my custom module "fb_fantab":
<?php
function fb_fantab_perm() {
return array('access fb_fantab', 'create fb_fantab','administer fb_fantab' );
} // function fb_fantab_perm()
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}
}
extract(fb_vars()); // $fb, $fb_app
$sr = $fb->getSignedRequest();
if ($sr->page->liked) {
// User does like the current page.
}
else {
// User does not like, or is not logged in.
}
But where would I specify the 2 different URLs for a) non-fans and b) fans?
(...sorry for asking yout to explain me how Drupal modules work...:-)
Comment #5
chrisjlee commentedCouldn't you just redirect users in the code? This is probably not the best practice?
Comment #6
Dave Cohen commentedMIght work, you'd have to try. Tabs are iframes and passed a signed request in the new facebook api. However after the drupal_goto(), the signed request data will be lost.
In the older FBML tab, it would definitely not work. In the iframes, I'm not sure but I suspect there will be undesirable side effects, in some cases.
Comment #7
Störtebeker commentedIt worked with my little custom module with the following code (node 17 & 18 for fans and non-fans):
<?php
function fb_fantab_menu() {
$items['facebook/fb-reveal'] = array(
'title' => 'Hi!',
'page callback' => 'fb_reveal',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function fb_reveal() {
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
$node = node_load(17);
$output = node_view($node);
} else {
$node = node_load(18);
$output = node_view($node);
}
}
return $output;
}
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
Comment #8
krembo commented@ Dave Cohen
I'd like to use this code via your version -
How can I implement it for every node? Meaning if "liked" work as usual, if not "liked" show different node in the same iframe? Thanks.
@Störtebeker
Tried your version somehow it didn't work for me...
Only changes I made was name of the module in hook_menu,
path in items[], and numbers of nodes...
Comment #9
Dave Cohen commentedI don't think you want to do that for every node, because we're talking about a page tab here. Usually a page tab will display only one page (links should take the user to another web site or to canvas pages). Can you explain why you want to do that?
I'd like fb_tab.module to be configurable so you don't need to work with that code yourself. But until that day, you can put that snippet either in a node body (make sure the input format is PHP) or a custom menu hook in your own module.
Comment #10
krembo commentedThanks for a quick answer. The reason for question is that we put several pages at specific page at facebook. Every page is a separate tab, so I need it for several nodes(pages).
Comment #11
chrisjlee commented@krembo isn't there a limit to 10 tabs per page on facebook?
Comment #12
Störtebeker commented@krembo
did you "Rebuild menu" in Devel (module)?
Comment #13
Störtebeker commented@chrisjlee
Then www.facebook.com/cocacola wouldn't look like it does... but maybe with over 26 mio. fans you get extra tabs permission from FB?
:-)
Comment #14
krembo commented@Störtebeker We used your code, and it worked perfectly, thanks.
Comment #15
Störtebeker commentedGreat! Happy facebookin'!
Comment #16
jaimeah commentedHow about making this a parameter in Views? Just like the one that appears for Friends of the user.
Comment #17
chrisjlee commented@Störtebeke With money and a budget like $KO you can do almost anything you want :-)
Thanks for the example by the way.
Comment #18
dwb17 commentedThank you Störtebeke, your solution on #7 worked great.
Just to clarify, that the menu item path 'facebook/fb-reveal' should be set as the Path under Facebook profile tabs, replacing the recommended value of fb_tab/view
Comment #19
Sms2luv commentedWhere should I update the code