-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
378 lines (375 loc) · 14.4 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="http://branch.io/img/logo_icon_black.png" property="og:image" />
<meta content="Branch Metrics Web SDK Example App" property="og:title" />
<meta content="A basic example to demonstrate some of the ways that the Web SDK can be used" property="og:description" />
<meta content='key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv' name='branch_key'/>
<title>Branch Metrics Web SDK Example App</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style type="text/css">
.btn {
margin-top: 5px;
}
.example-input {
width: 125px;
display: inline-block;
margin-top: 5px;
vertical-align: middle;
}
.radio-input {
margin-right: 10px !important;
margin-left: 20px !important;
}
.row {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="container">
<div class="row col-lg-8 col-lg-offset-2">
<h2>Branch Metrics Web SDK Example</h2>
</div>
<section>
<div class="row col-lg-8 col-lg-offset-2">
<h4>Session Info</h4>
<pre id="info">Reading session from .init()...</pre>
<br>
<h4>Request</h4>
<pre id="request">Click a button!</pre>
<br>
<h4>Response</h4>
<pre id="response">Click a button!</pre>
</div>
</section>
<section>
<div class="row col-lg-8 col-lg-offset-2">
<h3>Methods</h3>
<hr>
<h4>Session and Identity</h4>
<div class="group">
<button id="init" class="btn btn-success">.init()</button>
<button id="data" class="btn btn-info">.data()</button>
<button id="first" class="btn btn-info">.first()</button>
<input class="example-input" type="text" id="identityID" class="form-control" placeholder="[email protected]">
<button id="setIdentity" class="btn btn-info">.setIdentity()</button>
<button id="logout" class="btn btn-info">.logout()</button>
</div>
</div>
<div class="row col-lg-8 col-lg-offset-2">
<h4>Sharing and Tracking</h4>
<div class="group">
<button id="track" class="btn btn-info">.track()</button>
<button id="link" class="btn btn-info">.link()</button>
<button id="banner" class="btn btn-info">.banner()</button>
<button id="disable-tracking" class="btn btn-info">.disableTracking(true)</button>
<button id="enable-tracking" class="btn btn-info">.disableTracking(false)</button>
</div>
</div>
<div class="row col-lg-8 col-lg-offset-2">
<h4>QR Code</h4>
<div class="group">
<button id="qrCode" class="btn btn-info">.qrCode()</button>
</div>
</div>
<div class="row col-lg-8 col-lg-offset-2">
<h4>SMS</h4>
<div class="group">
<input class="example-input" type="text" id="SMSNumber" class="form-control" placeholder="1234567890">
<button id="sendSMS" class="btn btn-info">.sendSMS(#, linkData, {})</button>
<button id="sendSMSNew" class="btn btn-info">.sendSMS(#, linkData, {make_new_link: true})</button>
</div>
</div>
<div class="row col-lg-8 col-lg-offset-2">
<h4>Referral</h4>
<div class="group">
<button id="credits" class="btn btn-info">.credits()</button>
<button id="creditHistory" class="btn btn-info">.creditHistory()</button><br><br>
<input class="example-input" type="text" id="redeem-amount" class="form-control" placeholder="Credits">
<input class="example-input" type="text" id="redeem-bucket" class="form-control" placeholder="from Bucket"><br>
<button id="redeem" class="btn btn-info">.redeem()</button>
</div>
</div>
<div class="row col-lg-8 col-lg-offset-2">
<h4>Codes</h4>
<div class="group">
<input class="example-input" type="text" id="code-amount" class="form-control" placeholder="Amount">
<input class="example-input" type="text" id="code-bucket" class="form-control" placeholder="Bucket">
<input class="example-input" type="text" id="code-prefix" class="form-control" placeholder="Prefix">
<input class="example-input" type="text" id="code-expiration" class="form-control" placeholder="Expiration"><br><br>
<h6>How many times can this code be used?</h6>
<input class="radio-input" type="radio" name="code-type" value="1">Unlimted (1)
<input class="radio-input" type="radio" name="code-type" value="0">One Time Use (0)<br><br>
<h6>Who Gets the Points?</h6>
<input class="radio-input" type="radio" name="code-location" value="0">Referree (0)
<input class="radio-input" type="radio" name="code-location" value="2">Referrer (2)
<input class="radio-input" type="radio" name="code-location" value="3">Both (3)<br><br>
</div>
<div class="group">
<button id="getCode" class="btn btn-info">.getCode()</button>
</div>
</div>
<div class="row col-lg-8 col-lg-offset-2">
<div class="group">
<input class="example-input" type="text" id="code-input" class="form-control" placeholder="Code"><br>
<button id="validateCode" class="btn btn-info">.validateCode()</button>
<button id="applyCode" class="btn btn-info">.applyCode()</button>
</div>
</div>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
(function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="dist/build.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent logEvent disableTracking getBrowserFingerprintId crossPlatformIds lastAttributedTouchData setAPIResponseCallback qrCode".split(" "), 0);
branch.setAPIResponseCallback(function(url, method, requestBody, error, status, responseBody) {
console.log('Request: ' + method + ' ' + url + ' body=' + JSON.stringify(requestBody));
if (error) {
console.log('Response: Error ' + error + '; status ' + JSON.stringify(status) + ' body=' + JSON.stringify(responseBody));
}
else {
console.log('Response: status ' + JSON.stringify(status) + ' body=' + JSON.stringify(responseBody));
}
});
// Take the Branch key from a meta tag
branch.init($('meta[name="branch_key"]').attr('content'), function(err, data) {
// Avoid XSS by HTML escaping the data for display
$('#info').text(JSON.stringify(data));
});
</script>
<script type="text/javascript">
var request = $('#request');
var response = $('#response');
var sampleParams = {
tags: [ 'tag1', 'tag2' ],
channel: 'sample app',
feature: 'create link',
stage: 'created link',
type: 1,
data: {
mydata: 'bar',
'$desktop_url': 'https://cdn.branch.io/example.html',
'$og_title': 'Branch Metrics',
'$og_description': 'Branch Metrics',
'$og_image_url': 'http://branch.io/img/logo_icon_white.png'
}
};
var getInputVal = function(inputID) {
var inputElement = $(inputID);
if (!inputElement.val()) {
inputElement.parent().addClass('has-error');
return '';
}
else {
inputElement.parent().removeClass('has-error');
}
return inputElement.val();
};
$('#init').click(function() {
request.html('branch.init();');
// Take the Branch key from a meta tag
branch.init($('meta[name="branch_key"]').attr('content'), function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#data').click(function() {
request.html('branch.data();');
branch.data(function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#first').click(function() {
request.html('branch.first();');
branch.first(function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#setIdentity').click(function() {
var identity = getInputVal('#identityID');
request.html("branch.setIdentity('" + identity + "');");
branch.setIdentity(identity, function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#logout').click(function() {
request.html('branch.logout();');
branch.logout(function(err, data) {
response.html(err || 'undefined');
});
});
$('#track').click(function() {
request.html('branch.track(\'Tracked this event\');');
branch.track(
'Tracked this event',
{
'metadata foo': 'metadata bar'
},
function(err) {
response.html(err || 'no error');
});
});
$('#link').click(function() {
request.html('branch.link(' + JSON.stringify(sampleParams) + ');');
branch.link(sampleParams, function(err, link) {
response.html('<a href="' + link + '">' + link + '</a>');
});
});
$('#qrCode').click(function() {
var qrCodeSettings = {
"code_color":"#000000",
"background_color": "#FFFFFF",
"margin": 5,
"width": 1000,
"image_format": "png"
};
var qrCodeParams = {
tags: [ 'tag1', 'tag2' ],
channel: 'sample app',
feature: 'create link',
stage: 'created link',
type: 1,
data: {
mydata: 'bar',
'$desktop_url': 'https://cdn.branch.io/example.html',
'$og_title': 'Branch Metrics',
'$og_description': 'Branch Metrics',
'$og_image_url': 'http://branch.io/img/logo_icon_white.png'
}
};
branch.qrCode(qrCodeParams, qrCodeSettings, function(err, qrCode) {
response.html('<img src="data:image/png;charset=utf-8;base64,' + qrCode.base64() + '" width="500" height="500">');
});
});
$('#sendSMS').click(function() {
var smsOptions = {};
var phone = getInputVal('#SMSNumber');
request.html('branch.sendSMS(' + phone + ', ' + JSON.stringify(sampleParams) + ', ' + smsOptions + ');');
branch.sendSMS(phone, sampleParams, smsOptions, function(err, data) {
response.html(err || JSON.stringify(data) || 'undefined');
});
});
$('#sendSMSNew').click(function() {
var smsOptions = { make_new_link: true };
var phone = getInputVal('#SMSNumber');
request.html('branch.sendSMS(' + phone + ', ' + JSON.stringify(sampleParams) + ', ' + smsOptions + ');');
branch.sendSMS(phone, sampleParams, smsOptions, function(err, data) {
response.html(err || JSON.stringify(data) || 'undefined');
});
});
$('#referrals').click(function() {
request.html('branch.referrals();');
branch.referrals(function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#credits').click(function() {
request.html('branch.credits();');
branch.credits(function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#creditHistory').click(function() {
request.html('branch.creditHistory();');
branch.creditHistory(function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#applyCode').click(function() {
request.html('branch.applyCode({code: ' + getInputVal('#code-input') + '});');
branch.applyCode(getInputVal('#code-input'), 'default', function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#validateCode').click(function() {
request.html('branch.validateCode({code: ' + getInputVal('#code-input') + '});');
branch.validateCode(getInputVal('#code-input'), 'default', function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#getCode').click(function() {
request.html(
'branch.getCode({ amount: ' + getInputVal("#code-amount") +
', calculation_type: ' + getInputVal("input:radio[name ='code-type']:checked") +
', location: ' + getInputVal("input:radio[name ='code-location']:checked") +
', bucket: ' + getInputVal("#code-bucket") +
', prefix: ' + getInputVal("#code-prefix") +
', expiration: ' + getInputVal("#code-expiration") +
' });'
);
branch.getCode({
amount: parseInt(getInputVal('#code-amount')),
calculation_type: parseInt(getInputVal("input:radio[name ='code-type']:checked")),
location: parseInt(getInputVal("input:radio[name ='code-location']:checked")),
bucket: getInputVal('#code-bucket'),
prefix: getInputVal('#code-prefix'),
expiration: getInputVal('#code-expiration')
}, function(err, data) {
response.html(err || JSON.stringify(data));
});
});
$('#redeem').click(function() {
request.html(
'branch.redeem({amount: ' + getInputVal('#redeem-amount') +
', bucket: \'' + getInputVal('#redeem-bucket') +
'\'});'
);
branch.redeem(
parseInt(getInputVal('#redeem-amount')),
getInputVal('#redeem-bucket'),
function(err, data) {
response.html(err || JSON.stringify(data));
}
);
});
$('#banner').click(function() {
request.html(
'branch.banner({icon: ' +
'"http://icons.iconarchive.com/icons/wineass/ios7-redesign/512/Appstore-icon.png",' +
'title: "Branch Demo App",' +
'description: "The Branch demo app!",' +
'data: {foo: "bar"},' +
'reviewCount: 1000,' +
'rating: 5,' +
'iframe: "true",' +
'showMobile: "true",' +
'showDesktop: "true",' +
'disableHide: "false",' +
'forgetHide: "false"' +
'});'
);
branch.banner(
{
icon: 'http://icons.iconarchive.com/icons/wineass/ios7-redesign/512/Appstore-icon.png',
title: 'Demo App',
description: 'Branch Demo app!',
openAppButtonText: 'Open',
downloadAppButtonText: 'Download',
reviewCount: 1000, // Review count
rating: 5, // Average rating from 0 to 5 in increments of .5
iframe: true, // Show banner in an iframe if CSS on your page is conflicting
showMobile: true, // true by default, just set here for an example
showDesktop: true, // true by default, just set here for an example
disableHide: false, // false by default, just set here for an example
forgetHide: false // false by default, just set here for an example
}, // Banner Options
sampleParams // Link data or string of link
);
response.html('none');
});
$('#disable-tracking').click(function() {
request.text('branch.disableTracking(true);');
branch.disableTracking(true, function() {
response.text('none');
});
});
$('#enable-tracking').click(function() {
request.text('branch.disableTracking(false);');
branch.disableTracking(false, function() {
response.text('none');
});
});
</script>
</body>
</html>