{"__v":26,"_id":"55e5a218f11ba80d00323911","category":{"__v":9,"_id":"55e58d16f493c11700584314","pages":["55e58d21f11ba80d003238be","55e59fddd101191900f30b82","55e5a218f11ba80d00323911","55e5a28bf11ba80d00323915","55e5a2adf11ba80d00323917","55e5a335a603d62300f8926f","55e5a4cad101191900f30b9d","55e5a5396015ce1900eadb54","55e81c700f5df10d004a9c10"],"project":"55e58b63d101191900f30b13","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"},"parentDoc":null,"project":"55e58b63d101191900f30b13","user":"5554788cb450630d00041dbc","version":{"__v":3,"_id":"55e58b63d101191900f30b16","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":["584fa14a5f70af2d00855013"],"next":{"pages":[],"description":""},"createdAt":"2015-09-01T13:03:20.902Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"SubscriberID is a unique ID of the current user, exposed by the PushCrew API, which you can map in your own database against user information like email addresses etc.\n\nVariable **pushcrew.subscriberId** can be used to get the SubscriberID of current user.\n\nIf the user isn't subscribed to push notifications, its value will be false(boolean)\nIf the user has blocked push notifications, its value will be -1(integer)\n\n**Please Note: This variable should only be accessed when API is ready. Most preferably inside APIReady Callback**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"_pcq.push(['APIReady', callbackFunction]);\\n\\n//some code here\\n\\nfunction callbackFunction() {\\n      console.log(pushcrew.subscriberId); // will return something like this if current user is a subscriber '1c5d546172cfb4be65a8d51b047c4804'\\n\\n  console.log(pushcrew.subscriberId); // will return false(boolean) if user is not subscribed to push notifications\\n\\n  console.log(pushcrew.subscriberId); // will return -1(integer) if user has blocked push notifications from your website\\t  \\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nYou can also access **pushcrew.subscriberId** after checking if pushcrew.isAPIReady evaluates to true(Boolean).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if(pushcrew.isAPIReady) {\\n    console.log(pushcrew.subscriberId); // will return something like this if current user is a subscriber '1c5d546172cfb4be65a8d51b047c4804'\\n\\n  console.log(pushcrew.subscriberId); // will return false(boolean) if user is not subscribed to push notifications\\n\\n  console.log(pushcrew.subscriberId); // will return -1(integer) if user has blocked push notifications from your website\\t  \\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIf API is not ready, and **pushcrew.subscriberId** is accessed, it will return null.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"console.log(pushcrew.subscriberId); //returns null\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"get-subscriberid-of-current-user","type":"basic","title":"Get SubscriberID of current user"}

Get SubscriberID of current user


SubscriberID is a unique ID of the current user, exposed by the PushCrew API, which you can map in your own database against user information like email addresses etc. Variable **pushcrew.subscriberId** can be used to get the SubscriberID of current user. If the user isn't subscribed to push notifications, its value will be false(boolean) If the user has blocked push notifications, its value will be -1(integer) **Please Note: This variable should only be accessed when API is ready. Most preferably inside APIReady Callback** [block:code] { "codes": [ { "code": "_pcq.push(['APIReady', callbackFunction]);\n\n//some code here\n\nfunction callbackFunction() {\n console.log(pushcrew.subscriberId); // will return something like this if current user is a subscriber '1c5d546172cfb4be65a8d51b047c4804'\n\n console.log(pushcrew.subscriberId); // will return false(boolean) if user is not subscribed to push notifications\n\n console.log(pushcrew.subscriberId); // will return -1(integer) if user has blocked push notifications from your website\t \n}", "language": "javascript" } ] } [/block] You can also access **pushcrew.subscriberId** after checking if pushcrew.isAPIReady evaluates to true(Boolean). [block:code] { "codes": [ { "code": "if(pushcrew.isAPIReady) {\n console.log(pushcrew.subscriberId); // will return something like this if current user is a subscriber '1c5d546172cfb4be65a8d51b047c4804'\n\n console.log(pushcrew.subscriberId); // will return false(boolean) if user is not subscribed to push notifications\n\n console.log(pushcrew.subscriberId); // will return -1(integer) if user has blocked push notifications from your website\t \n}", "language": "javascript" } ] } [/block] If API is not ready, and **pushcrew.subscriberId** is accessed, it will return null. [block:code] { "codes": [ { "code": "console.log(pushcrew.subscriberId); //returns null", "language": "javascript" } ] } [/block]