Track use of send dialog - facebook

I'm using the Fb.ui send dialog to hopefully allow users to connect to other users. I want to know if there is anyway to track the use of this dialog box so I can tell if users are taking advantages of it.

You could track the usage of the send dialog by putting in some simple tracking at 3 different stages
User clicks on your 'send message' button to open the dialog
User opens the dialog but clicks cancel
User opens the dialog and then sends a message
Here's some sample code demoing how you can add a callback to the send dialog and determine whether or not the user actually sent a message. Although please note that there seems to be some issues with this at the moment and I'm not totally sure that the send dialog supports callbacks fully yet.
FB.ui({
method: 'send',
name: 'Google',
link: 'http://www.google.com',
},
function(response) {
if (response) {
// user sent the message
} else {
// user clicked cancel
}
});

In the callback function, trigger an ajax call to a php script that will recored the call in the database.
This way you'll know how many time the dialog was used, and by which user.

Related

Why Google Pay doesn't work from iPhone Safary after an ajax request?

I try to add a Googla Pay button on a website. I follow the Google Pay implementation tutorial (https://developers.google.com/pay/api/web/guides/tutorial).
There is a code:
var paymentsClient = getGooglePaymentsClient();
paymentsClient.isReadyToPay(getGoogleIsReadyToPayRequest())
.then(function(response) {
//...
})
.catch(function(err) {
//...
});
I need to get some data from my server side before I call the above code so I do the http post request. Within success hanlder of my post request I call the above code. It works fine in my Android browser and my laptop browser. But it doesn't work from Safari. I get the "Unexpected developer error please try again later" error. If I call it without ajax request it works in Safari as well. Could someone suggest the solution?
Thanks for including the jsfiddle.
The reason that it's not working is because Google Pay tries to open a popup window when you call loadPaymentData in Safari. When a new window is triggered as the result of a click event (user initiated action), the popup window opens as expected. When it is triggered by a non-user initiated action, Google Pay gets loaded in the same window which ends up causing it to fail.
It looks like when you make an ajax request in the click handler and then call loadPaymentData, Safari considers it a non-user initiated action.
Check out the following example in Safari:
const ajaxButton = document.getElementById('ajax');
const nojaxButton = document.getElementById('nojax');
ajaxButton.addEventListener('click', event => {
$.get('/echo/json/', () => {
window.open('about:blank');
});
});
nojaxButton.addEventListener('click', event => {
window.open('about:blank');
});
I would recommend avoiding making any http calls on the button click event before loadPaymentData. If you can fetch the data before the button is clicked, then do so.
Out of interest, what kind of data are you fetching?

Facebook UI, how to check if a user can send facebook message to another user

I want to follow up this question. I use FB.ui to send link and got exactly the same error for some users. Is there anyway to check it and decide whether to display the ui to the user ?
API Error Code: 100
API Error Description: Invalid parameter
Error Message: Viewer cannot message specified recipients.
<a href='#' onClick="
FB.ui({
method: 'send',
link: 'http://www.xxxxxxxxxxx.com',
to: ###########,
});
">Send a message</a>
Even when I use the url send method, some user does not work. For example:
Error User : https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=100000104626944
Normal User: https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=1311251197
(this is the share link example taken from https://developers.facebook.com/docs/reference/dialogs/send/)
bug reported to facebook: https://developers.facebook.com/bugs/538638372825668
Edit: in fact, everyone should be reachable through messages now. It's only there are new "filtering preferences". I guess this can_message field is now useless because it should always return true. I think it is going to be deprecated in a while.
In the user FQL table, you have a field that must verify what you need:
can_message (boolean): whether the user can send a message to another user
Source: https://developers.facebook.com/docs/reference/fql/user
select can_message from user where uid=USER_ID
USER_ID being the person that your app user want to send a message to.
You can use the FB api;
I use something like:
FB.api('/me/permissions', function (response)
{
//check contents of response for required permissions here
fb_publish_perm = response.data[0]['publish_stream'] ? response.data[0]['publish_stream'] : false;
if (fb_publish_perm)
{
// it permissions exist
}
else
{
// permissions dont exist launch the ui to request.
}
});
Please treat the above as psedo code, as it came straight off the top of my head!

How get the notification ID when user enter in you app

I'm using the Facebook requestdialog to show my friend list and invite,this in a Facebook Web APP, using this:
function sendRequestViaMultiFriendSelector() {
FB.ui(
{
method: 'apprequests',
message: 'Selección de amigos a los que invitar a KugaBar'
}, requestCallback);
}
function requestCallback(data) {
console.log(data);
}
It works (ok).
But I need to identify the user when enter in my APP, you see the requestCallback data and see a "request", but when the users click on the notification and enter in the APP
I don't know how identify the request to detect if the user is accessing by the notification.
EDIT: OK I found it.
The param in the GET vars are "request_ids", but one problem appear, this param only come if the user previously have accepted the permissions, if the user clicks on the notification, and accept the permissions, hitting enter: this param doesn't exist, if the user enter again (not need to accept nothing) this param exists in the URL.
Are there any method to get this param in the first time the user enter?
Thanks
When the user first clicks on a request, you should get the request_id from the URL and store it in a cookie. When the user has completed logging in, check if the cookie exists and then update your record accordingly.
Notifications and Requests are NOT the same thing on Facebook. In your case you're talking about Requests. Request ids are passed to the app as a GET parameter 'request_ids' which is a comma separated list.
To be able to access this parameter after login dialog, you want to save your GET parameters from the original launch URL before redirecting to the OAuth dialog and pass them around in the redirect URL. This way you solved this problem for all of your future GET parameters.
If you're using PHP, the function you're looking for is http_build_query. I'd highly discourage from using a cookie to store one-time and easily accessible URL parameters.

Facebook application: FB events work only for first time

I'm using the following code to subscribe to fb login and logout events.
FB.Event.subscribe('auth.logout', function(response) {
RefreshPageOnFBStatusChange(response);
});
FB.Event.subscribe('auth.login', function(response) {
RefreshPageOnFBStatusChange(response);
});
function RefreshPageOnFBStatusChange(response)
{
alert(response.status);
}
I want to redirect users to different pages when they are logged in or logged out. The function I'm using here gets called only during the actual page load, and never after that. I have a fb-like, fb-share and live stream plugin on a page. When I login and logout of live stream, nothing happens. Help!
Please modify your question and provide all FB-related code.
This may answer you question:
Facebook FB.Event.subscribe event does not fire:(
For User Status you can use if(FB._userStatus == "connected"){} to check user is login or not And for Logout & login you can use following simple code
FB.logout(function(response) { window.location = redriect_uri;
});
It seems like these events don't fire when you use the live chat plugin because it has its own way of handling the login and logout. What I had to do to solve this problem was to set a timeout of 5 seconds and call a javascript function that did a FB.GetLoginStatus, and based on what it was I would refresh the page. Not the best way of doing it, but I was left with no choice.

"Request Dialog" requestCallback when clicking Cancel or Close button

I am new into Facebook application development and also newbie about JavaScript and PHP programming.
I currently developing a Facebook application but currently stuck with Request Dialog window.
When the Request Dialog appears, I choose friends I want and then click "Send Requests", the requestCallback(response) are executed and friends who getting requests are notified as expected. But, If I click "Cancel" or the blue-colored close button, the requestCallback(response) is also executed but selected friends are not getting notified about the request.
Here is my code:
function requestCallback(response)
{
//console.log(response);
location.href='step2.php';
}
So, whether I click "Cancel" or close button, the script above are still executed (moving to page step2.php I specify.)
What I want is when the user clicking cancel button or close modal window button, the page stay at the same page.
Anyone know how to solve this problem?
Thanks!
You can just check what's inside the Facebook response object, because it won't be the same if requests have been sent or not !
Something like :
function requestCallback(response)
{
if(response && response.request_ids) {
// Here, requests have been sent, facebook gives you the ids of all requests
//console.log(response);
location.href='step2.php';
} else {
// No requests sent, you can do what you want (like...nothing, and stay on the page).
}
}
Or if you are using the new structure (Request 2.0 Efficient):
function requestCallback(response)
{
if(response && response.request) {
// Here, requests have been sent, facebook gives you the request and the array of recipients
//console.log(response);
location.href='step2.php';
} else {
// No requests sent, you can do what you want (like...nothing, and stay on the page).
}
}
Look at the structure of the response object to make your condition. The callback is fired even when you hit close in order to have the possibility to notice when your user quits the dialog. It's up to you to verify if he sent requests, and act like you want ! :)
Also, something important :
Facebook updated their request system a few weeks ago, making available "Requests 2.0" in your apps settings. It's turned off by default, but if you activate it, the structure of the response object when sending requests to people will change. So you'd have to update your condition in the callback !
Everything is explained here :
http://developers.facebook.com/blog/post/569/