{"_id":"548f7589a8f6730b004b34b3","__v":12,"category":{"_id":"53844558a43e08da4677be13","pages":["53844558a43e08da4677be14","54211ad2f980dee664db9fc5","54212689f980dee664db9fc9","5421d851f980dee664db9ffe","54504d643c6f700800a9b4de","548f7589a8f6730b004b34b3","554a9af6b4322819002b6a1b","55a44d8b1fd6fb0d00d6fb2a"],"project":"53844557a43e08da4677be0e","version":"53844558a43e08da4677be12","__v":14,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-05-27T07:57:12.144Z","from_sync":false,"order":0,"slug":"general-api-documentation","title":"General API Documentation"},"project":"53844557a43e08da4677be0e","user":"5432d74e8780d4080074d772","version":{"_id":"53844558a43e08da4677be12","__v":8,"project":"53844557a43e08da4677be0e","createdAt":"2014-05-27T07:57:12.136Z","releaseDate":"2014-05-27T07:57:12.136Z","categories":["53844558a43e08da4677be13","538619e1ef91f96d49aa1a0b","541e82877eb16bb64f83c0ca","5445a073c3eb3808000c76b2","5445a098c3eb3808000c76b3","54bb05ab522f03150054d9e8","54bb05cf9741c81500078f73","55b7d0e5568be2230092bb92"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"false","version_clean":"1.0.0","version":"1.0"},"updates":["55cbbec54153080d004468fa"],"next":{"pages":[],"description":""},"createdAt":"2014-12-15T23:58:01.705Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"One of the easiest ways to get started with Knowtify is through our javascript widget. With a few lines of frontend code you can be adding new contacts, updating contacts, sending transactional emails and powering your own in-app Notification center (which we call, InBox).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installing Knowtify\"\n}\n[/block]\nTo get started, you'll need to add our script to any web page you'd like to use Knowtify. We recommend adding this to your layout files above the closing </body> tag. You'll need to include your **Public Token** found in [Knowtify Settings](http://www.knowtify.io/settings).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script>\\n    var _knowtify = _knowtify || [];\\n    var _knowtifyInbox = _knowtifyInbox || [];\\n    _knowtify.public_token = \\\"xxx\\\";\\n\\n    (function(d,s,t,u){var j = d.createElement(s);var p = d.getElementsByTagName(s)[0];\\n        j.type = t;j.async = true;j.src = u;p.parentNode.insertBefore(j, p);})(document,'script','text/javascript', 'http://js.knowtify.io/knowtify.js');\\n</script>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Adding Contacts\"\n}\n[/block]\nAfter loading our script you'll be able to send us new contacts.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script>\\n\\t_knowtify.push(['add_contact', {\\n    email: \\\"joe:::at:::test.com\\\",\\n    id: 123,\\n    name: \\\"Joe\\\",\\n    followers: 12\\n\\t}]);\\n</script>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n- **email** - Required\n- **id** - Recommended\n- **other attributes** - Optional. You can send us any data associated with your contact which is used as content in emails and for segmentation. In this case we added 'name' and 'followers'. You can add as many attributes as you need.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Updating Contacts\"\n}\n[/block]\nIf you need to update any attributes associated with a contact you can send an update request.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script>\\n  _knowtify.push(['update_contact', {\\n    id: 123,\\n    email: \\\"joe@test.com\\\",\\n    followers: 100\\n  }]);\\n</script>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n- **id is required for updates** - This should be set to a unique number or string that isn't publicly available. This is to prevent unauthorized requests from updating contacts and sending transactional emails without your permission.\n- **email** - Required\n- **attributes you want to change** - In this case we're changing the 'followers' count to 100.\n- **event** - (optional) setting the event will trigger any transactional emails using that event tag. You can read more about events and event tags [here](http://api.knowtify.io/v1.0/docs/sending-event-based-emails). If you are using events, be careful not to trigger this function call more than once. An email will be delivered after every call.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Events\"\n}\n[/block]\nYou can use events to trigger transactional emails or Inbox messages. **If you send the same event multiple times it will trigger multiple messages**. You can read more about events and event tags [here](http://api.knowtify.io/v1.0/docs/sending-event-based-emails).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"_knowtify.push(['event', 'receipt', {\\n  id: 123,\\n  email: \\\"joe@test.com\\\",\\n  purchase_name: \\\"Chair\\\",\\n  purchase_price: \\\"$100\\\"\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\"\n}\n[/block]","excerpt":"","slug":"javascript-widget","type":"basic","title":"JAVASCRIPT API"}
One of the easiest ways to get started with Knowtify is through our javascript widget. With a few lines of frontend code you can be adding new contacts, updating contacts, sending transactional emails and powering your own in-app Notification center (which we call, InBox). [block:api-header] { "type": "basic", "title": "Installing Knowtify" } [/block] To get started, you'll need to add our script to any web page you'd like to use Knowtify. We recommend adding this to your layout files above the closing </body> tag. You'll need to include your **Public Token** found in [Knowtify Settings](http://www.knowtify.io/settings). [block:code] { "codes": [ { "code": "<script>\n var _knowtify = _knowtify || [];\n var _knowtifyInbox = _knowtifyInbox || [];\n _knowtify.public_token = \"xxx\";\n\n (function(d,s,t,u){var j = d.createElement(s);var p = d.getElementsByTagName(s)[0];\n j.type = t;j.async = true;j.src = u;p.parentNode.insertBefore(j, p);})(document,'script','text/javascript', 'http://js.knowtify.io/knowtify.js');\n</script>", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Adding Contacts" } [/block] After loading our script you'll be able to send us new contacts. [block:code] { "codes": [ { "code": "<script>\n\t_knowtify.push(['add_contact', {\n email: \"joe@test.com\",\n id: 123,\n name: \"Joe\",\n followers: 12\n\t}]);\n</script>", "language": "javascript" } ] } [/block] - **email** - Required - **id** - Recommended - **other attributes** - Optional. You can send us any data associated with your contact which is used as content in emails and for segmentation. In this case we added 'name' and 'followers'. You can add as many attributes as you need. [block:api-header] { "type": "basic", "title": "Updating Contacts" } [/block] If you need to update any attributes associated with a contact you can send an update request. [block:code] { "codes": [ { "code": "<script>\n _knowtify.push(['update_contact', {\n id: 123,\n email: \"joe@test.com\",\n followers: 100\n }]);\n</script>", "language": "javascript" } ] } [/block] - **id is required for updates** - This should be set to a unique number or string that isn't publicly available. This is to prevent unauthorized requests from updating contacts and sending transactional emails without your permission. - **email** - Required - **attributes you want to change** - In this case we're changing the 'followers' count to 100. - **event** - (optional) setting the event will trigger any transactional emails using that event tag. You can read more about events and event tags [here](http://api.knowtify.io/v1.0/docs/sending-event-based-emails). If you are using events, be careful not to trigger this function call more than once. An email will be delivered after every call. [block:api-header] { "type": "basic", "title": "Events" } [/block] You can use events to trigger transactional emails or Inbox messages. **If you send the same event multiple times it will trigger multiple messages**. You can read more about events and event tags [here](http://api.knowtify.io/v1.0/docs/sending-event-based-emails). [block:code] { "codes": [ { "code": "_knowtify.push(['event', 'receipt', {\n id: 123,\n email: \"joe@test.com\",\n purchase_name: \"Chair\",\n purchase_price: \"$100\"\n}]);", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic" } [/block]