Vijay Samuel's Blog

Push Notifications on DrupalGap

Posted on: January 12, 2015

With Push Notification contribution that is available, implementing push notifications was very simple and straightforward. A big thanks to the contributor.

  • To get push notifications working on Android, one needs to set up Google Cloud Messaging. Google has this well documented and the steps can be found here.
  • Once GCM has been set up, goto your Drupal website and install push_notifications and drupalgap_mobile_notifications plugins. Enable them after installation. Once you have enabled the plugins, goto the permissions of push_notifications and adjust the permissions of creating and removing device tokens as per your application needs. In my case, I wanted tokens to be created even for anonymous users so I had granted permissions for the same and had made the required changes in the drupalgap push_notifications module. Also place the GCM_SENDER_ID that was generated while setting up GCM in the variable defined in push_notifications.js right at the top.
  • After that, goto Administration -> Structure -> Services -> Drupalgap and enable the push notifications checkbox to make the REST endpoint live.
  • Goto Configuration -> Push Notifications -> Configuration to setup the push notifications module. In the bottom provide the API key that was generated in your GCM developer console and save the configuration.
  • Now we’re all set in the Drupal end to send notifications. Setting up the Drupalgap end is very straight forward. Download the push_notifications module and place it in the apps/modules/custom/push_notifications directory.
  • Add an entry to the settings.js to register the custom module.
  • Once this is done, launch the app to make sure that the device token gets registered with the Drupal push_notifications module. It can be verified by going to Configuration -> Push Notifications -> Overview which shows the number of device tokens registered per platform.
  • When you’ve verified that there are registered tokens, click on the Send Push tab to compose a Push message and send it across.

Hope this helps. Happy pushing! Cheers! 🙂


25 Responses to "Push Notifications on DrupalGap"

Hi – Thank you for the instructions – you mention ” made the required changes in the drupalgap push_notifications module.” what changes were those? Thanks – just learning drupalgap, appreciate the help

ok – i see it at line 9 if (Drupal.user.uid == 0) { … so I’m just commenting out the if else bits… in any case, I’m downloading the app, but not seeing it register a token after running.. any thoughts?

This is what I did, I commented out the part you ve mentioned above because my app doesnt require users to register:

// When the device is connected, if the user is anonymous we don’t want to register a token
//if (Drupal.user.uid == 0) {
//} else {

also I have commented out the push_notifications_services_postprocess method.


not sure where I’m making my mistake here… any thoughts on debugging? thanks again for your help – greatly appreciated 🙂

I just try to load the app and see if the corresponding token got registered with drupal gap push notifications module.

Thanks for writing up this documentation. It would be great if you mentioned here (and maybe in the drupalgap module README) that the GCM_SENDER_ID must be set manually in push_notifications.js.

I ve updated the needful here.

How do you do this for iOS?

Im experimenting with it. I will update the blog once Im done.


Thanks so much for all your work on this. I really appreciate it. Not sure if this helps at all but I found this tutorial – Let me know if it was helpful.

I ve been looking at the same. Yet to completely set up my drupal for APNS though. 🙂


Is the GCM_SENDER_ID the same as the Project ID that I created here Mine has numbers and letters in it should there be quotes around the GCM_SENDER_ID in the push_notifications.js at the top when defining the variable? Like so:
var GCM_SENDER_ID = “gcm_sender_id/project_id”;

yes use the project_id as the sender id and do var GCM_SENDER_ID=”project_id”

Also in your drupal push_notifications plugin config you will need to add the API KEY that was generated in the Credentials section of your developer console.

Sorry for the delayed reply.

vjsamuel, when debug or run the app have this error: “pushNotification undefined”.

this line it’s the problem:
pushNotification = window.plugins.push_notifications; because window.plugins is null or undefined

Please help me !!!
Sorry for my english, i’m Argentinian men.

Please install the push notifications plugin using the following command:

cordova plugin add


I am getting the same error. I have the plugin installed. I can see it when I do cordova plugin ls on the command line. It shows ‘com.phonegap.plugins.PushPlugin’. Any other thoughts why it might be causing issues.

I still happening the same, window.plugins is undefined.
I need to copy the PushNotification.js in a particular place?

Thank for your time samuel !!!

Did you do this manually following these ( instructions or just through the CLI?

FYI: You also need to go into your Drupal website permissions and under “Push Notifications” you need to allow the users permission to “Register Device Token” and “Remove Device Token.” I am still stuck with this issue but it was something else that i forgot. Also when I look at my project page I am showing no requests. Any Thoughts?

Joe can you fix problem of undefined window.plugins variable?
Please can someone tell me what can i do !!!

thanks all !!!

I am still stuck with that piece as well. Sorry. It was just another thing I noticed that we needed to do.

Not sure if you guys know about the drupalgap IRC chat room. You can go to (or what ever IRC you want) and put in any User Name you want and for Channel Put #drupal-drupalgap. I am in there pretty much all day as username JoeRobertsPhotog. Hit me up there so it is easier to chat about it. To ask me a question in IRC just start typing my name and hit the tab key. Then ask away and it will alert me that you asked me a question 😉

Any ideas about how to debug this?

I have followed your instructions exactly, and I’m not getting any errors but when I check /admin/config/services/push_notifications the Android device I am testing with never gets registered.

Push notification service on the server is working because if I manually POST a token/type to then the device ID is added to the server.

However, when I log in with my Android device (or even when I just open the app, after commenting out the code to check for authentication as per comment No. 2), the token is not added. I tried adding some drupalgap_alert() to my code but that function can apparently only print text, not print out the values of variables.

hi vjsamuel,

would you mind to enlighten me, step by step about what to do and where to place the requirements in drupalgap installer

I realy stuck in here, almost 4 days now, about this drupalgap push_notifications to working (sent token to my site)

thank you

Is it possible to push custom automatic push notifications based on a field inside the users profile?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

My Timeline

January 2015
« Sep    

I, Me and Myself

My Blog Stats

  • 7,123 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 4 other followers

%d bloggers like this: