I am trying to measure the latency between having a message exit Firebase Servers and being received on an Android app via the Firebase SDK. I have BigQuery integrated with my Firebase project, and have tried adding the following code:
// In the manifest:
<meta-data android:name= "delivery_metrics_exported_to_big_query_enabled"
android:value="true"/>
// In my Application object:
FirebaseMessaging.getInstance().setDeliveryMetricsExportToBigQuery(true);
The code seems to be exporting data to BigQuery. However, to calculate what I want I need timestamps for two different types of events associated to the same message id, "MESSAGE_ACCEPTED" and "MESSAGE_DELIVERED". Then, all I have to do is run a simple query that calculates the timestamp difference between those two.
My problem is: I can never seem to get the "MESSAGE_DELIVERED" variant for a given message id. I only ever get the "MESSAGE_ACCEPTED" side of the equation.
I am sending messages to the Android device via my own JavaScript app, and the request I make is like so:
app.get('/triggerAnt', function(req, res){
axios.post('https://fcm.googleapis.com/fcm/send', {
to:<TOKEN_FOR_DEVICE_GOES_HERE>,
notification:{
"title":"TESTNOTIFICATIONLATENCY",
"body":"TESTINGLATENCY"
},
fcm_options: {
analytics_label:<LABEL_HERE>
}
}, {headers: headers})
.then((response) => {
console.log(response.status);
}, (error) => {
console.log(error);
});
})
I would like to point out that the notification does effectively reach the device and I can open it too.
Is this delay on BigQuery's side or am I doing something wrong?
Thank you.
Google plus signin using cordova-plugin-googleplus in my ionic app is giving me an issue. After login, the success callback is not called.
window.plugins.googleplus.login(
{
'scopes': 'email profile',
'webClientId': '**********',
'offline': true,
},
function (obj) {
alert('login success');
//... user service called
},
function (msg) {
alert('error: ' + msg);
}
);
In the above code snippet, neither alerts are called. When I check the adb logcat logs I find that the login was success:
D/CordovaActivity( 1614): Incoming Result. Request code = 77552
D/CordovaInterfaceImpl( 1614): Sending activity result to plugin
I/GooglePlugin( 1614): In onActivityResult
I/GooglePlugin( 1614): One of our activities finished up
I/GooglePlugin( 1614): Handling SignIn Result
I/GooglePlugin( 1614): trying to get account information
W/CordovaPlugin( 1614): Attempted to send a second callback for
ID: *************
W/CordovaPlugin( 1614): Result was: {**** correct user info ****}
Also interestingly, the window.plugins.googleplus.trySilentLogin works fine.
I am using android physical device and also have facebook plugin among others.
Any pointers to solve this would be great.
I using this plugin, and just deleted
'webClientId': '**********',
'offline': true,
So the plugin is works.
I am using Cordova plugin to login with Google Plus on Android not receiving User data except email.
The success callback (second argument) only provinding email object.
function (obj) {
alert(JSON.stringify(obj)); // Only show email
},
It is not provideing following contents:-
obj.userId
obj.displayName
obj.imageUrl
obj.idToken
obj.oauthToken
obj.gender
obj.givenName
obj.middleName
obj.familyName
obj.birthday
obj.ageRangeMin
obj.ageRangeMax
I have read many articles but couldn't find out how it will show full detail.
I have also tried with scopes parameter.
{
'scopes': 'profile, email',
'offline': true,
},
I just had my first contacts with the ionic framework. I've worked with Phonegap and AngularJS before however, so it was not all that new to me.
I found out that there is this new feature to use Google Cloud Messaging push notifications in Ionic, through the Ionic Push feature (http://blog.ionic.io/announcing-ionic-push-alpha/).
Related lines of code from app.js
angular.module('starter', ['ionic','ionic.service.core', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
// enable push notifications
Ionic.io();
// enable users (http://docs.ionic.io/docs/user-quick-start)
// this will give you a fresh user or the previously saved 'current user'
var user = Ionic.User.current();
// if the user doesn't have an id, you'll need to give it one.
if (!user.id) {
user.id = Ionic.User.anonymousId();
// user.id = 'your-custom-user-id';
}
console.log('user-id:' + user.id);
//persist the user
user.save();
var push = new Ionic.Push({
"debug": true,
"onNotification": function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
"onRegister": function(data) {
console.log(data.token);
}
});
push.register(function(token) {
console.log("Device token:",token.token);
});
push.addTokenToUser(user);
console.log('token added to user');
});
})
Log from ionic serve
ionic $ 0 361081 log Ionic Core:, init
1 361083 log Ionic Core:, searching for cordova.js
2 361085 log Ionic Core:, attempting to mock plugins
3 361155 log user-id:1cc3d21c-b687-4988-b944-ad07b1a677c8
4 361158 log Ionic Push:, a token must be registered before you can add it to a user.
5 361159 log Ionic Push:, token is not a valid Android or iOS registration id. Cannot save to user.
6 361159 log token added to user
7 361160 log Ionic Push:, register
8 361160 error ReferenceError: PushNotification is not defined, http://localhost:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js, Line: 2
9 361526 log Ionic User:, saved user
Any input is welcome, I am also more than happy to provide more information if needed.
EDIT 10/05/2015:
found out that dev_push = false only works on physical devices, not in browser
I tried to add token to user before even registering the user
I'm having the same problem, seems not many answers online at the moment.
but even on real device, it won't save the token to user.
I just had to decide go live without push first, then use ionic deploy to follow up.
also I think you have to put this line
push.addTokenToUser(user);
inside the register callback according to this doc
http://docs.ionic.io/docs/push-usage
You also need to declare 'ionic.service.push' as a dependency in your angular module if you'd like to use it.
angular.module('starter', ['ionic','ionic.service.core', 'ionic.service.push'])
I have it like this and it works:
Ionic.io();
var user = Ionic.User.current();
if (!user.id) {
user.id = Ionic.User.anonymousId();
// save our newly created user
user.save();
}
var push = new Ionic.Push({});
push.register(function (token) {
console.log("Got Token:", token.token);
// now we have token, so add it to user
push.addTokenToUser(user);
// don't forget to save user to Ionic Platform with our new token
user.save();
});
// set this user as current, so we can acess him later
Ionic.User.current(user);
Did you use this
ionic config set dev_push true-if testing in emulator or laptop
ionic config set dev_pushfalse - if testing on the phone
ionic push --google-api-key Your API Key
ionic config set gcm_key Project Number
Your token is the registration id that is unique for a particular device. That is sent to you by android.
Your Phone (With the API Key)---------> to Google's GCM
Google GCM (recognises it's you via your Project number and API key) -----> Oh it's you let me make a note of it. (Save a token id in it's DB and send's one to you.)
You get a registration id unique for your device(will change if an app is uninstalled).
You call your server say hey it's me your user. Please Notify me if you get something.
Server obliges, says, okay dude, I got this. Saves the registration id with your details probably your username in it's DB.
Now from Server.
I need to inform my users about a great deal(or an accident or something).
Pull up all targeted registration Id's from DB(maybe on some condition)
registrationIds.push(regId) //in a loop
and sender.send(message, registration, function(err, result){
});
Send to Google. Google see's oh only these many people(not all maybe) from this API Key need a notification. no Problem I will notify them and you receive a notification, my dear friend.
As mentioned in the link , Adding token to the $ionicUser is done by doing , user.addPushToken(pushToken); .
For this to work you should first configure the app not to use developement pushes by ,
ionic config set dev_push true
After initialising Ionic.io and Ionic.push , load the user or create one with a new random id ,
Ionic.io();
var push = new Ionic.Push();
Ionic.User.load(localStorage.id).then(function (user) {
Ionic.User.current(user);
pushFactory.register(push, user);
}, function (error) {
/*the user with that id is not present , so create one with a random id and register the push */
});
The push factory is defined as below,
function pushFactory() {
return {
'register': function (push, user) {
push.register(function (pushToken) {
user.addPushToken(pushToken);
user.save().then(function (answer) {
console.log('user saved'+answer);
})
})
}
}
}
I'm using the plugin's registerDevice and unregisterDevice methods and looking at my app's control panel in pushwoosh. My app's preference defaults to accepting push notifications, so I register, that works and my subscriber count increments in pushwoosh control panel. It also fires a push-notification event where the event has the notification property as the guide shows, but it's set to null. This is confusing as I have not yet sent any push notifications from the control panel.
I then set my push preference to false and unregister the the device. It works because my subscriber count decrements in the control panel, but the fail callback is the one that fires, and the only argument it gets is the same push token string that the register success callback got. If I unregister again after that, still only the fail callback fires but this time the only argument is the empty string.
Am I doing something wrong with handling responses from the plugin?
The code I'm testing with:
(function() {
$document.on('push-notification', function(evt) {
var n = evt.originalEvent.notification;
console.log(n);
});
var pushPrefApply = function() {
app.pushPref(function(pushPref) {
console.log('pushPref', pushPref);
if (!pushPref) {
window.plugins.pushNotification.unregisterDevice(
function() {
console.log('unreg ok', arguments);
},
function() {
console.log('unreg fail', arguments);
}
);
return;
}
window.plugins.pushNotification.registerDevice(
{
projectid: '123456789012',
appid : 'F0000-BAAAA'
},
function(pushToken) {
console.log('reg ok', arguments);
},
function(status) {
console.log('reg fail', arguments);
}
);
});
};
//code for changing/initiating push preference goes here
})();
$document is not a typo, it's defined already. app.pushPref is the preference setting/fetching function. window.plugins.pushNotification.onDeviceReady has been done elsewhere on deviceready.
I'm hoping the pushwoosh devs will shed some light on this.
The problem has been fixed and SDK has been updated on Github:
https://github.com/shaders/push-notifications-sdk
and
https://github.com/shaders/phonegap-cordova-push-notifications
Also Android Phonegap sample now includes unregister function:
https://github.com/shaders/push-notifications-sdk/tree/master/SDK%20Sample%20Projects/Android-Phonegap