-
Notifications
You must be signed in to change notification settings - Fork 13
/
integration-nodejs.html
418 lines (389 loc) · 19.4 KB
/
integration-nodejs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="images/favicon.png">
<title>Countly Code Generator</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="jumbotron top">
<div class="container">
<div id="logo">
<span class="image"></span>
<span class="text">Code Generator</span>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div style="overflow: auto">
<div class="btn-group" style="float: left">
<a href="integration.html" id="back" class="btn btn-default">← Back</a>
<a href="events.html?sdk=nodejs" id="next" class="btn btn-default">Next: Create Event →</a>
</div>
<div id="buttons" class="btn-group" role="group" style="float: right">
</div>
</div>
<h2 class="text-center">Integrating NodeJS SDK</h2>
</div>
</div>
<div class='section configuration'>
<span class='label'>Provide configuration settings</span>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for='server-url'>Server URL:</label>
<input type="url" class="form-control" id='server-url' placeholder="https://try.count.ly">
</div>
</div><!-- /.col-lg-6 -->
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="app_key">App Key:</label>
<input type="text" class="form-control" id="app_key"
placeholder="f399aa0a6305c2bd51d304ca666418ae8d93d9bc">
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</div>
<div class='section features checkbox'>
<span class='label'>Choose features you want to use</span>
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_errors'> Track nodejs errors
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<p> </p>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" id="allfeatures"> I want all features
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</div>
<div class='section advanced'>
<span class='label'>
<span id="dropdown-icon" style="display: inline-block;"></span>
<span id="dropdown-icon-2" style="display: none;"></span>
Advanced Configuration</span>
<div class='advanced-list'>
<fieldset>
<legend>General</legend>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide custom device id (will generate if not provided)</label>
<input type="text" class="form-control" id='device_id' placeholder="someid" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide app version (will use 0.0 if not provided)</label>
<input type="text" class="form-control" id='app_version' placeholder="0.0" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</fieldset>
<fieldset>
<legend>Location</legend>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide country code of your user (will try to determine from IP address if not
provided)</label>
<input type="text" class="form-control" id='country_code' placeholder="US" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide city of your user (will try to determine from IP address if not
provided)</label>
<input type="text" class="form-control" id='city' placeholder="San Francisco" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide IP address of your user (will try to determine automatically, if not
provided)</label>
<input type="text" class="form-control" id='ip_address' placeholder="127.0.0.1" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</fieldset>
<fieldset>
<legend>Limits</legend>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide an interval how often to check if there is any data to report and report
it in miliseconds</label>
<input type="text" class="form-control" id='interval' placeholder="500" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide maximum amount of queued requests to store if server is
unresponsive</label>
<input type="text" class="form-control" id='queue_size' placeholder="1000" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide time in seconds to wait after failed connection to server in
seconds</label>
<input type="text" class="form-control" id='fail_timeout' placeholder="60" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide how often, in seconds, should a session be extended</label>
<input type="text" class="form-control" id='session_update' placeholder="60" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Maximum amount of events to send per one batch</label>
<input type="text" class="form-control" id='max_events' placeholder="10" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Maximum amount of breadcrum logs to store for crash reports</label>
<input type="text" class="form-control" id='max_logs' placeholder="100" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</fieldset>
<fieldset>
<legend>Optional</legend>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>
<input type="checkbox" id='debug' value='true'> Enable Debug logging
</label>
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>
<input type="checkbox" id='force_post' value='true'> Force using POST only
</label>
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</fieldset>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class='text-center'><button type="button" class="btn btn-success" id="generate">Generate
code</button></p>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<footer>
<p><a href='http://count.ly'>Count.ly</a></p>
</footer>
</div> <!-- /container -->
<div class="modal fade" id="end-modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title">Copy this snippet in your website</h4>
</div>
<div class="modal-body">
<p>Run <strong>npm install countly-sdk-nodejs</strong> to get NodeJS SDK and use it as provided:</p>
<p><textarea id='end-code' class="no-translate" readonly onclick="this.select();"></textarea></p>
</div>
<div class="modal-footer">
<p class='text-center'>
<button type="button" class="btn btn-success" id="copy"
data-clipboard-target="#end-code">Copy</button>
<button type="button" class="btn btn-success" id="download">Download</button>
<button type="button" class="btn btn-primary" id="gotit">Close</button>
</p>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>
<script src="https://global.localizecdn.com/localize.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
<script src="js/sdks.js"></script>
<script src="js/common.js"></script>
<script src="js/Blob.js"></script>
<script src="js/FileSaver.min.js"></script>
<script src="js/clipboard.min.js"></script>
<script>
$(document).ready(function () {
new Clipboard('#copy');
var sdk = sdks.nodejs;
$("#buttons").append('<a href="' + sdk.docs + '" target="_blank" class="btn btn-default">Documentation</a>');
$("#buttons").append('<a href="' + sdk.download + '" target="_blank" class="btn btn-default">Download</a>');
$("#buttons").append('<a href="' + sdk.repo + '" target="_blank" class="btn btn-default">Repository</a>');
var params = parseParams(location.search);
if (params.server) {
$(".server span").text(params.server);
$("#server-url").val(params.server);
}
else {
$(".server").hide();
}
if (params.app_key) {
$("#app_key").val(params.app_key);
}
if (params.server && params.app_key) {
$(".configuration").hide();
}
var template = "var Countly = require('countly-sdk-nodejs');\n\n" +
"Countly.init({\n" +
" app_key: 'YOUR_APP_KEY',\n" +
" url: 'https://cloud.count.ly/',\n" +
" [options]\n" +
"});\n" +
"\n" +
"[features]\n";
$("#generate").click(function () {
$(".alert").remove();
var data = {};
data.url = $("#server-url").val();
if (data.url == "") {
$("#server-url").parent().prepend('<div class="alert alert-danger" role="alert">Please provide server URL</div>');
return;
}
if (data.url.indexOf("http") != 0) {
$("#server-url").parent().prepend('<div class="alert alert-danger" role="alert">Your server URL should start with http:// or https://</div>');
return;
}
data.app_key = $("#app_key").val();
if (data.app_key == "") {
$("#app_key").parent().prepend('<div class="alert alert-danger" role="alert">Please provide App Key</div>');
return;
}
data.features = $(".feature:checked").map(function (feature) {
return this.value;
}).get();
if (data.features.length) {
data.features = "Countly." + data.features.join("();\nCountly.") + "();";
}
else {
data.features = "";
}
data.options = $(".advanced-list input").map(function (el) {
if (this.type == "text") {
if ($(this).hasClass("arr") && this.value.replace(/^\s+|\s+$/gm, '') != "") {
var arr = this.value.split(",");
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i].replace(/^\s+|\s+$/gm, '');
}
return { id: this.id, value: JSON.stringify(arr) };
}
else if (isNaN(this.value))
return { id: this.id, value: '"' + this.value + '"' };
else
return { id: this.id, value: this.value };
}
else if (this.type == "checkbox" && this.checked)
return { id: this.id, value: this.value };
else
return { id: this.id, value: "" };
}).get().filter(function (el) {
if (el.value.length && el.value != '""')
return true;
return false;
}).map(function (el) {
return el.id + ': ' + el.value;
});
if (data.options.length) {
data.options = " " + data.options.join(",\n ") + "\n";
}
else {
data.options = "";
}
var code = template.replace("http://yourdomain.com", data.url)
.replace("YOUR_APP_KEY", data.app_key)
.replace(" [options]\n", data.options)
.replace("[features]", data.features);
$("#end-code").val(code);
$('#end-modal').modal();
});
$("#allfeatures").change(function () {
$(".feature").prop('checked', $(this).prop("checked"));
});
$(".advanced span.label").on('click', function () {
var downArrow = document.getElementById('dropdown-icon').style.display;
if (downArrow === 'inline-block') {
$(this).parent().find("#dropdown-icon-2").attr('style', 'display: inline-block');
}
else {
$(this).parent().find("#dropdown-icon-2").attr('style', 'display: none');
}
$(this).parent().find("#dropdown-icon").toggle();
});
$("#gotit").click(function () {
$('#end-modal').modal('hide');
});
$("#download").click(function () {
var data = $("#end-code").val();
try {
var blob = new Blob([data], { type: "text/plain;charset=utf-8" });
saveAs(blob, "nodejs-sdk.txt");
} catch (e) {
alert(data);
}
});
});
</script>
</body>
</html>