PushBots' official module for Phonegap/Cordova
cordova plugin add pushbots-cordova-plugin --save- Intialize Pushbots in deviceReady section:
Firebase credentials:https://www.pushbots.help/en/articles/498201-the-google-part-firebase-credentials
window.plugins.PushbotsPlugin.initialize("5f4bb916f2e7634ba83f1b93",{"android":{"sender_id":"SENDER_ID","fcm_app_id":"FCM_APP_ID","web_api_key":"WEB_API_KEY","project_id":"PROJECT_ID"}});// Only with First time registrationwindow.plugins.PushbotsPlugin.on("registered",function(token){console.log("Registration Id:"+token);});//Get user registrationId/token and userId on PushBots, with evey launch of the app even launching with notificationwindow.plugins.PushbotsPlugin.on("user:ids",function(data){console.log("user:ids"+JSON.stringify(data));});- Methods to use it:
window.plugins.PushbotsPlugin.setAlias("Test");window.plugins.PushbotsPlugin.removeAlias();//Add or remove Single tagwindow.plugins.PushbotsPlugin.tag("tag1");window.plugins.PushbotsPlugin.untag("tag1");//Add or remove array of tagswindow.plugins.PushbotsPlugin.setTags(["tag1"]);window.plugins.PushbotsPlugin.removeTags(["tag1"]);window.plugins.PushbotsPlugin.debug(true);//Track eventwindow.plugins.PushbotsPlugin.trackEvent("added_to_cart");//ShareLocation with promptingwindow.plugins.PushbotsPlugin.shareLocationPrompt(true);//Sharelocation without promptingwindow.plugins.PushbotsPlugin.shareLocation(true);//Set log level with alertwindow.plugins.PushbotsPlugin.setLogLevelWithUI({"logLevel":3,"showAlert":true});//set log level without alertwindow.plugins.PushbotsPlugin.setLogLevel(3);//unsubscribe user from receiving notificationswindow.plugins.PushbotsPlugin.toggleNotifications(false);//iOS only//Reset Badgewindow.plugins.PushbotsPlugin.resetBadge();//Set badgewindow.plugins.PushbotsPlugin.setBadge(10);//Increment badge countwindow.plugins.PushbotsPlugin.incrementBadgeCountBy(1);//Decrement badge countwindow.plugins.PushbotsPlugin.decrementBadgeCountBy(10);- To handle Notification events:
// Should be called once app receive the notification [foreground/background]window.plugins.PushbotsPlugin.on("notification:received",function(data){console.log("received:"+JSON.stringify(data));//iOS: [foreground/background]console.log("notification received from:"+data.cordova_source);//Silent notifications Only [iOS only]//Send CompletionHandler signal with PushBots notification Idwindow.plugins.PushbotsPlugin.done(data.pb_n_id);});window.plugins.PushbotsPlugin.on("notification:clicked",function(data){// var userToken = data.token; // var userId = data.userId;console.log("clicked:"+JSON.stringify(data));});window.plugins.PushbotsPlugin.setName("name");window.plugins.PushbotsPlugin.setFirstName("first name");window.plugins.PushbotsPlugin.setLastName("last name");window.plugins.PushbotsPlugin.setEmail("email");window.plugins.PushbotsPlugin.setGender("M");window.plugins.PushbotsPlugin.setPhone("+2100");https://blog.phonegap.com/update-for-customers-using-phonegap-and-phonegap-build-cc701c77502c