-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
299 lines (297 loc) · 11.2 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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 class="info">Reading session from .init()...</pre>
<br>
<h4>Request</h4>
<pre class="request">Click a button!</pre>
<br>
<h4>Response</h4>
<pre class="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>
<input class="example-input" type="text" id="identityID" class="form-control" placeholder="test@test.com">
<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>
</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="referrals" class="btn btn-info">.referrals()</button>
<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 banner closeBanner creditHistory credits data first getCode init link logout redeem referrals removeListener sendSMS setIdentity track validateCode".split(" "),0);
branch.init('5680621892404085', function(err, data) {
document.getElementsByClassName('info')[0].innerHTML = JSON.stringify(data);
});
</script>
<script type="text/javascript">
var info = $('.info');
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();');
branch.init('5680621892404085', function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#data').click(function() {
request.html('branch.data();');
branch.data(function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#setIdentity').click(function() {
var identity = getInputVal('#identityID');
request.html("branch.setIdentity('" + identity + "');");
branch.setIdentity(identity, function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#logout').click(function() {
request.html('branch.logout();');
branch.logout(function(err, data) {
response.html(JSON.stringify(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(JSON.stringify(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>');
});
});
$('#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(JSON.stringify(err || 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(JSON.stringify(err || data || 'undefined'));
});
});
$('#referrals').click(function() {
request.html('branch.referrals();');
branch.referrals(function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#credits').click(function() {
request.html('branch.credits();');
branch.credits(function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#creditHistory').click(function() {
request.html('branch.creditHistory();');
branch.creditHistory(function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#applyCode').click(function() {
request.html('branch.applyCode({code: ' + getInputVal('#code-input') + '});');
branch.applyCode(getInputVal('#code-input'), 'default', function(err, data) {
response.html(JSON.stringify(err || data));
});
});
$('#validateCode').click(function() {
request.html('branch.validateCode({code: ' + getInputVal('#code-input') + '});');
branch.validateCode(getInputVal('#code-input'), 'default', function(err, data) {
response.html(JSON.stringify(err || 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(JSON.stringify(err || 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(JSON.stringify(err || 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"}' +
'});'
);
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',
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
}, // Banner Options
sampleParams // Link data or string of link
);
response.html('none');
});
</script>
</body>
</html>