UNPKG

4.04 kBMarkdownView Raw
1# [SupportKit Javascript SDK](supportkit.io)
2*SupportKit adds beautifully simple messaging to your app to keep your users engaged and coming back.*
3
4[![Circle CI](https://circleci.com/gh/supportkit/supportkit-js.svg?style=svg)](https://circleci.com/gh/supportkit/supportkit-js) [![npm version](https://badge.fury.io/js/supportkit.svg)](http://badge.fury.io/js/supportkit) [![Bower version](https://badge.fury.io/bo/supportkit.svg)](http://badge.fury.io/bo/supportkit)
5
6## Usage
7
8### Script Tag
9
10Add the following code towards the end of the `body` section on your page. Placing it at the end allows the rest of the page to load first.
11
12```html
13<script src="https://cdn.supportkit.io/supportkit.min.js"></script>
14```
15
16Note that SupportKit requires jQuery to work. If you aren't using jQuery yet, then add the following code before the previous code snippet. This step is only needed if you are using the CDN version.<br>
17
18```
19<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
20```
21
22Initialize the plugin using this code snippet
23
24```html
25<script>
26 SupportKit.init({appToken: 'your_app_token'});
27</script>
28```
29
30### In Node.js and Browserify
31
32Install from npm
33
34```
35npm install supportkit
36```
37
38Require and init
39
40```javascript
41var SupportKit = require('supportkit');
42
43SupportKit.init({appToken: 'your_app_token'});
44```
45
46### Bower
47
48Install from bower
49
50```
51bower install supportkit
52```
53
54Include in JS using preferred method and init
55
56```javascript
57SupportKit.init({appToken: 'your_app_token'});
58```
59
60## API
61
62### Individual functions
63
64#### init(options)
65Initializes the SupportKit widget in the web page using the specified options. It returns a promise that will resolve when the widget is ready.
66
67```javascript
68var skPromise = SupportKit.init({
69 appToken: 'your_app_token',
70 givenName: 'Cool',
71 surname: 'Person',
72 email: 'their_email@whatever.com',
73 // For secure mode
74 jwt: 'your_jwt',
75 userId: 'user_id',
76 // Additional properties
77 properties: {
78 'anything': 'whatever_you_want'
79 }
80});
81
82
83skPromise.then(function() {
84 // do something
85});
86
87// pass it around...
88
89skPromise.then(function() {
90 //do something else
91});
92
93
94```
95
96#### open()
97Opens the conversation widget
98
99```javascript
100SupportKit.open();
101```
102
103#### close()
104Closes the conversation widget
105
106```javascript
107SupportKit.close();
108```
109
110#### logout()
111Removes deviceId cookie from the browser, effectively logging out the user.
112Destroys the widget completely. Can be initiated again manually with `SupportKit.init(...)`
113
114```
115SupportKit.logout();
116```
117
118#### sendMessage(text)
119Sends a message on the user's behalf
120
121```javascript
122SupportKit.message('hello');
123```
124
125#### updateUser(user)
126Updates user information
127
128```javascript
129SupportKit.updateUser({
130 givenName: 'Updated',
131 surname: 'Name',
132 email: 'updated@email.com',
133 properties: {
134 'justGotUpdated': true
135 }
136});
137```
138
139#### track(eventName)
140Tracks an event for the current user.
141
142```javascript
143SupportKit.track('item-in-cart');
144```
145
146### Events
147If you want to make sure your events are triggered, try to bind them before calling `SupportKit.init`.
148
149#### ready
150```
151// This event triggers when init completes successfully... Be sure to bind before calling init!
152SupportKit.on('ready', function(){
153 console.log('the init has completed!');
154});
155
156SupportKit.init(...);
157```
158
159#### destroy
160```
161// This event triggers when init completes successfully... Be sure to bind before calling init!
162SupportKit.on('destroy', function(){
163 console.log('the widget is destroyed!');
164});
165
166SupportKit.destroy();
167```
168
169## How to contribute
170
171### Clone the git repo
172```git clone https://github.com/supportkit/supportkit-js```
173
174### Install Node.js and run the following
175
176```npm install```
177```npm install -g grunt```
178
179### Essential Grunt Tasks
180
181* ```grunt build``` dumps a plain and a minified file from all files in the folder ```src``` to dist/supportkit.min.js
182* ```grunt clean``` removes all files in the folder ```dist```
183* ```grunt test:unit``` runs karma tests
184
\No newline at end of file