{"__v":1,"_id":"571f6666e2b7000e0091c580","api":{"auth":"required","params":[],"results":{"codes":[]},"settings":"","url":""},"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Version\"\n}\n[/block]\nYou are viewing version 3.0 of the Nudgespot APIs. Version 2.0 documentation can be found [here](http://nudgespot.readme.io/v2.0/docs).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Introduction\"\n}\n[/block]\nNudgespot makes it easy to trigger emails, SMS and push notifications from your code. Instead of writing code to send any of these messages, you only send events (we call them activities) to Nudgespot, and then configure messages as triggers from our dashboard. This gives you the flexibility to change the subject, body or design at any time, without making changes to your code. Sending events to Nudgespot is easy, and if you have used Google Analytics or Mixpanel, then you are already familiar with most of this.\n\nIf you have any feedback on this page, don't hesitate to tweet us at @nudgespot, email us at  support@nudgespot.com or suggest edits yourself by clicking on \"Suggest Edits\" in the top right section of this page. You can also find our support [here](http://www.nudgespot.com).","category":"571f6666e2b7000e0091c57b","createdAt":"2015-04-13T20:04:56.810Z","excerpt":"This page will help you get started with Nudgespot. You'll be up and running in a jiffy!","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":0,"project":"552c21677820b80d00aa4ec5","slug":"getting-started","sync_unique":"","title":"Getting Started","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Getting Started

This page will help you get started with Nudgespot. You'll be up and running in a jiffy!

[block:api-header] { "type": "basic", "title": "Version" } [/block] You are viewing version 3.0 of the Nudgespot APIs. Version 2.0 documentation can be found [here](http://nudgespot.readme.io/v2.0/docs). [block:api-header] { "type": "basic", "title": "Introduction" } [/block] Nudgespot makes it easy to trigger emails, SMS and push notifications from your code. Instead of writing code to send any of these messages, you only send events (we call them activities) to Nudgespot, and then configure messages as triggers from our dashboard. This gives you the flexibility to change the subject, body or design at any time, without making changes to your code. Sending events to Nudgespot is easy, and if you have used Google Analytics or Mixpanel, then you are already familiar with most of this. If you have any feedback on this page, don't hesitate to tweet us at @nudgespot, email us at support@nudgespot.com or suggest edits yourself by clicking on "Suggest Edits" in the top right section of this page. You can also find our support [here](http://www.nudgespot.com).
[block:api-header] { "type": "basic", "title": "Version" } [/block] You are viewing version 3.0 of the Nudgespot APIs. Version 2.0 documentation can be found [here](http://nudgespot.readme.io/v2.0/docs). [block:api-header] { "type": "basic", "title": "Introduction" } [/block] Nudgespot makes it easy to trigger emails, SMS and push notifications from your code. Instead of writing code to send any of these messages, you only send events (we call them activities) to Nudgespot, and then configure messages as triggers from our dashboard. This gives you the flexibility to change the subject, body or design at any time, without making changes to your code. Sending events to Nudgespot is easy, and if you have used Google Analytics or Mixpanel, then you are already familiar with most of this. If you have any feedback on this page, don't hesitate to tweet us at @nudgespot, email us at support@nudgespot.com or suggest edits yourself by clicking on "Suggest Edits" in the top right section of this page. You can also find our support [here](http://www.nudgespot.com).
{"category":"571f6666e2b7000e0091c57c","project":"552c21677820b80d00aa4ec5","user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","updates":[],"_id":"571f6666e2b7000e0091c583","createdAt":"2015-04-21T22:41:27.755Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Nudgespot tracks activities of users and lets you send messages based on their behavior - both automated as well as ad hoc messages. \nIf you are planning to integrate Nudgespot with your website/web app, this is perhaps the simplest way to get started.\nThe integration consists of 3 steps:\n* Place our Javascript in all the pages of your website/app. Typically, you just need to paste this code in the generic template used by your website.\n* Identify the user: Tell us who is the user that is currently logged on. You can pass additional parameters to tell us more info about the user, all of which becomes available in your triggered messages, as well as in narrowing down users that should receive a message.\n* Track activities: And finally, call our track method, to track any activity performed by the user. You can pass parameters for these activities, that you can use in your triggered messages.","excerpt":"Using javascript to integrate with Nudgespot","slug":"javascript-getting-started","type":"basic","title":"Getting Started","__v":0,"childrenPages":[]}

Getting Started

Using javascript to integrate with Nudgespot

Nudgespot tracks activities of users and lets you send messages based on their behavior - both automated as well as ad hoc messages. If you are planning to integrate Nudgespot with your website/web app, this is perhaps the simplest way to get started. The integration consists of 3 steps: * Place our Javascript in all the pages of your website/app. Typically, you just need to paste this code in the generic template used by your website. * Identify the user: Tell us who is the user that is currently logged on. You can pass additional parameters to tell us more info about the user, all of which becomes available in your triggered messages, as well as in narrowing down users that should receive a message. * Track activities: And finally, call our track method, to track any activity performed by the user. You can pass parameters for these activities, that you can use in your triggered messages.
Nudgespot tracks activities of users and lets you send messages based on their behavior - both automated as well as ad hoc messages. If you are planning to integrate Nudgespot with your website/web app, this is perhaps the simplest way to get started. The integration consists of 3 steps: * Place our Javascript in all the pages of your website/app. Typically, you just need to paste this code in the generic template used by your website. * Identify the user: Tell us who is the user that is currently logged on. You can pass additional parameters to tell us more info about the user, all of which becomes available in your triggered messages, as well as in narrowing down users that should receive a message. * Track activities: And finally, call our track method, to track any activity performed by the user. You can pass parameters for these activities, that you can use in your triggered messages.
{"__v":3,"_id":"571f6666e2b7000e0091c584","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"Our Javascript API requires you to identify the user that performs the activities you are interested in tracking. Instead of asking you to pass this user info with every track call, we require you to identify a user once every session.\n\nThe identify method accepts 2 parameters, the first parameter is a string representing a unique ID to identify the user, and the second is a Javascript object/hash representing attributes of the user.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Most of our customers use email as the ID, but it could also be your database ID, or phone number, or any other string that uniquely identifies a user.\",\n  \"title\": \"What should you use for the ID parameter?\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"identify\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Parameter\",\n    \"h-1\": \"Optional\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"unique_id\\n**String**\",\n    \"0-1\": \"No\",\n    \"0-2\": \"The unique id\",\n    \"1-0\": \"user_properties\\n**Hash/Object**\",\n    \"0-3\": \"\",\n    \"1-1\": \"Yes\",\n    \"1-2\": \"Any number of properties to be associated with the user.\\nEg: {\\\"gender\\\": \\\"Male\\\", \\\"city\\\": \\\"London\\\", plan: \\\"Silver\\\"}\",\n    \"2-0\": \"callback\",\n    \"2-1\": \"Yes\",\n    \"2-2\": \"A callback function that will be called when the call to identify is complete. A boolean indicating success/failure will be passed as a parameter to this callback.\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"A note about user properties\",\n  \"body\": \"More than a couple of points, actually.\\n* If you are not using email as the unique ID, you should pass contacts as a key in the user properties. The contacts should include at least one record for email or phone, otherwise, you won't be able to send any message to the user.\\n* To denote when a user joined your service/app, you can pass signed_up_at as a key as part of the user properties hash. The signed up datetime should be passed in ISO-8601 format.\\n* The hash can contain key value pairs of any types - you can send even array or a hash property, and use these in your emails (remember, we support Liquid templating in our emails).\"\n}\n[/block]\nYou can use the identify call in the following ways:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"nudgespot.identify(\\\"foo@example.com\\\"); //Just email as an identifier\",\n      \"language\": \"javascript\",\n      \"name\": \"js-identify-simple\"\n    }\n  ]\n}\n[/block]\n---- OR ----\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\nnudgespot.identify(\\\"fefta23df5fdfdjoomeumbwer\\\", {signed_up_at: \\\"2015-04-20T13:00:28+00:00\\\", contacts: [{contact_type: \\\"email\\\", contact_value: \\\"foo@example.com\\\", subscription_status: \\\"active\\\"},{contact_type: \\\"phone\\\", contact_value: \\\"+19876543210\\\", subscription_status: \\\"inactive\\\"}], plan: \\\"Silver\\\"}); // Example that uses a unique ID, along with contact attributes in the user properties hash. The subscription_status flag can be used to subscribe/unsubscriber a particular contact.\",\n      \"language\": \"javascript\",\n      \"name\": \"js-identify-props\"\n    }\n  ]\n}\n[/block]\n---- OR ----\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"nudgespot.identify(\\\"foo@example.com\\\", {plan: \\\"Gold\\\"}, function(call_status){\\n    if (call_status) {\\n      // Yay, success\\n    }\\n}); // Example that uses callback\",\n      \"language\": \"javascript\",\n      \"name\": \"js-identify-callback\"\n    }\n  ]\n}\n[/block]","category":"571f6666e2b7000e0091c57c","createdAt":"2015-04-21T21:10:51.375Z","excerpt":"","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":2,"project":"552c21677820b80d00aa4ec5","slug":"js-identify-a-user","sync_unique":"","title":"Identify a user","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Identify a user


Our Javascript API requires you to identify the user that performs the activities you are interested in tracking. Instead of asking you to pass this user info with every track call, we require you to identify a user once every session. The identify method accepts 2 parameters, the first parameter is a string representing a unique ID to identify the user, and the second is a Javascript object/hash representing attributes of the user. [block:callout] { "type": "info", "body": "Most of our customers use email as the ID, but it could also be your database ID, or phone number, or any other string that uniquely identifies a user.", "title": "What should you use for the ID parameter?" } [/block] [block:api-header] { "type": "fn", "title": "identify" } [/block] [block:parameters] { "data": { "h-0": "Parameter", "h-1": "Optional", "h-2": "Description", "0-0": "unique_id\n**String**", "0-1": "No", "0-2": "The unique id", "1-0": "user_properties\n**Hash/Object**", "0-3": "", "1-1": "Yes", "1-2": "Any number of properties to be associated with the user.\nEg: {\"gender\": \"Male\", \"city\": \"London\", plan: \"Silver\"}", "2-0": "callback", "2-1": "Yes", "2-2": "A callback function that will be called when the call to identify is complete. A boolean indicating success/failure will be passed as a parameter to this callback." }, "cols": 3, "rows": 3 } [/block] [block:callout] { "type": "info", "title": "A note about user properties", "body": "More than a couple of points, actually.\n* If you are not using email as the unique ID, you should pass contacts as a key in the user properties. The contacts should include at least one record for email or phone, otherwise, you won't be able to send any message to the user.\n* To denote when a user joined your service/app, you can pass signed_up_at as a key as part of the user properties hash. The signed up datetime should be passed in ISO-8601 format.\n* The hash can contain key value pairs of any types - you can send even array or a hash property, and use these in your emails (remember, we support Liquid templating in our emails)." } [/block] You can use the identify call in the following ways: [block:code] { "codes": [ { "code": "nudgespot.identify(\"foo@example.com\"); //Just email as an identifier", "language": "javascript", "name": "js-identify-simple" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "\nnudgespot.identify(\"fefta23df5fdfdjoomeumbwer\", {signed_up_at: \"2015-04-20T13:00:28+00:00\", contacts: [{contact_type: \"email\", contact_value: \"foo@example.com\", subscription_status: \"active\"},{contact_type: \"phone\", contact_value: \"+19876543210\", subscription_status: \"inactive\"}], plan: \"Silver\"}); // Example that uses a unique ID, along with contact attributes in the user properties hash. The subscription_status flag can be used to subscribe/unsubscriber a particular contact.", "language": "javascript", "name": "js-identify-props" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "nudgespot.identify(\"foo@example.com\", {plan: \"Gold\"}, function(call_status){\n if (call_status) {\n // Yay, success\n }\n}); // Example that uses callback", "language": "javascript", "name": "js-identify-callback" } ] } [/block]
Our Javascript API requires you to identify the user that performs the activities you are interested in tracking. Instead of asking you to pass this user info with every track call, we require you to identify a user once every session. The identify method accepts 2 parameters, the first parameter is a string representing a unique ID to identify the user, and the second is a Javascript object/hash representing attributes of the user. [block:callout] { "type": "info", "body": "Most of our customers use email as the ID, but it could also be your database ID, or phone number, or any other string that uniquely identifies a user.", "title": "What should you use for the ID parameter?" } [/block] [block:api-header] { "type": "fn", "title": "identify" } [/block] [block:parameters] { "data": { "h-0": "Parameter", "h-1": "Optional", "h-2": "Description", "0-0": "unique_id\n**String**", "0-1": "No", "0-2": "The unique id", "1-0": "user_properties\n**Hash/Object**", "0-3": "", "1-1": "Yes", "1-2": "Any number of properties to be associated with the user.\nEg: {\"gender\": \"Male\", \"city\": \"London\", plan: \"Silver\"}", "2-0": "callback", "2-1": "Yes", "2-2": "A callback function that will be called when the call to identify is complete. A boolean indicating success/failure will be passed as a parameter to this callback." }, "cols": 3, "rows": 3 } [/block] [block:callout] { "type": "info", "title": "A note about user properties", "body": "More than a couple of points, actually.\n* If you are not using email as the unique ID, you should pass contacts as a key in the user properties. The contacts should include at least one record for email or phone, otherwise, you won't be able to send any message to the user.\n* To denote when a user joined your service/app, you can pass signed_up_at as a key as part of the user properties hash. The signed up datetime should be passed in ISO-8601 format.\n* The hash can contain key value pairs of any types - you can send even array or a hash property, and use these in your emails (remember, we support Liquid templating in our emails)." } [/block] You can use the identify call in the following ways: [block:code] { "codes": [ { "code": "nudgespot.identify(\"foo@example.com\"); //Just email as an identifier", "language": "javascript", "name": "js-identify-simple" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "\nnudgespot.identify(\"fefta23df5fdfdjoomeumbwer\", {signed_up_at: \"2015-04-20T13:00:28+00:00\", contacts: [{contact_type: \"email\", contact_value: \"foo@example.com\", subscription_status: \"active\"},{contact_type: \"phone\", contact_value: \"+19876543210\", subscription_status: \"inactive\"}], plan: \"Silver\"}); // Example that uses a unique ID, along with contact attributes in the user properties hash. The subscription_status flag can be used to subscribe/unsubscriber a particular contact.", "language": "javascript", "name": "js-identify-props" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "nudgespot.identify(\"foo@example.com\", {plan: \"Gold\"}, function(call_status){\n if (call_status) {\n // Yay, success\n }\n}); // Example that uses callback", "language": "javascript", "name": "js-identify-callback" } ] } [/block]
{"__v":2,"_id":"571f6666e2b7000e0091c585","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"You can track activities performed by your users using our **track** method call.\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"track\"\n}\n[/block]\nParameters for the track method\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Parameter\",\n    \"h-1\": \"Optional\",\n    \"0-0\": \"activity_name\\n**String**\",\n    \"0-1\": \"No\",\n    \"0-2\": \"The activity that you are tracking against a user. We recommend using _ (underscore) notation for names. Eg: purchased, subscribed_to_plan, canceled_plan\",\n    \"1-0\": \"activity_properties\\n**Hash/Object**\",\n    \"1-1\": \"Yes\",\n    \"2-0\": \"callback\",\n    \"2-1\": \"Yes\",\n    \"1-2\": \"Properties that you'd like to associate with the activity. You can use these properties in your triggered emails, as well as search users based on the activities they performed. Eg: {\\\"product_name\\\": \\\"Mountain Dew\\\", \\\"price\\\": \\\"10.10\\\", expires: \\\"2015-04-29T13:00:28+00:00\\\"}\",\n    \"2-2\": \"A callback function that will be called when the call to **track** is complete. A boolean indicating success/failure will be passed as a parameter to this callback.\",\n    \"h-2\": \"Description\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\nHere are a few examples to use the **track** method\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"nudgespot.track(\\\"canceled_plan\\\"); //Track event without any properties\",\n      \"language\": \"javascript\",\n      \"name\": \"js-track-simple\"\n    }\n  ]\n}\n[/block]\n---- OR ----\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Track event with properties\\nnudgespot.track(\\\"add_to_cart\\\", {\\\"items\\\": [{\\\"value\\\": 200, \\\"name\\\": \\\"Hugo Boss Perfume\\\"}],\\\"total_value\\\": 200});\",\n      \"language\": \"javascript\",\n      \"name\": \"js-track-props-advanced\"\n    }\n  ]\n}\n[/block]\n---- OR ----\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"nudgespot.track(\\\"signup\\\", {plan: \\\"Silver\\\"});\",\n      \"language\": \"javascript\",\n      \"name\": \"js-track-props-basic\"\n    }\n  ]\n}\n[/block]","category":"571f6666e2b7000e0091c57c","createdAt":"2015-04-21T22:07:32.195Z","excerpt":"","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":3,"project":"552c21677820b80d00aa4ec5","slug":"js-track-an-activity","sync_unique":"","title":"Track an activity","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Track an activity


You can track activities performed by your users using our **track** method call. [block:api-header] { "type": "fn", "title": "track" } [/block] Parameters for the track method [block:parameters] { "data": { "h-0": "Parameter", "h-1": "Optional", "0-0": "activity_name\n**String**", "0-1": "No", "0-2": "The activity that you are tracking against a user. We recommend using _ (underscore) notation for names. Eg: purchased, subscribed_to_plan, canceled_plan", "1-0": "activity_properties\n**Hash/Object**", "1-1": "Yes", "2-0": "callback", "2-1": "Yes", "1-2": "Properties that you'd like to associate with the activity. You can use these properties in your triggered emails, as well as search users based on the activities they performed. Eg: {\"product_name\": \"Mountain Dew\", \"price\": \"10.10\", expires: \"2015-04-29T13:00:28+00:00\"}", "2-2": "A callback function that will be called when the call to **track** is complete. A boolean indicating success/failure will be passed as a parameter to this callback.", "h-2": "Description" }, "cols": 3, "rows": 3 } [/block] Here are a few examples to use the **track** method [block:code] { "codes": [ { "code": "nudgespot.track(\"canceled_plan\"); //Track event without any properties", "language": "javascript", "name": "js-track-simple" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "// Track event with properties\nnudgespot.track(\"add_to_cart\", {\"items\": [{\"value\": 200, \"name\": \"Hugo Boss Perfume\"}],\"total_value\": 200});", "language": "javascript", "name": "js-track-props-advanced" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "nudgespot.track(\"signup\", {plan: \"Silver\"});", "language": "javascript", "name": "js-track-props-basic" } ] } [/block]
You can track activities performed by your users using our **track** method call. [block:api-header] { "type": "fn", "title": "track" } [/block] Parameters for the track method [block:parameters] { "data": { "h-0": "Parameter", "h-1": "Optional", "0-0": "activity_name\n**String**", "0-1": "No", "0-2": "The activity that you are tracking against a user. We recommend using _ (underscore) notation for names. Eg: purchased, subscribed_to_plan, canceled_plan", "1-0": "activity_properties\n**Hash/Object**", "1-1": "Yes", "2-0": "callback", "2-1": "Yes", "1-2": "Properties that you'd like to associate with the activity. You can use these properties in your triggered emails, as well as search users based on the activities they performed. Eg: {\"product_name\": \"Mountain Dew\", \"price\": \"10.10\", expires: \"2015-04-29T13:00:28+00:00\"}", "2-2": "A callback function that will be called when the call to **track** is complete. A boolean indicating success/failure will be passed as a parameter to this callback.", "h-2": "Description" }, "cols": 3, "rows": 3 } [/block] Here are a few examples to use the **track** method [block:code] { "codes": [ { "code": "nudgespot.track(\"canceled_plan\"); //Track event without any properties", "language": "javascript", "name": "js-track-simple" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "// Track event with properties\nnudgespot.track(\"add_to_cart\", {\"items\": [{\"value\": 200, \"name\": \"Hugo Boss Perfume\"}],\"total_value\": 200});", "language": "javascript", "name": "js-track-props-advanced" } ] } [/block] ---- OR ---- [block:code] { "codes": [ { "code": "nudgespot.track(\"signup\", {plan: \"Silver\"});", "language": "javascript", "name": "js-track-props-basic" } ] } [/block]
{"category":"571f6666e2b7000e0091c57d","project":"552c21677820b80d00aa4ec5","user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","updates":[],"_id":"571f6666e2b7000e0091c586","createdAt":"2015-04-13T21:55:25.586Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Endpoint\"\n}\n[/block]\nThe base endpoint for all Nudgespot APIs is **https://api.nudgespot.com/201507/**\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Authentication\"\n}\n[/block]\nNudgespot uses Basic authentication to authenticate all REST API calls. The username for authenticating the requests is always \"api\" (without the quotes). You can find your password in the [settings section](https://app.nudgespot.com/settings) of your Nudgespot account. The password is listed as REST API Key.","excerpt":"","slug":"authenticating-your-requests","type":"basic","title":"Getting Started","__v":0,"childrenPages":[]}

Getting Started


[block:api-header] { "type": "basic", "title": "Endpoint" } [/block] The base endpoint for all Nudgespot APIs is **https://api.nudgespot.com/201507/** [block:api-header] { "type": "basic", "title": "Authentication" } [/block] Nudgespot uses Basic authentication to authenticate all REST API calls. The username for authenticating the requests is always "api" (without the quotes). You can find your password in the [settings section](https://app.nudgespot.com/settings) of your Nudgespot account. The password is listed as REST API Key.
[block:api-header] { "type": "basic", "title": "Endpoint" } [/block] The base endpoint for all Nudgespot APIs is **https://api.nudgespot.com/201507/** [block:api-header] { "type": "basic", "title": "Authentication" } [/block] Nudgespot uses Basic authentication to authenticate all REST API calls. The username for authenticating the requests is always "api" (without the quotes). You can find your password in the [settings section](https://app.nudgespot.com/settings) of your Nudgespot account. The password is listed as REST API Key.
{"__v":1,"_id":"571f6666e2b7000e0091c587","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"Here is a list of response codes that Nudgespot uses to convey the status of your HTTP request.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Success Codes\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"200\",\n    \"h-0\": \"Status Code\",\n    \"h-1\": \"Description\",\n    \"1-0\": \"201\",\n    \"2-0\": \"202\",\n    \"0-1\": \"The request was a success. Usually returned as part of find, update and delete requests.\",\n    \"1-1\": \"Created. Used when creating an entity using our API. You can find the href to the entity in the response.\",\n    \"2-1\": \"Accepted. Used when creating an entity using our API, but the server has not yet created the entity, and will create it shortly.\"\n  },\n  \"cols\": 2,\n  \"rows\": 3\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Error Codes\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Status Code\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"400\",\n    \"0-1\": \"Bad Request. Used when the request was malformed.\",\n    \"3-1\": \"Resource Not Found. Used whenever the resource you are trying to lookup, update or delete does not actually exist.\",\n    \"1-0\": \"401\",\n    \"1-1\": \"Unauthorized. Used when the request credentials fail to authenticate. You should check that your REST API key is correct and also the username/password is being sent as a basic authentication header.\",\n    \"2-0\": \"403\",\n    \"2-1\": \"Forbidden. Used when you are allowed to perform that request. It means that most likely your credentials are correct but you do not have the appropriate permissions to perform the operation\",\n    \"3-0\": \"404\",\n    \"4-0\": \"405\",\n    \"4-1\": \"Method not allowed. Used when you are trying to perform an operation on a resource that is not permitted. For example, you cannot delete an account.\",\n    \"5-0\": \"422\",\n    \"5-1\": \"Unprocessable entity. Used when the request is correctly formed and is also authorized but the payload does not meet the validity criteria to be processed. Usually an error response will also be returned indicating the type of error\"\n  },\n  \"cols\": 2,\n  \"rows\": 6\n}\n[/block]","category":"571f6666e2b7000e0091c57d","createdAt":"2015-04-13T21:56:00.518Z","excerpt":"","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":5,"project":"552c21677820b80d00aa4ec5","slug":"response-status-codes","sync_unique":"","title":"Response Status codes","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Response Status codes


Here is a list of response codes that Nudgespot uses to convey the status of your HTTP request. [block:api-header] { "type": "basic", "title": "Success Codes" } [/block] [block:parameters] { "data": { "0-0": "200", "h-0": "Status Code", "h-1": "Description", "1-0": "201", "2-0": "202", "0-1": "The request was a success. Usually returned as part of find, update and delete requests.", "1-1": "Created. Used when creating an entity using our API. You can find the href to the entity in the response.", "2-1": "Accepted. Used when creating an entity using our API, but the server has not yet created the entity, and will create it shortly." }, "cols": 2, "rows": 3 } [/block] [block:api-header] { "type": "basic", "title": "Error Codes" } [/block] [block:parameters] { "data": { "h-0": "Status Code", "h-1": "Description", "0-0": "400", "0-1": "Bad Request. Used when the request was malformed.", "3-1": "Resource Not Found. Used whenever the resource you are trying to lookup, update or delete does not actually exist.", "1-0": "401", "1-1": "Unauthorized. Used when the request credentials fail to authenticate. You should check that your REST API key is correct and also the username/password is being sent as a basic authentication header.", "2-0": "403", "2-1": "Forbidden. Used when you are allowed to perform that request. It means that most likely your credentials are correct but you do not have the appropriate permissions to perform the operation", "3-0": "404", "4-0": "405", "4-1": "Method not allowed. Used when you are trying to perform an operation on a resource that is not permitted. For example, you cannot delete an account.", "5-0": "422", "5-1": "Unprocessable entity. Used when the request is correctly formed and is also authorized but the payload does not meet the validity criteria to be processed. Usually an error response will also be returned indicating the type of error" }, "cols": 2, "rows": 6 } [/block]
Here is a list of response codes that Nudgespot uses to convey the status of your HTTP request. [block:api-header] { "type": "basic", "title": "Success Codes" } [/block] [block:parameters] { "data": { "0-0": "200", "h-0": "Status Code", "h-1": "Description", "1-0": "201", "2-0": "202", "0-1": "The request was a success. Usually returned as part of find, update and delete requests.", "1-1": "Created. Used when creating an entity using our API. You can find the href to the entity in the response.", "2-1": "Accepted. Used when creating an entity using our API, but the server has not yet created the entity, and will create it shortly." }, "cols": 2, "rows": 3 } [/block] [block:api-header] { "type": "basic", "title": "Error Codes" } [/block] [block:parameters] { "data": { "h-0": "Status Code", "h-1": "Description", "0-0": "400", "0-1": "Bad Request. Used when the request was malformed.", "3-1": "Resource Not Found. Used whenever the resource you are trying to lookup, update or delete does not actually exist.", "1-0": "401", "1-1": "Unauthorized. Used when the request credentials fail to authenticate. You should check that your REST API key is correct and also the username/password is being sent as a basic authentication header.", "2-0": "403", "2-1": "Forbidden. Used when you are allowed to perform that request. It means that most likely your credentials are correct but you do not have the appropriate permissions to perform the operation", "3-0": "404", "4-0": "405", "4-1": "Method not allowed. Used when you are trying to perform an operation on a resource that is not permitted. For example, you cannot delete an account.", "5-0": "422", "5-1": "Unprocessable entity. Used when the request is correctly formed and is also authorized but the payload does not meet the validity criteria to be processed. Usually an error response will also be returned indicating the type of error" }, "cols": 2, "rows": 6 } [/block]
{"__v":0,"_id":"571f6666e2b7000e0091c588","api":{"examples":{"codes":[{"language":"json","code":"{\n  \"subscriber\":{\n    \"uid\":\"frodo.baggins\",\n    \"first_name\":\"Frodo\",\n    \"last_name\":\"Baggins\",\n    \"name\":\"Frodo T. Baggins\",\n    \"signed_up_at\":\"2015-07-01T09:30:00Z\",\n    \"properties\":{\n      \"gender\":\"male\",\n      \"age\":53,\n      \"address\":{\n        \"address_line\":\"Bag End\",\n        \"city\":\"Hobbiton\",\n        \"state\":\"Shire\",\n        \"postal_code\":\"SH9087\",\n        \"country\":\"Middle Earth\"\n      }\n    },\n    \"contacts\":[\n      {\n        \"contact_type\":\"email\",\n        \"contact_value\":\"frodo.baggins@bagend.com\",\n        \"subscription_status\":\"active\"\n      },\n      {\n        \"contact_type\":\"phone\",\n        \"contact_value\":\"+12345678900\",\n        \"subscription_status\":\"active\"\n      }\n    ]\n  }\n}","name":"subscriber-create-request"}]},"results":{"codes":[{"name":"","code":"{\n  \"href\":\"https://api.nudgespot.com/201507/subscribers/954\",\n  \"id\":954,\n  \"uid\":\"frodo.baggins\",\n  \"first_name\":\"Frodo\",\n  \"last_name\":\"Baggins\",\n  \"name\":\"Frodo T. Baggins\",\n  \"signed_up_at\":\"2015-07-01T09:30:00Z\",\n  \"properties\":{\n    \"address\":{\n      \"postal_code\":\"SH9087\",\n      \"state\":\"Shire\",\n      \"address_line\":\"Bag End\",\n      \"country\":\"Middle Earth\",\n      \"city\":\"Hobbiton\"\n    },\n    \"age\":53,\n    \"gender\":\"male\",\n    \"last_opened\":null,\n    \"last_clicked\":null,\n    \"last_contact\":null,\n    \"last_seen\":null\n  },\n  \"contacts\":[\n    {\n      \"href\":\"https://api.nudgespot.com/201507/subscriber_contacts/1079\",\n      \"id\":1079,\n      \"contact_type\":\"email\",\n      \"contact_value\":\"frodo.baggins@bagend.com\",\n      \"subscription_status\":\"new\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    },\n    {\n      \"href\":\"https://api.nudgespot.com/201507/subscriber_contacts/1080\",\n      \"id\":1080,\n      \"contact_type\":\"phone\",\n      \"contact_value\":\"+1234567890\",\n      \"subscription_status\":\"active\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    }\n  ]\n}","language":"json","status":200},{"code":"{\"error\":\"conflict\"}","language":"json","status":409}]},"settings":"55a6b400112cf20d003a30d2","auth":"required","params":[{"_id":"552c472ed9f89e0d0015a5c5","ref":"","required":true,"desc":"Unique ID of the user. This should almost always be same as the unique ID that you use in your system. It could be an email, phone number or a random string generated by your system as long as it is unique and can be used to uniquely identify a user.","default":"","type":"string","name":"subscriber.uid","in":"body"},{"_id":"552c4c8ed9f89e0d0015a5db","ref":"","required":false,"desc":"First name of the user","default":"","type":"string","name":"subscriber.first_name","in":"body"},{"_id":"552c4d56d9f89e0d0015a5e0","ref":"","required":false,"desc":"Last name of the user","default":"","type":"string","name":"subscriber.last_name","in":"body"},{"_id":"55a6b7885ca7b41700e13268","ref":"","required":false,"desc":"Full name of the user. Defaults to the combination of first_name and last_name if not provided.","default":"","type":"string","name":"subscriber.name","in":"body"},{"_id":"552c4d56d9f89e0d0015a5df","ref":"","required":false,"desc":"Should be in ISO8601 format. Example: 2015-01-02T05:30:21Z. Defaults to current timestamp in UTC if not provided.","default":"","type":"datetime","name":"subscriber.signed_up_at","in":"body"},{"_id":"552c4d56d9f89e0d0015a5dd","ref":"","required":false,"desc":"Name-value pairs of additional attributes you'd like to associate with the user. You can send a nested hash of basic key-value pairs. General convention is to send the keys in lower case separated with \"underscore\". If not sent, the system automatically converts them.","default":"","type":"object","name":"subscriber.properties","in":"body"},{"_id":"552c4d56d9f89e0d0015a5de","ref":"","required":false,"desc":"One or more contacts. Each contact should be a hash/object with contact_type and contact_value attributes, subscription_status is optional and defaults to \"active\". The attributes contact_type can be either \"email\" or \"phone\". If the contact_type is an email, it should satisfy the standard email format validations. If the contact_type is a phone, it should be sent in the ISO E.164 format with the \"+\" symbol followed by the country code and then the number. The \"subscirption_status\" attribute can be used to unsubscribe the contact by sending its value as \"inactive\"","default":"","type":"array_mixed","name":"subscriber.contacts","in":"body"}],"url":"/subscribers"},"body":"","category":"571f6666e2b7000e0091c57d","createdAt":"2015-04-13T22:49:23.071Z","editedParams":true,"editedParams2":true,"excerpt":"Create a user in your account. Returns 409 if the user already exists.","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":6,"project":"552c21677820b80d00aa4ec5","slug":"subscribers-create","sync_unique":"","title":"Add a user","type":"post","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

postAdd a user

Create a user in your account. Returns 409 if the user already exists.

Body JSON

subscriber.uid:
required
string
Unique ID of the user. This should almost always be same as the unique ID that you use in your system. It could be an email, phone number or a random string generated by your system as long as it is unique and can be used to uniquely identify a user.
subscriber.first_name:
string
First name of the user
subscriber.last_name:
string
Last name of the user
subscriber.name:
string
Full name of the user. Defaults to the combination of first_name and last_name if not provided.
subscriber.signed_up_at:
datetime
Should be in ISO8601 format. Example: 2015-01-02T05:30:21Z. Defaults to current timestamp in UTC if not provided.
subscriber.properties:
object
Name-value pairs of additional attributes you'd like to associate with the user. You can send a nested hash of basic key-value pairs. General convention is to send the keys in lower case separated with "underscore". If not sent, the system automatically converts them.
subscriber.contacts:
array of mixed
One or more contacts. Each contact should be a hash/object with contact_type and contact_value attributes, subscription_status is optional and defaults to "active". The attributes contact_type can be either "email" or "phone". If the contact_type is an email, it should satisfy the standard email format validations. If the contact_type is a phone, it should be sent in the ISO E.164 format with the "+" symbol followed by the country code and then the number. The "subscirption_status" attribute can be used to unsubscribe the contact by sending its value as "inactive"

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}

Definition

{{ api_url }}{{ page_api_url }}

Examples


Result Format



{"__v":0,"_id":"571f6666e2b7000e0091c589","api":{"examples":{"codes":[{"name":"subscribers-find-request","code":"GET https://api.nudgespot.com/201507/subscribers?uid=frodo.baggins","language":"json"}]},"results":{"codes":[{"status":200,"language":"json","code":"{\n  \"href\":\"https://api.nudgespot.com/201507/subscribers/954\",\n  \"id\":954,\n  \"uid\":\"frodo.baggins\",\n  \"first_name\":\"Frodo\",\n  \"last_name\":\"Baggins\",\n  \"name\":\"Frodo T. Baggins\",\n  \"signed_up_at\":\"2015-07-01T09:30:00Z\",\n  \"properties\":{\n    \"address\":{\n      \"postal_code\":\"SH9087\",\n      \"state\":\"Shire\",\n      \"address_line\":\"Bag End\",\n      \"country\":\"Middle Earth\",\n      \"city\":\"Hobbiton\"\n    },\n    \"age\":53,\n    \"gender\":\"male\",\n    \"last_opened\":null,\n    \"last_clicked\":null,\n    \"last_contact\":null,\n    \"last_seen\":null\n  },\n  \"contacts\":[\n    {\n      \"href\":\"https://api.nudgespot.com/201507/subscriber_contacts/1079\",\n      \"id\":1079,\n      \"contact_type\":\"email\",\n      \"contact_value\":\"frodo.baggins@bagend.com\",\n      \"subscription_status\":\"new\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    },\n    {\n      \"href\":\"https://api.nudgespot.com/201507/subscriber_contacts/1080\",\n      \"id\":1080,\n      \"contact_type\":\"phone\",\n      \"contact_value\":\"+1234567890\",\n      \"subscription_status\":\"active\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    }\n  ]\n}","name":null},{"code":"{\"uid\":\"User does not exist\"}","language":"json","status":404}]},"settings":"55a6b400112cf20d003a30d2","auth":"required","params":[{"_id":"552c472ed9f89e0d0015a5c5","ref":"","required":true,"desc":"Search for users with the specified user uid. The value should be URL encoded.","default":"","type":"string","name":"uid","in":"query"}],"url":"/subscribers"},"body":"","category":"571f6666e2b7000e0091c57d","createdAt":"2015-04-13T22:44:45.260Z","editedParams":true,"editedParams2":true,"excerpt":"Search for a user by her uid.","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":7,"project":"552c21677820b80d00aa4ec5","slug":"subscribers","sync_unique":"","title":"Find a user","type":"get","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

getFind a user

Search for a user by her uid.

Query Params

uid:
required
string
Search for users with the specified user uid. The value should be URL encoded.

User Information

Try It Out

get
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}

Definition

{{ api_url }}{{ page_api_url }}

Examples


Result Format



{"__v":0,"_id":"571f6666e2b7000e0091c58a","api":{"examples":{"codes":[{"language":"json","code":"{\n  \"subscriber\":{\n    \"name\":\"Frodo B. Baggins\",\n    \"properties\":{\n      \"mission\":\"destroy_the_ring\",\n      \"team\":\"the_fellowship\"\n    }\n  }\n}","name":"subscriber-update-request"}]},"results":{"codes":[{"name":"","code":"{\n  \"href\":\"http://localhost:3000/201507/subscribers/954\",\n  \"id\":954,\n  \"uid\":\"frodo.baggins\",\n  \"first_name\":\"Frodo\",\n  \"last_name\":\"Baggins\",\n  \"name\":\"Frodo B. Baggins\",\n  \"signed_up_at\":\"2015-07-01T09:30:00Z\",\n  \"properties\":{\n    \"last_opened\":null,\n    \"last_clicked\":null,\n    \"team\":\"the_fellowship\",\n    \"last_contact\":null,\n    \"address\":{\n      \"postal_code\":\"SH9087\",\n      \"state\":\"Shire\",\n      \"address_line\":\"Bag End\",\n      \"country\":\"Middle Earth\",\n      \"city\":\"Hobbiton\"\n    },\n    \"mission\":\"destroy_the_ring\",\n    \"age\":53.0,\n    \"gender\":\"male\",\n    \"last_seen\":null\n  },\n  \"contacts\":[\n    {\n      \"href\":\"http://localhost:3000/201507/subscriber_contacts/1079\",\n      \"id\":1079,\n      \"contact_type\":\"email\",\n      \"contact_value\":\"frodo.baggins@bagend.com\",\n      \"subscription_status\":\"new\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    },\n    {\n      \"href\":\"http://localhost:3000/201507/subscriber_contacts/1080\",\n      \"id\":1080,\n      \"contact_type\":\"phone\",\n      \"contact_value\":\"+1234567890\",\n      \"subscription_status\":\"active\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    }\n  ]\n}","language":"json","status":200},{"code":"{\"uid\":\"User not found\"}","language":"text","status":404}]},"settings":"55a6b400112cf20d003a30d2","auth":"required","params":[{"_id":"552c5183a8112f0d0090c717","ref":"","required":false,"desc":"First name of the user","default":"","type":"string","name":"subscriber.first_name","in":"body"},{"_id":"552c5183a8112f0d0090c716","ref":"","required":false,"desc":"Last name of the user","default":"","type":"string","name":"subscriber.last_name","in":"body"},{"_id":"55aa3a0d3be8f60d00041d2d","ref":"","required":false,"desc":"Full name of the user. Defaults to the combination of first_name and last_name if not provided.","default":"","type":"string","name":"subscriber.name","in":"body"},{"_id":"552c5183a8112f0d0090c715","ref":"","required":false,"desc":"Should be in ISO8601 format. Example: 2015-01-02T05:30:21Z. Defaults to current timestamp in UTC if not provided.","default":"","type":"datetime","name":"subscriber.signed_up_at","in":"body"},{"_id":"552c5183a8112f0d0090c714","ref":"","required":false,"desc":"Name-value pairs of additional attributes you'd like to associate with the user. You can send a nested hash of basic key-value pairs. General convention is to send the keys in lower case separated with \"underscore\". If not sent, the system automatically converts them.","default":"","type":"object","name":"subscriber.properties","in":"body"},{"_id":"552c5183a8112f0d0090c713","ref":"","required":false,"desc":"One or more contacts. Each contact should be a hash/object with contact_type and contact_value attributes, subscription_status is optional and defaults to \"active\". The attributes contact_type can be either \"email\" or \"phone\". If the contact_type is an email, it should satisfy the standard email format validations. If the contact_type is a phone, it should be sent in the ISO E.164 format with the \"+\" symbol followed by the country code and then the number. The \"subscirption_status\" attribute can be used to unsubscribe the contact by sending its value as \"inactive\"","default":"","type":"array_mixed","name":"subscriber.contact","in":"body"}],"url":"/subscribers/:id"},"body":"","category":"571f6666e2b7000e0091c57d","createdAt":"2015-04-13T23:25:52.455Z","editedParams":true,"editedParams2":true,"excerpt":"Update a user already present in your account","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":8,"project":"552c21677820b80d00aa4ec5","slug":"subscribersid","sync_unique":"","title":"Update a user","type":"put","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

putUpdate a user

Update a user already present in your account

Body JSON

subscriber.first_name:
string
First name of the user
subscriber.last_name:
string
Last name of the user
subscriber.name:
string
Full name of the user. Defaults to the combination of first_name and last_name if not provided.
subscriber.signed_up_at:
datetime
Should be in ISO8601 format. Example: 2015-01-02T05:30:21Z. Defaults to current timestamp in UTC if not provided.
subscriber.properties:
object
Name-value pairs of additional attributes you'd like to associate with the user. You can send a nested hash of basic key-value pairs. General convention is to send the keys in lower case separated with "underscore". If not sent, the system automatically converts them.
subscriber.contact:
array of mixed
One or more contacts. Each contact should be a hash/object with contact_type and contact_value attributes, subscription_status is optional and defaults to "active". The attributes contact_type can be either "email" or "phone". If the contact_type is an email, it should satisfy the standard email format validations. If the contact_type is a phone, it should be sent in the ISO E.164 format with the "+" symbol followed by the country code and then the number. The "subscirption_status" attribute can be used to unsubscribe the contact by sending its value as "inactive"

User Information

Try It Out

put
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}

Definition

{{ api_url }}{{ page_api_url }}

Examples


Result Format



{"__v":0,"_id":"571f6666e2b7000e0091c58b","api":{"examples":{"codes":[{"language":"json","code":"{\n  \"subscriber\":{\n    \"uid\":\"frodo.baggins\",\n    \"first_name\":\"Frodo\",\n    \"last_name\":\"Baggins\",\n    \"name\":\"Frodo T. Baggins\",\n    \"signed_up_at\":\"2015-07-01T09:30:00Z\",\n    \"properties\":{\n      \"gender\":\"male\",\n      \"age\":53,\n      \"address\":{\n        \"address_line\":\"Bag End\",\n        \"city\":\"Hobbiton\",\n        \"state\":\"Shire\",\n        \"postal_code\":\"SH9087\",\n        \"country\":\"Middle Earth\"\n      }\n    },\n    \"contacts\":[\n      {\n        \"contact_type\":\"email\",\n        \"contact_value\":\"frodo.baggins@bagend.com\",\n        \"subscription_status\":\"active\"\n      },\n      {\n        \"contact_type\":\"phone\",\n        \"contact_value\":\"+12345678900\",\n        \"subscription_status\":\"active\"\n      }\n    ]\n  }\n}","name":"subscriber-identify-request"}]},"results":{"codes":[{"name":"","code":"{\n  \"href\":\"https://api.nudgespot.com/201507/subscribers/954\",\n  \"id\":954,\n  \"uid\":\"frodo.baggins\",\n  \"first_name\":\"Frodo\",\n  \"last_name\":\"Baggins\",\n  \"name\":\"Frodo T. Baggins\",\n  \"signed_up_at\":\"2015-07-01T09:30:00Z\",\n  \"properties\":{\n    \"address\":{\n      \"postal_code\":\"SH9087\",\n      \"state\":\"Shire\",\n      \"address_line\":\"Bag End\",\n      \"country\":\"Middle Earth\",\n      \"city\":\"Hobbiton\"\n    },\n    \"age\":53,\n    \"gender\":\"male\",\n    \"last_opened\":null,\n    \"last_clicked\":null,\n    \"last_contact\":null,\n    \"last_seen\":null\n  },\n  \"contacts\":[\n    {\n      \"href\":\"https://api.nudgespot.com/201507/subscriber_contacts/1079\",\n      \"id\":1079,\n      \"contact_type\":\"email\",\n      \"contact_value\":\"frodo.baggins@bagend.com\",\n      \"subscription_status\":\"new\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    },\n    {\n      \"href\":\"https://api.nudgespot.com/201507/subscriber_contacts/1080\",\n      \"id\":1080,\n      \"contact_type\":\"phone\",\n      \"contact_value\":\"+1234567890\",\n      \"subscription_status\":\"active\",\n      \"subscriber_id\":954,\n      \"account_id\":5\n    }\n  ]\n}","language":"json","status":200}]},"settings":"55a6b400112cf20d003a30d2","auth":"required","params":[{"_id":"552c472ed9f89e0d0015a5c5","ref":"","required":true,"desc":"Unique ID of the user. This should almost always be same as the unique ID that you use in your system. It could be an email, phone number or a random string generated by your system as long as it is unique and can be used to uniquely identify a user.","default":"","type":"string","name":"subscriber.uid","in":"body"},{"_id":"552c4c8ed9f89e0d0015a5db","ref":"","required":false,"desc":"First name of the user","default":"","type":"string","name":"subscriber.first_name","in":"body"},{"_id":"552c4d56d9f89e0d0015a5e0","ref":"","required":false,"desc":"Last name of the user","default":"","type":"string","name":"subscriber.last_name","in":"body"},{"_id":"55a6b7885ca7b41700e13268","ref":"","required":false,"desc":"Full name of the user. Defaults to the combination of first_name and last_name if not provided.","default":"","type":"string","name":"subscriber.name","in":"body"},{"_id":"552c4d56d9f89e0d0015a5df","ref":"","required":false,"desc":"Should be in ISO8601 format. Example: 2015-01-02T05:30:21Z. Defaults to current timestamp in UTC if not provided.","default":"","type":"datetime","name":"subscriber.signed_up_at","in":"body"},{"_id":"552c4d56d9f89e0d0015a5dd","ref":"","required":false,"desc":"Name-value pairs of additional attributes you'd like to associate with the user. You can send a nested hash of basic key-value pairs. General convention is to send the keys in lower case separated with \"underscore\". If not sent, the system automatically converts them.","default":"","type":"object","name":"subscriber.properties","in":"body"},{"_id":"552c4d56d9f89e0d0015a5de","ref":"","required":false,"desc":"One or more contacts. Each contact should be a hash/object with contact_type and contact_value attributes, subscription_status is optional and defaults to \"active\". The attributes contact_type can be either \"email\" or \"phone\". If the contact_type is an email, it should satisfy the standard email format validations. If the contact_type is a phone, it should be sent in the ISO E.164 format with the \"+\" symbol followed by the country code and then the number. The \"subscirption_status\" attribute can be used to unsubscribe the contact by sending its value as \"inactive\"","default":"","type":"array_mixed","name":"subscriber.contacts","in":"body"}],"url":"/subscribers/identify"},"body":"","category":"571f6666e2b7000e0091c57d","createdAt":"2015-07-22T16:42:56.342Z","editedParams":true,"editedParams2":true,"excerpt":"Create a user in your account or update it if it already exists","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":9,"project":"552c21677820b80d00aa4ec5","slug":"create-or-update-a-user","sync_unique":"","title":"Identify a user","type":"post","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

postIdentify a user

Create a user in your account or update it if it already exists

Body JSON

subscriber.uid:
required
string
Unique ID of the user. This should almost always be same as the unique ID that you use in your system. It could be an email, phone number or a random string generated by your system as long as it is unique and can be used to uniquely identify a user.
subscriber.first_name:
string
First name of the user
subscriber.last_name:
string
Last name of the user
subscriber.name:
string
Full name of the user. Defaults to the combination of first_name and last_name if not provided.
subscriber.signed_up_at:
datetime
Should be in ISO8601 format. Example: 2015-01-02T05:30:21Z. Defaults to current timestamp in UTC if not provided.
subscriber.properties:
object
Name-value pairs of additional attributes you'd like to associate with the user. You can send a nested hash of basic key-value pairs. General convention is to send the keys in lower case separated with "underscore". If not sent, the system automatically converts them.
subscriber.contacts:
array of mixed
One or more contacts. Each contact should be a hash/object with contact_type and contact_value attributes, subscription_status is optional and defaults to "active". The attributes contact_type can be either "email" or "phone". If the contact_type is an email, it should satisfy the standard email format validations. If the contact_type is a phone, it should be sent in the ISO E.164 format with the "+" symbol followed by the country code and then the number. The "subscirption_status" attribute can be used to unsubscribe the contact by sending its value as "inactive"

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}

Definition

{{ api_url }}{{ page_api_url }}

Examples


Result Format



{"__v":0,"_id":"571f6666e2b7000e0091c58c","api":{"examples":{"codes":[{"name":"activity-track-request","code":"{\n  \"activity\":{\n    \"subscriber\":{\n      \"uid\":\"frodo.baggins\"\n    },\n    \"event\":\"ring_destroyed\",\n    \"timestamp\":\"2015-07-15T19:30:00Z\",\n    \"properties\":{\n      \"location\":\"mount_doom\",\n      \"ring_owner\":\"sauron\"\n    }\n  }\n}","language":"json"}]},"results":{"codes":[{"name":"","code":"{\n  \"event\":\"ring_destroyed\",\n  \"timestamp\":\"2015-07-15T19:30:00.000Z\",\n  \"properties\":{\n    \"location\":\"mount_doom\",\n    \"ring_owner\":\"sauron\"\n  },\n  \"account\":{\n    \"id\":5,\n    \"api_key\":\"00419cc2eabfbc719c62c64a041f76b6\"\n  },\n  \"subscriber\":{\n    \"id\":954,\n    \"uid\":\"frodo.baggins\"\n  }\n}","language":"json","status":200}]},"settings":"55a6b400112cf20d003a30d2","auth":"required","params":[{"_id":"552c472ed9f89e0d0015a5c5","ref":"","required":true,"desc":"Unique ID of the user who performed the activity. This is the same UID that you use to identify your users and must have sent as part of the \"uid\" property while creating the user.","default":"","type":"string","name":"activity.subscriber.uid","in":"body"},{"_id":"55aa428a5d3abb0d0012f3a9","ref":"","required":true,"desc":"Name of the activity. You can refer to this name when searching for activities or in the message.","default":"","type":"string","name":"activity.event","in":"body"},{"_id":"55aa435af078970d00c7c0a4","ref":"","required":false,"desc":"Time of the activity. Should be sent in ISO8601 format. Defaults to current timestamp if not specified.","default":"","type":"datetime","name":"activity.timestamp","in":"body"},{"_id":"55aa435af078970d00c7c0a3","ref":"","required":false,"desc":"Name-value pairs of additional attributes you'd like to associate with the activity. You can send a nested hash of basic name-value pairs. General convention is to send the keys in lower case separated with \"underscore\". If not sent, the system automatically converts them.","default":"","type":"object","name":"activity.properties","in":"body"}],"url":"/activities"},"body":"","category":"571f6666e2b7000e0091c57d","createdAt":"2015-07-18T11:58:32.944Z","editedParams":true,"editedParams2":true,"excerpt":"Send an activity done by a user","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":10,"project":"552c21677820b80d00aa4ec5","slug":"track-an-activity","sync_unique":"","title":"Track an activity","type":"post","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

postTrack an activity

Send an activity done by a user

Body JSON

activity.subscriber.uid:
required
string
Unique ID of the user who performed the activity. This is the same UID that you use to identify your users and must have sent as part of the "uid" property while creating the user.
activity.event:
required
string
Name of the activity. You can refer to this name when searching for activities or in the message.
activity.timestamp:
datetime
Time of the activity. Should be sent in ISO8601 format. Defaults to current timestamp if not specified.
activity.properties:
object
Name-value pairs of additional attributes you'd like to associate with the activity. You can send a nested hash of basic name-value pairs. General convention is to send the keys in lower case separated with "underscore". If not sent, the system automatically converts them.

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}

Definition

{{ api_url }}{{ page_api_url }}

Examples


Result Format



{"__v":14,"_id":"571f6666e2b7000e0091c581","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"**Prerequisite**:\n* Google Play Services should be included. If not, follow the instructions **[here](https://developer.android.com/google/play-services/setup.html)**.\n* Google Cloud Platform Account with Google Cloud Messaging enabled\n\n**Download**: You can download the library from **[here](https://s3.amazonaws.com/images.nudgespot.com/sdk/android/nudgespot-release-V3.1.2.aar)** and import it into your Android project.\n\n**Configuration**:\n* Go to your account settings in **[Nudgespot](https://app.nudgespot.com)** and update your GCM provider details (GCM Sender ID & GCM API Key)\n\n**Instructions**: *Update your AndroidManifest.xml with the following:*\n* Note: In the following two steps, replace <your_application_package> with your actual application package name.\n* Add the following permissions directly under the manifest root. Chances are you already have some of them. You can skip those.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.INTERNET\\\" />\\n<uses-permission android:name=\\\"android.permission.GET_ACCOUNTS\\\" />\\n<uses-permission android:name=\\\"android.permission.WAKE_LOCK\\\" />\\n<uses-permission android:name=\\\"com.google.android.c2dm.permission.RECEIVE\\\" />\\n<permission android:name=\\\"<your_application_package>.permission.C2D_MESSAGE\\\" android:protectionLevel=\\\"signature\\\" />\\n<uses-permission android:name=\\\"your_application_package>.permission.C2D_MESSAGE\\\" />\",\n      \"language\": \"xml\",\n      \"name\": \"android-permissions\"\n    }\n  ]\n}\n[/block]\n* Add the following under the “application” element. The receiver “com.nudgespot.notification.GcmBroadcastReceiver” below does the task of receiving the push notifications from the Nudgespot system through the GCM server. It then delegates the task of displaying/managing the notification to the service class “com.nudgespot.notification.GcmIntentService”. The activity “com.nudgespot.notification.ReceiverActivity” is launched when the user clicks on the notification and passes the data to the launch activity of your application. This activity is just a pass through and is never displayed to the end user.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver\\n     android:name=\\\"com.nudgespot.notification.MessageReceiver\\\"\\n     android:exported=\\\"true\\\"\\n     android:permission=\\\"com.google.android.c2dm.permission.SEND\\\">\\n    <intent-filter android:priority=\\\"1\\\">\\n        <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\"/>\\n        <action android:name=\\\"com.google.android.c2dm.intent.REGISTRATION\\\" />\\n        <category android:name=\\\"com.nudgespot.gcmdemo\\\"/>\\n    </intent-filter>\\n</receiver>\\n<service\\n     android:name=\\\"com.nudgespot.notification.MessageProcessor\\\"\\n     android:exported=\\\"false\\\">\\n    <intent-filter>\\n        <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\"/>\\n    </intent-filter>\\n</service>\\n<service android:name=\\\"com.nudgespot.api.NudgespotClient$NudgespotInstanceIDListenerService\\\"\\n     android:exported=\\\"false\\\">\\n    <intent-filter>\\n        <action android:name=\\\"com.google.android.gms.iid.InstanceID\\\"/>\\n    </intent-filter>\\n</service>\\n<activity\\n     android:name=\\\"com.nudgespot.notification.ReceiverActivity\\\"\\n     android:theme=\\\"@android:style/Theme.NoDisplay\\\">\\n</activity>\",\n      \"language\": \"xml\",\n      \"name\": \"android-receiver\"\n    }\n  ]\n}\n[/block]","category":"571f6666e2b7000e0091c57e","createdAt":"2015-07-24T18:14:10.679Z","excerpt":"Integrating the Nudgespot Android library","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":19,"project":"552c21677820b80d00aa4ec5","slug":"android-getting-started","sync_unique":"","title":"Getting Started","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Getting Started

Integrating the Nudgespot Android library

**Prerequisite**: * Google Play Services should be included. If not, follow the instructions **[here](https://developer.android.com/google/play-services/setup.html)**. * Google Cloud Platform Account with Google Cloud Messaging enabled **Download**: You can download the library from **[here](https://s3.amazonaws.com/images.nudgespot.com/sdk/android/nudgespot-release-V3.1.2.aar)** and import it into your Android project. **Configuration**: * Go to your account settings in **[Nudgespot](https://app.nudgespot.com)** and update your GCM provider details (GCM Sender ID & GCM API Key) **Instructions**: *Update your AndroidManifest.xml with the following:* * Note: In the following two steps, replace <your_application_package> with your actual application package name. * Add the following permissions directly under the manifest root. Chances are you already have some of them. You can skip those. [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.INTERNET\" />\n<uses-permission android:name=\"android.permission.GET_ACCOUNTS\" />\n<uses-permission android:name=\"android.permission.WAKE_LOCK\" />\n<uses-permission android:name=\"com.google.android.c2dm.permission.RECEIVE\" />\n<permission android:name=\"<your_application_package>.permission.C2D_MESSAGE\" android:protectionLevel=\"signature\" />\n<uses-permission android:name=\"your_application_package>.permission.C2D_MESSAGE\" />", "language": "xml", "name": "android-permissions" } ] } [/block] * Add the following under the “application” element. The receiver “com.nudgespot.notification.GcmBroadcastReceiver” below does the task of receiving the push notifications from the Nudgespot system through the GCM server. It then delegates the task of displaying/managing the notification to the service class “com.nudgespot.notification.GcmIntentService”. The activity “com.nudgespot.notification.ReceiverActivity” is launched when the user clicks on the notification and passes the data to the launch activity of your application. This activity is just a pass through and is never displayed to the end user. [block:code] { "codes": [ { "code": "<receiver\n android:name=\"com.nudgespot.notification.MessageReceiver\"\n android:exported=\"true\"\n android:permission=\"com.google.android.c2dm.permission.SEND\">\n <intent-filter android:priority=\"1\">\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\"/>\n <action android:name=\"com.google.android.c2dm.intent.REGISTRATION\" />\n <category android:name=\"com.nudgespot.gcmdemo\"/>\n </intent-filter>\n</receiver>\n<service\n android:name=\"com.nudgespot.notification.MessageProcessor\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\"/>\n </intent-filter>\n</service>\n<service android:name=\"com.nudgespot.api.NudgespotClient$NudgespotInstanceIDListenerService\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.google.android.gms.iid.InstanceID\"/>\n </intent-filter>\n</service>\n<activity\n android:name=\"com.nudgespot.notification.ReceiverActivity\"\n android:theme=\"@android:style/Theme.NoDisplay\">\n</activity>", "language": "xml", "name": "android-receiver" } ] } [/block]
**Prerequisite**: * Google Play Services should be included. If not, follow the instructions **[here](https://developer.android.com/google/play-services/setup.html)**. * Google Cloud Platform Account with Google Cloud Messaging enabled **Download**: You can download the library from **[here](https://s3.amazonaws.com/images.nudgespot.com/sdk/android/nudgespot-release-V3.1.2.aar)** and import it into your Android project. **Configuration**: * Go to your account settings in **[Nudgespot](https://app.nudgespot.com)** and update your GCM provider details (GCM Sender ID & GCM API Key) **Instructions**: *Update your AndroidManifest.xml with the following:* * Note: In the following two steps, replace <your_application_package> with your actual application package name. * Add the following permissions directly under the manifest root. Chances are you already have some of them. You can skip those. [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.INTERNET\" />\n<uses-permission android:name=\"android.permission.GET_ACCOUNTS\" />\n<uses-permission android:name=\"android.permission.WAKE_LOCK\" />\n<uses-permission android:name=\"com.google.android.c2dm.permission.RECEIVE\" />\n<permission android:name=\"<your_application_package>.permission.C2D_MESSAGE\" android:protectionLevel=\"signature\" />\n<uses-permission android:name=\"your_application_package>.permission.C2D_MESSAGE\" />", "language": "xml", "name": "android-permissions" } ] } [/block] * Add the following under the “application” element. The receiver “com.nudgespot.notification.GcmBroadcastReceiver” below does the task of receiving the push notifications from the Nudgespot system through the GCM server. It then delegates the task of displaying/managing the notification to the service class “com.nudgespot.notification.GcmIntentService”. The activity “com.nudgespot.notification.ReceiverActivity” is launched when the user clicks on the notification and passes the data to the launch activity of your application. This activity is just a pass through and is never displayed to the end user. [block:code] { "codes": [ { "code": "<receiver\n android:name=\"com.nudgespot.notification.MessageReceiver\"\n android:exported=\"true\"\n android:permission=\"com.google.android.c2dm.permission.SEND\">\n <intent-filter android:priority=\"1\">\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\"/>\n <action android:name=\"com.google.android.c2dm.intent.REGISTRATION\" />\n <category android:name=\"com.nudgespot.gcmdemo\"/>\n </intent-filter>\n</receiver>\n<service\n android:name=\"com.nudgespot.notification.MessageProcessor\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\"/>\n </intent-filter>\n</service>\n<service android:name=\"com.nudgespot.api.NudgespotClient$NudgespotInstanceIDListenerService\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.google.android.gms.iid.InstanceID\"/>\n </intent-filter>\n</service>\n<activity\n android:name=\"com.nudgespot.notification.ReceiverActivity\"\n android:theme=\"@android:style/Theme.NoDisplay\">\n</activity>", "language": "xml", "name": "android-receiver" } ] } [/block]
{"__v":3,"_id":"571f6666e2b7000e0091c582","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"* Initializing the client: Somewhere in your launcher activity (onResume method preferably) you can create a private static instance of the Nudgespot GcmClient (referred to as nsClient in the code sample below). This step only initializes the client with your credentials.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"this.nsClient = NudgespotClient.getClient(new NudgespotCredentials(\\\"<your_javascript_api_key\\\", \\\"your_rest_api_key\\\"), this);\",\n      \"language\": \"java\",\n      \"name\": \"android-authenticate\"\n    }\n  ]\n}\n[/block]\n* Wherever in the application, your user logs in, you can identify the user as below. The user id is the unique id that you send to Nudgespot for identifying that user, and is most likely the email address of the user but could be the phone number or the database primary key. This step also registers the user for push notifications with the GCM server in background. In case of anonymous users, you can call initialize() without the userId and the library internally generates a unique random string for the user.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if (userId != null && !userId.isEmpty()) {\\n  this.nsClient.initialize(userId);\\n} else {\\n  this.nsClient.initialize();\\n}\",\n      \"language\": \"java\",\n      \"name\": \"android-initialize\"\n    }\n  ]\n}\n[/block]\n* Further, when the user is anonymous and logs in later, you can identify the user by calling the same initialize() method with the userId. This action, will move the complete history of the anonymous user to the identified user.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public void doLogin(String userId, String password) {\\n  // your code related to login\\n  // on successful login\\n  this.nsClient.initialize(userId);\\n}\",\n      \"language\": \"java\",\n      \"name\": \"android-initialize-login\"\n    }\n  ]\n}\n[/block]\n* You can also initialize the user with the NudgespotSubscriber object. Using the object gives you flexibility to pass additional details about the user such as their profile properties.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NudgespotSubscriber subscriber = new NudgespotSubscriber(user_id);\\nJSONObject props = new JSONObject();\\nprops.put(“gender”, “female”);\\nsubscriber.setProperties(props);\\nthis.mGcmClient.initialize(subscriber);\",\n      \"language\": \"java\",\n      \"name\": \"android-subscriber-initialize\"\n    }\n  ]\n}\n[/block]\n* Now you can track the users by just calling the “track” method on the client as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NudgespotActivity activity = new NudgespotActivity(\\\"enroll_course\\\");\\nJSONObject properties = new JSONObject();\\nproperties.put(\\\"course_name\\\", courseName);\\nactivity.setProperties(properties);\\nthis.mGcmClient.track(activity);\",\n      \"language\": \"java\",\n      \"name\": \"android-track\"\n    }\n  ]\n}\n[/block]\n* Finally, when your user logs out, you should remove that device association as:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"this.mGcmClient.clearRegistration();\",\n      \"language\": \"java\",\n      \"name\": \"android-unregister\"\n    }\n  ]\n}\n[/block]","category":"571f6666e2b7000e0091c57e","createdAt":"2015-07-24T18:24:34.739Z","excerpt":"Instructions on how to use the Nudgespot Android library","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":20,"project":"552c21677820b80d00aa4ec5","slug":"android-using-library","sync_unique":"","title":"Using the library","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Using the library

Instructions on how to use the Nudgespot Android library

* Initializing the client: Somewhere in your launcher activity (onResume method preferably) you can create a private static instance of the Nudgespot GcmClient (referred to as nsClient in the code sample below). This step only initializes the client with your credentials. [block:code] { "codes": [ { "code": "this.nsClient = NudgespotClient.getClient(new NudgespotCredentials(\"<your_javascript_api_key\", \"your_rest_api_key\"), this);", "language": "java", "name": "android-authenticate" } ] } [/block] * Wherever in the application, your user logs in, you can identify the user as below. The user id is the unique id that you send to Nudgespot for identifying that user, and is most likely the email address of the user but could be the phone number or the database primary key. This step also registers the user for push notifications with the GCM server in background. In case of anonymous users, you can call initialize() without the userId and the library internally generates a unique random string for the user. [block:code] { "codes": [ { "code": "if (userId != null && !userId.isEmpty()) {\n this.nsClient.initialize(userId);\n} else {\n this.nsClient.initialize();\n}", "language": "java", "name": "android-initialize" } ] } [/block] * Further, when the user is anonymous and logs in later, you can identify the user by calling the same initialize() method with the userId. This action, will move the complete history of the anonymous user to the identified user. [block:code] { "codes": [ { "code": "public void doLogin(String userId, String password) {\n // your code related to login\n // on successful login\n this.nsClient.initialize(userId);\n}", "language": "java", "name": "android-initialize-login" } ] } [/block] * You can also initialize the user with the NudgespotSubscriber object. Using the object gives you flexibility to pass additional details about the user such as their profile properties. [block:code] { "codes": [ { "code": "NudgespotSubscriber subscriber = new NudgespotSubscriber(user_id);\nJSONObject props = new JSONObject();\nprops.put(“gender”, “female”);\nsubscriber.setProperties(props);\nthis.mGcmClient.initialize(subscriber);", "language": "java", "name": "android-subscriber-initialize" } ] } [/block] * Now you can track the users by just calling the “track” method on the client as follows: [block:code] { "codes": [ { "code": "NudgespotActivity activity = new NudgespotActivity(\"enroll_course\");\nJSONObject properties = new JSONObject();\nproperties.put(\"course_name\", courseName);\nactivity.setProperties(properties);\nthis.mGcmClient.track(activity);", "language": "java", "name": "android-track" } ] } [/block] * Finally, when your user logs out, you should remove that device association as: [block:code] { "codes": [ { "code": "this.mGcmClient.clearRegistration();", "language": "java", "name": "android-unregister" } ] } [/block]
* Initializing the client: Somewhere in your launcher activity (onResume method preferably) you can create a private static instance of the Nudgespot GcmClient (referred to as nsClient in the code sample below). This step only initializes the client with your credentials. [block:code] { "codes": [ { "code": "this.nsClient = NudgespotClient.getClient(new NudgespotCredentials(\"<your_javascript_api_key\", \"your_rest_api_key\"), this);", "language": "java", "name": "android-authenticate" } ] } [/block] * Wherever in the application, your user logs in, you can identify the user as below. The user id is the unique id that you send to Nudgespot for identifying that user, and is most likely the email address of the user but could be the phone number or the database primary key. This step also registers the user for push notifications with the GCM server in background. In case of anonymous users, you can call initialize() without the userId and the library internally generates a unique random string for the user. [block:code] { "codes": [ { "code": "if (userId != null && !userId.isEmpty()) {\n this.nsClient.initialize(userId);\n} else {\n this.nsClient.initialize();\n}", "language": "java", "name": "android-initialize" } ] } [/block] * Further, when the user is anonymous and logs in later, you can identify the user by calling the same initialize() method with the userId. This action, will move the complete history of the anonymous user to the identified user. [block:code] { "codes": [ { "code": "public void doLogin(String userId, String password) {\n // your code related to login\n // on successful login\n this.nsClient.initialize(userId);\n}", "language": "java", "name": "android-initialize-login" } ] } [/block] * You can also initialize the user with the NudgespotSubscriber object. Using the object gives you flexibility to pass additional details about the user such as their profile properties. [block:code] { "codes": [ { "code": "NudgespotSubscriber subscriber = new NudgespotSubscriber(user_id);\nJSONObject props = new JSONObject();\nprops.put(“gender”, “female”);\nsubscriber.setProperties(props);\nthis.mGcmClient.initialize(subscriber);", "language": "java", "name": "android-subscriber-initialize" } ] } [/block] * Now you can track the users by just calling the “track” method on the client as follows: [block:code] { "codes": [ { "code": "NudgespotActivity activity = new NudgespotActivity(\"enroll_course\");\nJSONObject properties = new JSONObject();\nproperties.put(\"course_name\", courseName);\nactivity.setProperties(properties);\nthis.mGcmClient.track(activity);", "language": "java", "name": "android-track" } ] } [/block] * Finally, when your user logs out, you should remove that device association as: [block:code] { "codes": [ { "code": "this.mGcmClient.clearRegistration();", "language": "java", "name": "android-unregister" } ] } [/block]
{"__v":7,"_id":"571f6666e2b7000e0091c595","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"**Prerequisite**:\n* iOS 7.x  and upwards\n* Firebase Cloud Platform Account with Firebase Cloud Messaging enabled\n\n**Installation using CocoaPods**\n* Add the Nudgespot pod into your Podfile `pod 'Nudgespot'` and run `pod install`\n\n**Configuration**:\n* Go to your Firebase Cloud Messaging **[account](https://console.firebase.google.com/)** and configure your GCM account to send iOS push notification. You can do so by clicking on 'Get A Configuration File', followed by uploading your Apple Push Notification certificates and the app bundle id. This process will generate a project id and a server key in your Google Developers account. Note: You can use the same project in case you have already been using one for Android push notifications.\n* Download GoogleService-Info.plist file into your Xcode project bundle.\n* Go to your account settings in **[Nudgespot](https://app.nudgespot.com)** and update your GCM provider details (GCM Sender ID & GCM API Key)","category":"571f6666e2b7000e0091c57f","createdAt":"2016-04-05T10:11:47.787Z","excerpt":"Integrating the Nudgespot iOS Library","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":21,"project":"552c21677820b80d00aa4ec5","slug":"ios-getting-started","sync_unique":"","title":"Getting Started","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Getting Started

Integrating the Nudgespot iOS Library

**Prerequisite**: * iOS 7.x and upwards * Firebase Cloud Platform Account with Firebase Cloud Messaging enabled **Installation using CocoaPods** * Add the Nudgespot pod into your Podfile `pod 'Nudgespot'` and run `pod install` **Configuration**: * Go to your Firebase Cloud Messaging **[account](https://console.firebase.google.com/)** and configure your GCM account to send iOS push notification. You can do so by clicking on 'Get A Configuration File', followed by uploading your Apple Push Notification certificates and the app bundle id. This process will generate a project id and a server key in your Google Developers account. Note: You can use the same project in case you have already been using one for Android push notifications. * Download GoogleService-Info.plist file into your Xcode project bundle. * Go to your account settings in **[Nudgespot](https://app.nudgespot.com)** and update your GCM provider details (GCM Sender ID & GCM API Key)
**Prerequisite**: * iOS 7.x and upwards * Firebase Cloud Platform Account with Firebase Cloud Messaging enabled **Installation using CocoaPods** * Add the Nudgespot pod into your Podfile `pod 'Nudgespot'` and run `pod install` **Configuration**: * Go to your Firebase Cloud Messaging **[account](https://console.firebase.google.com/)** and configure your GCM account to send iOS push notification. You can do so by clicking on 'Get A Configuration File', followed by uploading your Apple Push Notification certificates and the app bundle id. This process will generate a project id and a server key in your Google Developers account. Note: You can use the same project in case you have already been using one for Android push notifications. * Download GoogleService-Info.plist file into your Xcode project bundle. * Go to your account settings in **[Nudgespot](https://app.nudgespot.com)** and update your GCM provider details (GCM Sender ID & GCM API Key)
{"__v":2,"_id":"571f6666e2b7000e0091c596","api":{"auth":"required","params":[],"results":{"codes":[{"name":"","code":"{}","language":"json","status":200},{"name":"","code":"{}","language":"json","status":400}]},"settings":"","url":""},"body":"**Authentication**\nInitializing the client: In your application delegate, you can initialize the client as follows. This step only initializes the client with your credentials but is not yet ready to start identifying users or tracking activities.\n\nNote: For Swift initialization create Bridge Header File and insert the below code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <Nudgespot/NudgespotSDK.h> or #import “NudgespotSDK.h”\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\\n  // Initialize Nudgespot\\n  [Nudgespot setJavascriptApiKey:@\\\"\\\" andSetRESTApiKey:@\\\"\\\"];\\n}\\n- (void)applicationDidBecomeActive:(UIApplication *)application {\\n// Connect to the Nudgetspot to receive notification\\n  [Nudgespot connectToFcm];\\n}\\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {\\n// Acknowledge Fcm server to the to receive notification\\n// Acknowledge Nudgespot server to the to process notification.\\n  [Nudgespot acknowledgeFcmServer:userInfo];\\n  [Nudgespot  processNudgespotNotification:userInfo withApplication:application andWindow:self.window];\\n}\\n- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken  {\\n// Set Device Token on Fcm to know server you are working on Production environment or sandbox\\n  [Nudgespot setAPNSToken:deviceToken ofType:NudgespotAPNSTokenTypeSandbox];\\n}\\n- (void)applicationDidEnterBackground:(UIApplication *)application  {\\n// Disconnect to Fcm..\\n  [Nudgespot  disconnectToFcm];\\n}\\n\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    },\n    {\n      \"code\": \"func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\\n  // Initialize Nudgespot\\n        Nudgespot.setJavascriptAPIkey(””, andRESTAPIkey:””)\\n}\\n\\nfunc applicationDidBecomeActive(application: UIApplication) {\\n// Connect to the Nudgetspot to receive notification\\n        Nudgespot.connectToFcm()\\n}\\n\\nfunc application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)  {\\n// Acknowledge Fcm server to the to receive notification\\n// Acknowledge Nudgespot server to the to process notification.\\nNudgespot.acknowledgeFcmServer(userInfo)\\nNudgespot.processNudgespotNotification(userInfo, withApplication: application, andWindow: window)\\n}\\n\\nfunc application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {\\n// Set Device Token on Fcm to know server you are working on Production environment or sandbox\\n   Nudgespot.setAPNSToken(deviceToken, ofType: .APNSTokenTypeSandbox)\\n}\\n\\n\\nfunc applicationDidEnterBackground(application: UIApplication) {\\n    Nudgespot.disconnectToFcm()\\n}\\n\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n**Registering Anonymous Users**\nUse the following code for registering logged-out or anonymous users in your system -\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Nudgespot registerAnonymousUser:^(id response, NSError *error) {\\n  // Your additional code to handle success or error\\n}];\\n\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Nudgespot.registerAnonymousUser({ (response: AnyObject?, error: NSError?) in\\n                print(response)\\n            })\\n\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n**Registering Logged-in/Identified Users**\nWhen the user logs in, you can identify the user as below. The user id is the unique id that you send to Nudgespot for identifying that user, and is most likely the email address of the user but could be the phone number or the database primary key. This step also registers the user for push notifications with the GCM via APNS server in background.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Nudgespot setWithUID: @\\\"your uid\\\" registrationHandler:^(NSString *registrationToken, NSError *error){\\n  // Your additional code to handle success or error\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    },\n    {\n      \"code\": \"Nudgespot.setWithUID(\\\"as uid\\\", registrationHandler: {  (response: String?, error: NSError?) in\\n            print(response)\\n})\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n**Subscriber Initialization Helper**\nYou can also initialize the user with the NudgespotSubscriber object. Using the object gives you flexibility to pass additional details about the user such as their profile properties.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NudgespotSubsciber *subscriber = [[NudgespotSubscriber alloc] init];\\nNSMutableDictionary *properties = [[NSMutableDictionary alloc] initWithDictionary:@{@\\\"gender\\\" : @\\\"female\\\"}];\\n[subscriber setProperties: properties];\\n[Nudgespot setWithSubscriber:subscriber registrationHandler:^(NSString *registrationToken, NSError *error){\\n  // Your additional code to handle success or error\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    },\n    {\n      \"code\": \"let subscriber = NudgespotSubscriber()\\nlet properties = NSMutableDictionary.init(dictionary: [\\\"gender\\\" : \\\"female\\\"])\\nsubscriber.properties = properties\\nNudgespot.setWithSubscriber(subscriber){ (response: AnyObject?, error: NSError?) in\\n// Your additional code to handle success or error\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n**Track an Activity**\nNow you can track the users by calling the “track” method on the client as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NudgespotActivity *activity = [[NudgespotActivity alloc] initwithNudgespotActivity: @”Your activity” andUID: [[[Nudgespot sharedInstance]subsciber]uid] andProperty:nil];\\n[Nudgespot trackActivity: activity completion:^(id response, NSError *error){\\n  // Your additional code to handle success or error\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    },\n    {\n      \"code\": \"let dictionary : NSMutableDictionary? = nil        \\nlet activity = NudgespotActivity().initwithNudgespotActivity(\\\"Acitvity Event Name\\\", andProperty: dictionary)\\nNudgespot.trackActivity(activity!) { (response: AnyObject?, error: NSError?) in\\n            // Your additional code to handle success or error\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n**Clear Registration**\nFinally, when your user logs out, you should remove that device association as:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Nudgespot clearRegistration:^(id response, NSError *error){\\n  // Your additional code handle success or error\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    },\n    {\n      \"code\": \"Nudgespot.clearRegistration { (response: AnyObject?, error: NSError?) in\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","category":"571f6666e2b7000e0091c57f","createdAt":"2016-04-05T10:50:37.266Z","excerpt":"Instructions on how to use the Nudgespot iOS Library","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":22,"project":"552c21677820b80d00aa4ec5","slug":"ios-using-library","sync_unique":"","title":"Using the library","type":"basic","updates":[],"user":"552c213ccd0a981700922b4f","version":"571f6666e2b7000e0091c57a","childrenPages":[]}

Using the library

Instructions on how to use the Nudgespot iOS Library

**Authentication** Initializing the client: In your application delegate, you can initialize the client as follows. This step only initializes the client with your credentials but is not yet ready to start identifying users or tracking activities. Note: For Swift initialization create Bridge Header File and insert the below code. [block:code] { "codes": [ { "code": "#import <Nudgespot/NudgespotSDK.h> or #import “NudgespotSDK.h”", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n // Initialize Nudgespot\n [Nudgespot setJavascriptApiKey:@\"\" andSetRESTApiKey:@\"\"];\n}\n- (void)applicationDidBecomeActive:(UIApplication *)application {\n// Connect to the Nudgetspot to receive notification\n [Nudgespot connectToFcm];\n}\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {\n// Acknowledge Fcm server to the to receive notification\n// Acknowledge Nudgespot server to the to process notification.\n [Nudgespot acknowledgeFcmServer:userInfo];\n [Nudgespot processNudgespotNotification:userInfo withApplication:application andWindow:self.window];\n}\n- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\n// Set Device Token on Fcm to know server you are working on Production environment or sandbox\n [Nudgespot setAPNSToken:deviceToken ofType:NudgespotAPNSTokenTypeSandbox];\n}\n- (void)applicationDidEnterBackground:(UIApplication *)application {\n// Disconnect to Fcm..\n [Nudgespot disconnectToFcm];\n}\n", "language": "objectivec", "name": "Objective-C" }, { "code": "func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\n // Initialize Nudgespot\n Nudgespot.setJavascriptAPIkey(””, andRESTAPIkey:””)\n}\n\nfunc applicationDidBecomeActive(application: UIApplication) {\n// Connect to the Nudgetspot to receive notification\n Nudgespot.connectToFcm()\n}\n\nfunc application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {\n// Acknowledge Fcm server to the to receive notification\n// Acknowledge Nudgespot server to the to process notification.\nNudgespot.acknowledgeFcmServer(userInfo)\nNudgespot.processNudgespotNotification(userInfo, withApplication: application, andWindow: window)\n}\n\nfunc application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {\n// Set Device Token on Fcm to know server you are working on Production environment or sandbox\n Nudgespot.setAPNSToken(deviceToken, ofType: .APNSTokenTypeSandbox)\n}\n\n\nfunc applicationDidEnterBackground(application: UIApplication) {\n Nudgespot.disconnectToFcm()\n}\n", "language": "swift" } ] } [/block] **Registering Anonymous Users** Use the following code for registering logged-out or anonymous users in your system - [block:code] { "codes": [ { "code": "[Nudgespot registerAnonymousUser:^(id response, NSError *error) {\n // Your additional code to handle success or error\n}];\n", "language": "objectivec" }, { "code": "Nudgespot.registerAnonymousUser({ (response: AnyObject?, error: NSError?) in\n print(response)\n })\n", "language": "swift" } ] } [/block] **Registering Logged-in/Identified Users** When the user logs in, you can identify the user as below. The user id is the unique id that you send to Nudgespot for identifying that user, and is most likely the email address of the user but could be the phone number or the database primary key. This step also registers the user for push notifications with the GCM via APNS server in background. [block:code] { "codes": [ { "code": "[Nudgespot setWithUID: @\"your uid\" registrationHandler:^(NSString *registrationToken, NSError *error){\n // Your additional code to handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "Nudgespot.setWithUID(\"as uid\", registrationHandler: { (response: String?, error: NSError?) in\n print(response)\n})", "language": "swift" } ] } [/block] **Subscriber Initialization Helper** You can also initialize the user with the NudgespotSubscriber object. Using the object gives you flexibility to pass additional details about the user such as their profile properties. [block:code] { "codes": [ { "code": "NudgespotSubsciber *subscriber = [[NudgespotSubscriber alloc] init];\nNSMutableDictionary *properties = [[NSMutableDictionary alloc] initWithDictionary:@{@\"gender\" : @\"female\"}];\n[subscriber setProperties: properties];\n[Nudgespot setWithSubscriber:subscriber registrationHandler:^(NSString *registrationToken, NSError *error){\n // Your additional code to handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "let subscriber = NudgespotSubscriber()\nlet properties = NSMutableDictionary.init(dictionary: [\"gender\" : \"female\"])\nsubscriber.properties = properties\nNudgespot.setWithSubscriber(subscriber){ (response: AnyObject?, error: NSError?) in\n// Your additional code to handle success or error\n}", "language": "swift" } ] } [/block] **Track an Activity** Now you can track the users by calling the “track” method on the client as follows: [block:code] { "codes": [ { "code": "NudgespotActivity *activity = [[NudgespotActivity alloc] initwithNudgespotActivity: @”Your activity” andUID: [[[Nudgespot sharedInstance]subsciber]uid] andProperty:nil];\n[Nudgespot trackActivity: activity completion:^(id response, NSError *error){\n // Your additional code to handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "let dictionary : NSMutableDictionary? = nil \nlet activity = NudgespotActivity().initwithNudgespotActivity(\"Acitvity Event Name\", andProperty: dictionary)\nNudgespot.trackActivity(activity!) { (response: AnyObject?, error: NSError?) in\n // Your additional code to handle success or error\n}", "language": "swift" } ] } [/block] **Clear Registration** Finally, when your user logs out, you should remove that device association as: [block:code] { "codes": [ { "code": "[Nudgespot clearRegistration:^(id response, NSError *error){\n // Your additional code handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "Nudgespot.clearRegistration { (response: AnyObject?, error: NSError?) in\n}", "language": "swift" } ] } [/block]
**Authentication** Initializing the client: In your application delegate, you can initialize the client as follows. This step only initializes the client with your credentials but is not yet ready to start identifying users or tracking activities. Note: For Swift initialization create Bridge Header File and insert the below code. [block:code] { "codes": [ { "code": "#import <Nudgespot/NudgespotSDK.h> or #import “NudgespotSDK.h”", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n // Initialize Nudgespot\n [Nudgespot setJavascriptApiKey:@\"\" andSetRESTApiKey:@\"\"];\n}\n- (void)applicationDidBecomeActive:(UIApplication *)application {\n// Connect to the Nudgetspot to receive notification\n [Nudgespot connectToFcm];\n}\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {\n// Acknowledge Fcm server to the to receive notification\n// Acknowledge Nudgespot server to the to process notification.\n [Nudgespot acknowledgeFcmServer:userInfo];\n [Nudgespot processNudgespotNotification:userInfo withApplication:application andWindow:self.window];\n}\n- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\n// Set Device Token on Fcm to know server you are working on Production environment or sandbox\n [Nudgespot setAPNSToken:deviceToken ofType:NudgespotAPNSTokenTypeSandbox];\n}\n- (void)applicationDidEnterBackground:(UIApplication *)application {\n// Disconnect to Fcm..\n [Nudgespot disconnectToFcm];\n}\n", "language": "objectivec", "name": "Objective-C" }, { "code": "func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\n // Initialize Nudgespot\n Nudgespot.setJavascriptAPIkey(””, andRESTAPIkey:””)\n}\n\nfunc applicationDidBecomeActive(application: UIApplication) {\n// Connect to the Nudgetspot to receive notification\n Nudgespot.connectToFcm()\n}\n\nfunc application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {\n// Acknowledge Fcm server to the to receive notification\n// Acknowledge Nudgespot server to the to process notification.\nNudgespot.acknowledgeFcmServer(userInfo)\nNudgespot.processNudgespotNotification(userInfo, withApplication: application, andWindow: window)\n}\n\nfunc application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {\n// Set Device Token on Fcm to know server you are working on Production environment or sandbox\n Nudgespot.setAPNSToken(deviceToken, ofType: .APNSTokenTypeSandbox)\n}\n\n\nfunc applicationDidEnterBackground(application: UIApplication) {\n Nudgespot.disconnectToFcm()\n}\n", "language": "swift" } ] } [/block] **Registering Anonymous Users** Use the following code for registering logged-out or anonymous users in your system - [block:code] { "codes": [ { "code": "[Nudgespot registerAnonymousUser:^(id response, NSError *error) {\n // Your additional code to handle success or error\n}];\n", "language": "objectivec" }, { "code": "Nudgespot.registerAnonymousUser({ (response: AnyObject?, error: NSError?) in\n print(response)\n })\n", "language": "swift" } ] } [/block] **Registering Logged-in/Identified Users** When the user logs in, you can identify the user as below. The user id is the unique id that you send to Nudgespot for identifying that user, and is most likely the email address of the user but could be the phone number or the database primary key. This step also registers the user for push notifications with the GCM via APNS server in background. [block:code] { "codes": [ { "code": "[Nudgespot setWithUID: @\"your uid\" registrationHandler:^(NSString *registrationToken, NSError *error){\n // Your additional code to handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "Nudgespot.setWithUID(\"as uid\", registrationHandler: { (response: String?, error: NSError?) in\n print(response)\n})", "language": "swift" } ] } [/block] **Subscriber Initialization Helper** You can also initialize the user with the NudgespotSubscriber object. Using the object gives you flexibility to pass additional details about the user such as their profile properties. [block:code] { "codes": [ { "code": "NudgespotSubsciber *subscriber = [[NudgespotSubscriber alloc] init];\nNSMutableDictionary *properties = [[NSMutableDictionary alloc] initWithDictionary:@{@\"gender\" : @\"female\"}];\n[subscriber setProperties: properties];\n[Nudgespot setWithSubscriber:subscriber registrationHandler:^(NSString *registrationToken, NSError *error){\n // Your additional code to handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "let subscriber = NudgespotSubscriber()\nlet properties = NSMutableDictionary.init(dictionary: [\"gender\" : \"female\"])\nsubscriber.properties = properties\nNudgespot.setWithSubscriber(subscriber){ (response: AnyObject?, error: NSError?) in\n// Your additional code to handle success or error\n}", "language": "swift" } ] } [/block] **Track an Activity** Now you can track the users by calling the “track” method on the client as follows: [block:code] { "codes": [ { "code": "NudgespotActivity *activity = [[NudgespotActivity alloc] initwithNudgespotActivity: @”Your activity” andUID: [[[Nudgespot sharedInstance]subsciber]uid] andProperty:nil];\n[Nudgespot trackActivity: activity completion:^(id response, NSError *error){\n // Your additional code to handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "let dictionary : NSMutableDictionary? = nil \nlet activity = NudgespotActivity().initwithNudgespotActivity(\"Acitvity Event Name\", andProperty: dictionary)\nNudgespot.trackActivity(activity!) { (response: AnyObject?, error: NSError?) in\n // Your additional code to handle success or error\n}", "language": "swift" } ] } [/block] **Clear Registration** Finally, when your user logs out, you should remove that device association as: [block:code] { "codes": [ { "code": "[Nudgespot clearRegistration:^(id response, NSError *error){\n // Your additional code handle success or error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "Nudgespot.clearRegistration { (response: AnyObject?, error: NSError?) in\n}", "language": "swift" } ] } [/block]