forked from Countly/countly-code-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration-web.html
567 lines (536 loc) · 25.9 KB
/
integration-web.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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<!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=web" 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 Web 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 source radio'>
<span class='label'>Choose from where to load the script</span>
<div class="row server">
<div class="col-md-12">
<label>
<input type="radio" name='source' id='source-server' value=''> Load from this server (<span></span>)
</label>
</div><!-- /.col-lg-6 -->
</div>
<div class="row">
<div class="col-md-12">
<label>
<input type="radio" name='source' id="cdnjs" value='https://cdnjs.cloudflare.com/ajax/libs/countly-sdk-web/version/countly.min.js'> Load from cdnjs
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="radio" name='source' value='https://cdn.jsdelivr.net/npm/countly-sdk-web@latest/lib/countly.min.js'> Load from jsdeliver
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="radio" name='source' value='custom'> Load custom server: <input type='text' id='custom-source' class="form-custom-control" placeholder='http://myserver.com/path/to/countly.min.js'/>
</label>
</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_sessions'> Track user sessions
</label>
</div><!-- /.col-lg-6 -->
</div>
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_pageview'> Track page views
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_clicks'> Track user clicks
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_scrolls'> Track page scrolls
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_errors'> Track javascript errors
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_links'> Generate events for link clicks
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='track_forms'> Generate events for form submissions
</label>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<label>
<input type="checkbox" class='feature' value='collect_from_forms'> Collect user information from forms
</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'>Advanced Configuration</span>
<div class='advanced-list'>
<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 -->
<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 -->
<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 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 -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide after how many minutes user should be counted as inactive, if there are no actions, as mouse move, scroll or keypress</label>
<input type="text" class="form-control" id='inactivity_time' placeholder="20" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide comma separated list of referrers to ignore</label>
<input type="text" class="form-control arr" id='ignore_referrers' placeholder="domain1.com, domain2.com" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Provide how long till cookie session should expire in minutes</label>
<input type="text" class="form-control" id='session_cookie_timeout' placeholder="30" />
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<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='require_consent' value='true'> Require Consent
</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='use_session_cookie' value='true'> Use session cookie to track session
</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 -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>
<input type="checkbox" id='ignore_bots' value='false'> Do not ignore bots
</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='ignore_prefetch' value='false'> Do not ignore prefetch/prerender requests
</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='ignore_visitor' value='false'> Ignore current visitor
</label>
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</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>Insert this snippet somewhere between <head></head> tags, make sure it appears on each page</p>
<p><textarea id='end-code' class="no-translate" readonly onclick="this.select();"></textarea></p>
<p>Insert this snippet somewhere between <body></body> tags, to track users with disabled Javascript</p>
<p><textarea id='pixel-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/1.11.3/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.web;
$("#cdnjs").val($("#cdnjs").val().replace("/version/", "/"+sdk.version+"/"));
$("#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);
$("#source-server").val(stripTrailingSlash(params.server)+"/sdk/web/countly.min.js");
}
else{
$(".server").hide();
}
if(params.app_key){
$("#app_key").val(params.app_key);
}
if(params.server && params.app_key){
$(".configuration").hide();
}
var template = "<script type='text/javascript'>\n"+
"//some default pre init\n"+
"var Countly = Countly || {};\n"+
"Countly.q = Countly.q || [];\n"+
"\n"+
"//provide countly initialization parameters\n"+
"Countly.app_key = 'YOUR_APP_KEY';\n"+
"Countly.url = 'http://yourdomain.com';\n"+
"[options]\n"+
"\n"+
"[features]\n"+
"\n"+
"//load countly script asynchronously\n"+
"(function() {\n"+
" var cly = document.createElement('script'); cly.type = 'text/javascript';\n"+
" cly.async = true;\n"+
" //enter url of script here\n"+
" cly.src = '/path/to/countly.min.js';\n"+
" cly.onload = function(){Countly.init()};\n"+
" var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);\n"+
"})();\n"+
"</scri" + "pt>";
var pixel_template = "<noscript><img src='http://domain.com/pixel.png?app_key=YOUR_APP_KEY&begin_session=1'/></noscript>";
$("#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>');
$(".configuration").show();
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>');
$(".configuration").show();
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>');
$(".configuration").show();
return;
}
data.src = $("input:radio[name=source]:checked").val();
if(data.src == "custom")
data.src = $("#custom-source").val();
if(!data.src || data.src == ""){
$(".source").prepend('<div class="alert alert-danger" role="alert">Please select at least one source</div>');
return;
}
data.features = $(".feature:checked").map(function(feature){
return this.value;
}).get();
if(data.features.length){
data.features = "Countly.q.push(['"+data.features.join("']);\nCountly.q.push(['")+"']);";
}
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 = "Countly."+data.options.join("\nCountly.")+"\n";
}
else{
data.options = "";
}
var code = template.replace("http://yourdomain.com", data.url)
.replace("YOUR_APP_KEY", data.app_key)
.replace("/path/to/countly.min.js", data.src)
.replace("[options]\n", data.options)
.replace("[features]", data.features);
$("#end-code").val(code);
var pixel = pixel_template.replace("http://domain.com", data.url)
.replace("YOUR_APP_KEY", data.app_key);
$("#pixel-code").val(pixel);
$('#end-modal').modal();
});
$("#allfeatures").change(function(){
$(".feature").prop('checked', $(this).prop("checked"));
});
$("#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, "web-sdk.txt");
} catch (e) {
alert(data);
}
});
});
</script>
</body>
</html>