{"_id":"55e5a28bf11ba80d00323915","user":"5554788cb450630d00041dbc","category":{"_id":"55e58d16f493c11700584314","project":"55e58b63d101191900f30b13","__v":9,"pages":["55e58d21f11ba80d003238be","55e59fddd101191900f30b82","55e5a218f11ba80d00323911","55e5a28bf11ba80d00323915","55e5a2adf11ba80d00323917","55e5a335a603d62300f8926f","55e5a4cad101191900f30b9d","55e5a5396015ce1900eadb54","55e81c700f5df10d004a9c10"],"version":"55e58b63d101191900f30b16","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-01T11:33:42.203Z","from_sync":false,"order":1,"slug":"js-api","title":"JavaScript API"},"project":"55e58b63d101191900f30b13","__v":74,"parentDoc":null,"version":{"_id":"55e58b63d101191900f30b16","__v":3,"project":"55e58b63d101191900f30b13","createdAt":"2015-09-01T11:26:27.668Z","releaseDate":"2015-09-01T11:26:27.668Z","categories":["55e58b65d101191900f30b17","55e58d16f493c11700584314","55e58d1bd101191900f30b1d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["57a1aab7f724ae1900df4898","5927ae06ac22862f00b59635","59ee391338753e003a772afb"],"next":{"pages":[],"description":""},"createdAt":"2015-09-01T13:05:15.382Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"This is used to explicitly trigger an Opt-in box for subscribing the user to push notifications.\n\n**Parameters**\n\n**1) triggerOptIn:** Command to trigger the opt-in box for subscribing the user to push notifications.\n\n**2) settingsObject:** (Type: Dictionary, Optional):\n\nContents of 'Settings Object' Dictionary:\n\n**i) Subscriber Segment** (Type: String, Optional, Default: 'global' (default subscriber segment)) - This will add the subscriber to the segment specified.\n\n**ii) Modal box (with logo and text) to explain the rationale:** (Type: Dictionary, Optional) - If this parameter is not specified, modal will not be shown. \n\nThis parameter is used only in case of HTTPS implementations. In case of HTTP implementations, a custom opt-in box is shown instead of the modal.\n\nContents of 'Modal box' Dictionary:\n\na) Text (Type: String, Optional) - This text will be shown in the modal box. Default text will be shown if this parameter is not specified.\nDefault: “Please click ‘Allow’ to receive push notifications from {company name}”. \n\nb) Blacken background. (Type: Boolean, Default: true) - This will blacken the page background, outside the modal box, if set to true.\n\n**3) HTTPWindowOnly** (Type: Boolean, Optional, Default: false)\nThis is only applicable for HTTP implementations. If this is set to True, the child window which subscribes users to push notifications, will open directly without opening the custom opt-in box.\n\n**Functionality:**\n\ni) **If User is not subscribed**\n\n**For HTTPS implementations:**\nShows the Chrome Native opt-in box\nShows the modal box (that says please subscribe)(if 'modal' parameter is passed)\nBlackens the background\n\n**For HTTP implementations:**\nShows the custom opt-in box\nBlackens the background\n\nii) **If User is already subscribed**\nShows modal box with logo and text. Default :“You are already subscribed to push notifications” (if 'modal' parameter is passed)\n\niii) **If User had blocked**\nShows modal box with logo, and text. Default: “Uh-oh! You seem to have blocked the notifications last time you came on our website. To see how to subscribe, <link to official docs>Click Here</link>\". (if 'modal' parameter is passed)\n\n**Example code**\n\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', modal: {text: 'Get instant alerts from our website. Please subscribe.', blackenBackground: true}, httpWindowOnly: true}]);\n\n//Examples for HTTPS Implementations\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//Examples for HTTPS Implementations\\n\\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', modal: {text: 'Get instant alerts from our website. Please subscribe.', blackenBackground: true}}]); //Calls triggerOptIn with custom text, blackened background and segment as 'homepage'\\n\\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', modal: {text: 'Get instant alerts from our website. Please subscribe.', blackenBackground: true}}]); //Calls triggerOptIn with default text,  blackened background and segment and default segment as 'homepage'\\n\\nwindow._pcq.push(['triggerOptIn', {subscriberSegment: 'homepage'}]); //Calls triggerOptIn without modal and default segment as 'homepage'\\n\\nwindow._pcq.push(['triggerOptIn']); //Calls triggerOptIn with default text and default segment(global)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n//Examples for HTTP Implementations\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//Examples for HTTP Implementations\\n\\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage'}]);//Calls triggerOptIn with segment as 'homepage'\\n\\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', httpWindowOnly: true}]); //Calls triggerOptIn with segment as 'homepage' and with child window only. Custom Opt-in will not open in this case.\\n\\nwindow._pcq.push(['triggerOptIn',{httpWindowOnly: true}]); //Calls triggerOptIn with default segment(global) and with child window only. Custom Opt-in will not open in this case.\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"trigger-opt-in-box-for-subscribing-to-push-notifications","type":"fn","title":"Trigger Opt-In Box  for Subscribing to Push Notifications"}

Trigger Opt-In Box for Subscribing to Push Notifications


This is used to explicitly trigger an Opt-in box for subscribing the user to push notifications. **Parameters** **1) triggerOptIn:** Command to trigger the opt-in box for subscribing the user to push notifications. **2) settingsObject:** (Type: Dictionary, Optional): Contents of 'Settings Object' Dictionary: **i) Subscriber Segment** (Type: String, Optional, Default: 'global' (default subscriber segment)) - This will add the subscriber to the segment specified. **ii) Modal box (with logo and text) to explain the rationale:** (Type: Dictionary, Optional) - If this parameter is not specified, modal will not be shown. This parameter is used only in case of HTTPS implementations. In case of HTTP implementations, a custom opt-in box is shown instead of the modal. Contents of 'Modal box' Dictionary: a) Text (Type: String, Optional) - This text will be shown in the modal box. Default text will be shown if this parameter is not specified. Default: “Please click ‘Allow’ to receive push notifications from {company name}”. b) Blacken background. (Type: Boolean, Default: true) - This will blacken the page background, outside the modal box, if set to true. **3) HTTPWindowOnly** (Type: Boolean, Optional, Default: false) This is only applicable for HTTP implementations. If this is set to True, the child window which subscribes users to push notifications, will open directly without opening the custom opt-in box. **Functionality:** i) **If User is not subscribed** **For HTTPS implementations:** Shows the Chrome Native opt-in box Shows the modal box (that says please subscribe)(if 'modal' parameter is passed) Blackens the background **For HTTP implementations:** Shows the custom opt-in box Blackens the background ii) **If User is already subscribed** Shows modal box with logo and text. Default :“You are already subscribed to push notifications” (if 'modal' parameter is passed) iii) **If User had blocked** Shows modal box with logo, and text. Default: “Uh-oh! You seem to have blocked the notifications last time you came on our website. To see how to subscribe, <link to official docs>Click Here</link>". (if 'modal' parameter is passed) **Example code** window._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', modal: {text: 'Get instant alerts from our website. Please subscribe.', blackenBackground: true}, httpWindowOnly: true}]); //Examples for HTTPS Implementations [block:code] { "codes": [ { "code": "//Examples for HTTPS Implementations\n\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', modal: {text: 'Get instant alerts from our website. Please subscribe.', blackenBackground: true}}]); //Calls triggerOptIn with custom text, blackened background and segment as 'homepage'\n\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', modal: {text: 'Get instant alerts from our website. Please subscribe.', blackenBackground: true}}]); //Calls triggerOptIn with default text, blackened background and segment and default segment as 'homepage'\n\nwindow._pcq.push(['triggerOptIn', {subscriberSegment: 'homepage'}]); //Calls triggerOptIn without modal and default segment as 'homepage'\n\nwindow._pcq.push(['triggerOptIn']); //Calls triggerOptIn with default text and default segment(global)", "language": "javascript" } ] } [/block] //Examples for HTTP Implementations [block:code] { "codes": [ { "code": "//Examples for HTTP Implementations\n\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage'}]);//Calls triggerOptIn with segment as 'homepage'\n\nwindow._pcq.push(['triggerOptIn',{subscriberSegment: 'homepage', httpWindowOnly: true}]); //Calls triggerOptIn with segment as 'homepage' and with child window only. Custom Opt-in will not open in this case.\n\nwindow._pcq.push(['triggerOptIn',{httpWindowOnly: true}]); //Calls triggerOptIn with default segment(global) and with child window only. Custom Opt-in will not open in this case.", "language": "javascript" } ] } [/block]