{"_id":"57c45e6519b0bb0e00ee1675","version":{"_id":"56cecbdc44c5700b0095c03d","project":"56cecbdb44c5700b0095c03a","__v":10,"createdAt":"2016-02-25T09:39:40.121Z","releaseDate":"2016-02-25T09:39:40.121Z","categories":["56cecbdc44c5700b0095c03e","56d1d2c05ad7ad0b00b7e809","56d1d2fa5ad7ad0b00b7e80a","56d369331660770b00081159","56d3693d1660770b0008115a","56e5361e7990160e002e3fbc","56e5362775eb791700a9c4d2","57a9030947f2f419009188d4","57b4705ee9e4c60e00f6f4c3","5828f5b04774ab0f005179a2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":0,"parentDoc":null,"project":"56cecbdb44c5700b0095c03a","githubsync":"","category":{"_id":"57b4705ee9e4c60e00f6f4c3","project":"56cecbdb44c5700b0095c03a","__v":0,"version":"56cecbdc44c5700b0095c03d","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-08-17T14:10:38.587Z","from_sync":false,"order":5,"slug":"web","title":"Website"},"user":"56cecbb2e50c9c1b008303eb","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-08-29T16:10:13.659Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Registration\"\n}\n[/block]\nWhen using the PushApps SDK, you can choose whether you would like to automatically register every website user to push notifications, or to do it on your time, maybe just on specific pages or after a specific user action.\nIf you choose the automatic way, the PushApps SDK will take care of all possible scenarios.\nIf you prefer to choose when to ask the user for the notifications permission, it will be best to check first, if the user's browser supports push notification.\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Check if browser supports push notification\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var browserSupport = PushApps.BrowserSupportsPushNotification();\\nconsole.log(\\\"Does this browser support push notifications? \\\" + browserSupport);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Get updated on push subscription changed\"\n}\n[/block]\n*The following subscription statuses are available:*\n* **none** - user was not offered to register to push notification or he ignored this offer (did not click nor on Accept neither on Decline)\n* **granted** - user has approved push notifications subscription\n* **denied** - user has denied push notifications subscription\n\n*For HTTPS sites:*\nOnce the user has granted the push notifications subscription, the page will reload, in order for this approval to take effect. This means that on every page load, you should check the push subscription. To do so, please call the following method, as a callback to our init function:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.GetPushSubscription(function (subscription) {\\n  console.log(\\\"user id: \\\" + subscription.device_id);\\n  console.log(\\\"push status: \\\" + subscription.status);\\n  switch (subscription.status) {\\n\\t\\t      case \\\"none\\\":\\n      \\t\\t  console.log(\\\"push notifications permiisions were not set, you should call PushApps.registerForPushNotification();\\\");\\n          case \\\"granted\\\":\\n          \\tconsole.log(\\\"push token: \\\" + subscription.push_token);\\n          case \\\"denied\\\":\\n\\t\\t      \\tconsole.log(\\\"push notifications were not allowed\\\");\\n  }\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nAlso, to be updated on every changed, you can also listen to the HTML event `pushappsregistrationchanged`. To achieve that, you can use the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"window.addEventListener(\\\"pushappsregistrationchanged\\\", function (event) {\\n    console.log(event.detail);\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n*For HTTP sites:*\nPlease use the `pushappsregistrationchanged` HTML event to listen to the subscription changes:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"window.addEventListener(\\\"pushappsregistrationchanged\\\", function (event) {\\n  var subscription = event.detail;\\n  console.log(\\\"user id: \\\" + subscription.device_id);\\n  console.log(\\\"push status: \\\" + subscription.status);\\n  if (subscription.status === \\\"granted\\\") {\\n    console.log(\\\"push token: \\\" + subscription.push_token);\\n  }\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"User Segmentation\"\n}\n[/block]\nUser segmentation enables you to send notifications to a specific audience. For example, if you have a news website, you can let your users specific content categories that interest them. So if one marked \"Sports\" you can tag it with this name, and later send a sport specific notification, just to those users who marked this category.\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Adding tags for a device\"\n}\n[/block]\nIn order to add tag for a device, add the following code at the relevant place:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.addTag(\\\"sports_fan\\\");\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Tags are case insensitive\",\n  \"body\": \"Please notice that tags should be lowercase only (but can contains numbers, signs or any other characters).\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Removing tags for a device\"\n}\n[/block]\nIn order to remove tag for a device, add the following code at the relevant place:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.removeTag(\\\"sports_fan\\\");\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Get tags for device\"\n}\n[/block]\nIn order to get all the tags, which are assigned to the current device, please use the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.getDeviceTags(function (tagsArray) {\\n\\tconsole.log(tagsArray);\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"advanced-features-1","type":"basic","title":"Advenced Features"}
[block:api-header] { "type": "basic", "title": "Registration" } [/block] When using the PushApps SDK, you can choose whether you would like to automatically register every website user to push notifications, or to do it on your time, maybe just on specific pages or after a specific user action. If you choose the automatic way, the PushApps SDK will take care of all possible scenarios. If you prefer to choose when to ask the user for the notifications permission, it will be best to check first, if the user's browser supports push notification. [block:api-header] { "type": "fn", "title": "Check if browser supports push notification" } [/block] [block:code] { "codes": [ { "code": "var browserSupport = PushApps.BrowserSupportsPushNotification();\nconsole.log(\"Does this browser support push notifications? \" + browserSupport);", "language": "javascript" } ] } [/block] [block:api-header] { "type": "fn", "title": "Get updated on push subscription changed" } [/block] *The following subscription statuses are available:* * **none** - user was not offered to register to push notification or he ignored this offer (did not click nor on Accept neither on Decline) * **granted** - user has approved push notifications subscription * **denied** - user has denied push notifications subscription *For HTTPS sites:* Once the user has granted the push notifications subscription, the page will reload, in order for this approval to take effect. This means that on every page load, you should check the push subscription. To do so, please call the following method, as a callback to our init function: [block:code] { "codes": [ { "code": "PushApps.GetPushSubscription(function (subscription) {\n console.log(\"user id: \" + subscription.device_id);\n console.log(\"push status: \" + subscription.status);\n switch (subscription.status) {\n\t\t case \"none\":\n \t\t console.log(\"push notifications permiisions were not set, you should call PushApps.registerForPushNotification();\");\n case \"granted\":\n \tconsole.log(\"push token: \" + subscription.push_token);\n case \"denied\":\n\t\t \tconsole.log(\"push notifications were not allowed\");\n }\n});", "language": "javascript" } ] } [/block] Also, to be updated on every changed, you can also listen to the HTML event `pushappsregistrationchanged`. To achieve that, you can use the following code: [block:code] { "codes": [ { "code": "window.addEventListener(\"pushappsregistrationchanged\", function (event) {\n console.log(event.detail);\n});", "language": "javascript" } ] } [/block] *For HTTP sites:* Please use the `pushappsregistrationchanged` HTML event to listen to the subscription changes: [block:code] { "codes": [ { "code": "window.addEventListener(\"pushappsregistrationchanged\", function (event) {\n var subscription = event.detail;\n console.log(\"user id: \" + subscription.device_id);\n console.log(\"push status: \" + subscription.status);\n if (subscription.status === \"granted\") {\n console.log(\"push token: \" + subscription.push_token);\n }\n});", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "User Segmentation" } [/block] User segmentation enables you to send notifications to a specific audience. For example, if you have a news website, you can let your users specific content categories that interest them. So if one marked "Sports" you can tag it with this name, and later send a sport specific notification, just to those users who marked this category. [block:api-header] { "type": "fn", "title": "Adding tags for a device" } [/block] In order to add tag for a device, add the following code at the relevant place: [block:code] { "codes": [ { "code": "PushApps.addTag(\"sports_fan\");", "language": "javascript" } ] } [/block] [block:callout] { "type": "warning", "title": "Tags are case insensitive", "body": "Please notice that tags should be lowercase only (but can contains numbers, signs or any other characters)." } [/block] [block:api-header] { "type": "fn", "title": "Removing tags for a device" } [/block] In order to remove tag for a device, add the following code at the relevant place: [block:code] { "codes": [ { "code": "PushApps.removeTag(\"sports_fan\");", "language": "javascript" } ] } [/block] [block:api-header] { "type": "fn", "title": "Get tags for device" } [/block] In order to get all the tags, which are assigned to the current device, please use the following code: [block:code] { "codes": [ { "code": "PushApps.getDeviceTags(function (tagsArray) {\n\tconsole.log(tagsArray);\n});", "language": "javascript" } ] } [/block]