{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Subscription Successful/Failure Callbacks","type":"fn","slug":"successful-subscription-callback","excerpt":"","body":"You can register callback functions which will get executed once the user gets successfully subscribed/fails to get subscribed to push notifications. The same is pushed into the global _pcq queue. Refer to the syntax below:\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Successful Subscription CallBack\"\n}\n[/block]\n**Parameters:**\n\n1) subscriptionSuccessCallback: Command to register the callback function to be executed when the user gets successfully subscribed to push notifications.\n2) callbackFunctionName: This is the name of the callback function. We will return the subscriberId as a parameter to this callback function and another object with two parameters:\n\ni) status: String with value as 'SUBSCRIBED' or 'ALREADYSUBSCRIBED'\nii) message: String which denotes whether user is a new subscriber or whether user was already previously subscribed.\n\nRefer to the syntax below:\n\n_pcq.push(['subscriptionSuccessCallback', callbackFunctionName]);\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"window._pcq = window._pcq || [];\\n_pcq.push(['subscriptionSuccessCallback',callbackFunctionOnSuccessfulSubscription]); //registers callback function to be called when user gets successfully subscribed\\n\\nfunction callbackFunctionOnSuccessfulSubscription(subscriberId, values) {\\n    console.log('User got successfully subscribed.');\\n\\n    console.log(subscriberId); //will output the user's subscriberId\\n\\n    console.log(values.status); // SUBSCRIBED or ALREADYSUBSCRIBED\\n\\n    console.log(values.message) // 'User has subscribed to push notifications.' or 'User is already subscribed to push notifications.'\\n\\n    console.log('Now you may run code which should be executed once user gets successfully subscribed.');\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"Subscription Failure CallBack\"\n}\n[/block]\n**Parameters:**\n\n1) subscriptionFailureCallback: Command to register the callback function to be executed when the subscription fails.\n2) callbackFunctionName: This is the name of the callback function. We will return an object with two parameters.\n\ni) status: String with value as 'BLOCKED', 'UNSUBSCRIBED' or 'CANCELLED'\nii) message as to why the subscription failed.\n\nRefer to the syntax below:\n\n_pcq.push(['subscriptionFailureCallback', callbackFunctionName]);\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"window._pcq = window._pcq || [];\\n_pcq.push(['subscriptionFailureCallback',callbackFunctionOnFailedSubscription]); //registers callback function to be called when user gets successfully subscribed\\n\\nfunction callbackFunctionOnFailedSubscription(values) {\\n    console.log('User could not get subscribed to push notifications');\\n\\n    console.log(values.status); // BLOCKED , UNSUBSCRIBED or CANCELLED\\n\\n    console.log(values.message) // 'User has blocked push notifications.', 'User has unsubscribed from push notifications', 'No change in subscription. Child window was closed.' or 'User has closed the notifications opt-in.'\\n\\n    console.log('Now you may run code which should be executed once user subscription fails');\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","updates":["57250c9a1e280b1900e78754","59489dedc5c6290010089392"],"order":6,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"55e5a2adf11ba80d00323917","__v":39,"user":"5554788cb450630d00041dbc","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["55e58b65d101191900f30b17","55e58d16f493c11700584314","55e58d1bd101191900f30b1d"],"_id":"55e58b63d101191900f30b16","__v":3,"createdAt":"2015-09-01T11:26:27.668Z","releaseDate":"2015-09-01T11:26:27.668Z","project":"55e58b63d101191900f30b13"},"category":{"sync":{"isSync":false,"url":""},"pages":["55e58d21f11ba80d003238be","55e59fddd101191900f30b82","55e5a218f11ba80d00323911","55e5a28bf11ba80d00323915","55e5a2adf11ba80d00323917","55e5a335a603d62300f8926f","55e5a4cad101191900f30b9d","55e5a5396015ce1900eadb54","55e81c700f5df10d004a9c10"],"title":"JavaScript API","slug":"js-api","order":1,"from_sync":false,"reference":false,"_id":"55e58d16f493c11700584314","project":"55e58b63d101191900f30b13","__v":9,"createdAt":"2015-09-01T11:33:42.203Z","version":"55e58b63d101191900f30b16"},"project":"55e58b63d101191900f30b13","createdAt":"2015-09-01T13:05:49.309Z","githubsync":"","parentDoc":null}

Subscription Successful/Failure Callbacks


You can register callback functions which will get executed once the user gets successfully subscribed/fails to get subscribed to push notifications. The same is pushed into the global _pcq queue. Refer to the syntax below: [block:api-header] { "type": "fn", "title": "Successful Subscription CallBack" } [/block] **Parameters:** 1) subscriptionSuccessCallback: Command to register the callback function to be executed when the user gets successfully subscribed to push notifications. 2) callbackFunctionName: This is the name of the callback function. We will return the subscriberId as a parameter to this callback function and another object with two parameters: i) status: String with value as 'SUBSCRIBED' or 'ALREADYSUBSCRIBED' ii) message: String which denotes whether user is a new subscriber or whether user was already previously subscribed. Refer to the syntax below: _pcq.push(['subscriptionSuccessCallback', callbackFunctionName]); [block:code] { "codes": [ { "code": "window._pcq = window._pcq || [];\n_pcq.push(['subscriptionSuccessCallback',callbackFunctionOnSuccessfulSubscription]); //registers callback function to be called when user gets successfully subscribed\n\nfunction callbackFunctionOnSuccessfulSubscription(subscriberId, values) {\n console.log('User got successfully subscribed.');\n\n console.log(subscriberId); //will output the user's subscriberId\n\n console.log(values.status); // SUBSCRIBED or ALREADYSUBSCRIBED\n\n console.log(values.message) // 'User has subscribed to push notifications.' or 'User is already subscribed to push notifications.'\n\n console.log('Now you may run code which should be executed once user gets successfully subscribed.');\n}", "language": "javascript" } ] } [/block] [block:api-header] { "type": "fn", "title": "Subscription Failure CallBack" } [/block] **Parameters:** 1) subscriptionFailureCallback: Command to register the callback function to be executed when the subscription fails. 2) callbackFunctionName: This is the name of the callback function. We will return an object with two parameters. i) status: String with value as 'BLOCKED', 'UNSUBSCRIBED' or 'CANCELLED' ii) message as to why the subscription failed. Refer to the syntax below: _pcq.push(['subscriptionFailureCallback', callbackFunctionName]); [block:code] { "codes": [ { "code": "window._pcq = window._pcq || [];\n_pcq.push(['subscriptionFailureCallback',callbackFunctionOnFailedSubscription]); //registers callback function to be called when user gets successfully subscribed\n\nfunction callbackFunctionOnFailedSubscription(values) {\n console.log('User could not get subscribed to push notifications');\n\n console.log(values.status); // BLOCKED , UNSUBSCRIBED or CANCELLED\n\n console.log(values.message) // 'User has blocked push notifications.', 'User has unsubscribed from push notifications', 'No change in subscription. Child window was closed.' or 'User has closed the notifications opt-in.'\n\n console.log('Now you may run code which should be executed once user subscription fails');\n}", "language": "javascript" } ] } [/block]