-
Notifications
You must be signed in to change notification settings - Fork 101
/
example.html
322 lines (316 loc) · 11.1 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
<!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">.logEvent()</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">
</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="https://cdn.branch.io/branch-latest.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 banner closeBanner closeJourney data deepview deepviewCta first init link logout removeListener setBranchViewData setIdentity track trackCommerceEvent logEvent disableTracking getBrowserFingerprintId crossPlatformIds lastAttributedTouchData setAPIResponseCallback qrCode setRequestMetaData setDMAParamsForEEA setAPIUrl getAPIUrl".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 DOMPurify.sanitize(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.text("branch.setIdentity('" + identity + "');");
branch.setIdentity(identity, function(err, data) {
response.text(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.logEvent(\' this event\');');
var event_and_custom_data = {
"transaction_id": "tras_Id_1232343434",
"currency": "USD",
"revenue": 180.2,
"shipping": 10.5,
"tax": 13.5,
"coupon": "promo-1234",
"affiliation": "high_fi",
"description": "Preferred purchase",
"purchase_loc": "Palo Alto",
"store_pickup": "unavailable"
};
var content_items = [
{
"$content_schema": "COMMERCE_PRODUCT",
"$og_title": "Nike Shoe",
"$og_description": "Start loving your steps",
"$og_image_url": "http://example.com/img1.jpg",
"$canonical_identifier": "nike/1234",
"$publicly_indexable": false,
"$price": 101.2,
"$locally_indexable": true,
"$quantity": 1,
"$sku": "1101123445",
"$product_name": "Runner",
"$product_brand": "Nike",
"$product_category": "Sporting Goods",
"$product_variant": "XL",
"$rating_average": 4.2,
"$rating_count": 5,
"$rating_max": 2.2,
"$creation_timestamp": 1499892854966,
"$exp_date": 1499892854966,
"$keywords": [ "sneakers", "shoes" ],
"$address_street": "230 South LaSalle Street",
"$address_city": "Chicago",
"$address_region": "IL",
"$address_country": "US",
"$address_postal_code": "60604",
"$latitude": 12.07,
"$longitude": -97.5,
"$image_captions": [ "my_img_caption1", "my_img_caption_2" ],
"$condition": "NEW",
"$custom_fields": {"foo1":"bar1","foo2":"bar2"}
},
{
"$og_title": "Nike Woolen Sox",
"$canonical_identifier": "nike/5324",
"$og_description": "Fine combed woolen sox for those who love your foot",
"$publicly_indexable": false,
"$price": 80.2,
"$locally_indexable": true,
"$quantity": 5,
"$sku": "110112467",
"$product_name": "Woolen Sox",
"$product_brand": "Nike",
"$product_category": "Apparel & Accessories",
"$product_variant": "Xl",
"$rating_average": 3.3,
"$rating_count": 5,
"$rating_max": 2.8,
"$creation_timestamp": 1499892854966
}];
var customer_event_alias = "my custom alias";
branch.logEvent(
"PURCHASE",
event_and_custom_data,
content_items,
customer_event_alias,
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">');
});
});
$('#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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.4.3/purify.min.js" integrity="sha512-3dcbndbDLLWfKWevQu8C/1qVRcxx6h+eRDSnn3/pcBZHISRJgsj3u71U/Ad6nQVHrEi05hOSr6Hnb/p0pWc94w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</html>