-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_notify.html
225 lines (204 loc) · 8.63 KB
/
web_notify.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
<!DOCTYPE html>
<html>
<!-- UA Web Push: 0b3d476922:1569603225255 -->
<head>
<meta charset="utf-8">
<title>push playground</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div id="example"></div>
<script id="template" type="text/ractive">
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">
<span class="label label-default">UA</span> UA Web Notify Demo: Prod Goat
</a>
</div>
{{#if sdk}}
{{#if !channel.optedIn}}
{{#if secure}}
<button on-click="sdk.register()" type="button" class="btn btn-default navbar-btn navbar-right">Register</button>
{{else}}
<p class="navbar-text navbar-right">
<a target="_blank" href="{{registrationURL}}">Register on secure site</a>
</p>
{{/if}}
{{else}}
<p class="navbar-text navbar-right"><a on-click="channel.optOut()">opt out of push</a></p>
{{/if}}
{{/if}}
</div>
</nav>
<div class="container">
<div class="row">
{{#each tags}}
<div class="container col-md-4">
<div class="well">
<h3>{{this}}
<small class="pull-right">
{{#if channel.optedIn}}
{{#if channel.tags.has(this)}}
☑️ Subscribed <a on-click="channel.tags.remove(this)" class="close" style="float:none;" aria-label="Close"><span aria-hidden="true">×</span></a>
{{else}}
<a on-click="channel.tags.add(this)">Subscribe</a>
{{/if}}
{{/if}}
</small>
</h3>
<p>
Get the latest {{this}} updates.
</p>
</div>
</div>
{{/each}}
</div>
<div class="row">
<div class="container">
<p>
{{#if channel}}
{{#if channel.namedUser.id}}
named_user: <b>{{channel.namedUser.id}}</b> <a on-click="channel.namedUser.remove()" class="label label-default">𝗫</a>
{{else}}
set named_user: <input value="{{user}}"> <button on-click="channel.namedUser.set(user)" class="btn">set</button>
{{/if}}
{{/if}}
</p>
</div>
</div>
<div class="row">
<div class="container">
<p><button class="btn" on-click="@this.customEvent(@event)">Click me for custom event</button></p>
</div>
</div>
{{#if channel}}
<pre>
ID: {{channel.id}}
optedIn: {{channel.optedIn}}
namedUser: {{channel.namedUser.id}}
{{#if channel.tags.list}}TAGS:
{{#each channel.tags.list:group}}{{group}}: {{JSON.stringify(this)}}{{/each}}
{{/if}}
{{JSON.stringify(channel, null, 2)}}
{{#if push}}
--
Latest push:
{{JSON.stringify(push, null, 2)}}
{{/if}}
{{#if customEvent}}
--
Custom event sent:
{{JSON.stringify(customEvent, null, 2)}}
{{/if}}
// You can open up your web inspector and add/remove tags to channel in the
// console with these commands:
> UA.then(sdk => sdk.channel.tags.add('your-tag'))
> UA.then(sdk => sdk.channel.tags.remove('your-tag'))
</pre>
<small><a class="text-muted" on-click="@this.clear()">Clear local storage</a></small>
{{/if}}
</div>
</script>
<script type="text/javascript">
const options = {
appKey: 'ISex_TTJRuarzs9-o_Gkhg',
token: 'MTpJU2V4X1RUSlJ1YXJ6czktb19Ha2hnOkZyc3F4THdzVzNUWDBnZkZMZ2MwTG9BY2dkQ0t0STR2VnJ6Tm9lS2QtZGM',
vapidPublicKey: 'BFAX8NDGwnWeDbTsGjn6TpCmY6uoJ8SXrexaQR3MR+OU6TwbbjgWDKaZuxturl2CvbU7QTOb4NiD5w1YxOMoLB4=',
debug: false,
workerUrl: '/push-worker.js',
websitePushId: 'web.com.urbanairship.safari.test',
secureIframeUrl: 'https://jumpinggrendel.github.io/secure-bridge.html'
}
!function(n,t,c,e,u){function r(n){try{f=n(u)}catch(n){return h=n,void i(p,n)}i(s,f)}function i(n,t){for(var c=0;c<n.length;c++)d(n[c],t);
}function o(n,t){return n&&(f?d(n,f):s.push(n)),t&&(h?d(t,h):p.push(t)),l}function a(n){return o(!1,n)}function d(t,c){
n.setTimeout(function(){t(c)},0)}var f,h,s=[],p=[],l={then:o,catch:a,_setup:r};n[e]=l;var v=t.createElement("script");
v.src=c,v.async=!0,v.id="_uasdk",v.rel=e,t.head.appendChild(v)}(window,document,'https://aswpsdkus.com/notify/v1/ua-sdk.min.js',
'UA', options)
</script>
<script src="ractive.min.js" type="text/javascript"></script>
<script type="text/javascript">
let channel = ''
const ractive = new Ractive({
el: '#example',
template: '#template',
data: {
tags: ['Basketball', 'Politics', 'Potent Potables'],
channel: null,
sdk: null,
push: null,
user: null,
customEvent: null,
registrationURL: 'https://jumpinggrendel.github.io/web_notify.html',
secure: !!window.location.protocol.match('https')
},
// Just for demo purposes
clear: () => {localStorage.clear(); location.reload()},
customEvent: ev => {
console.log(ev)
UA.then(sdk => {
const c = new sdk.CustomEvent('demo_page_button', 1, {
x: ev.offsetX,
y: ev.offsetY
})
ractive.set('customEvent', c.toJSON())
c.track()
})
}
})
UA.then(function(sdk) {
channel = sdk.channel
ractive.set({sdk: sdk, channel: sdk.channel})
sdk.addEventListener('channel', ev => ractive.set({channel: ev.channel}))
sdk.addEventListener('tags', ev => ractive.update('channel.tags'))
sdk.addEventListener('push', ev => ractive.set('push', ev.push))
}).catch(function(e) {
console.log(e)
}).catch(function(e) {
console.log('STILL BAD', e)
})
var optimoveSDKToken = 'c8bcd75214d35b386d74f4c76c3cb3aca3adab0329413963c733d80fe5384c0e';
var optimoveSDKVersion = '1.0.7';
var optimoveSDKconfigVersion = 'shopify.1.0.0';
// ---------------------------------------
// Function: createOptimoveSDK
// Args: resourceURL, callback
// creates JS script that is async
// ---------------------------------------
function createOptimoveSDK(resourceURL, callback) {
console.log('In createOptimoveSDK() '+resourceURL);
if (resourceURL != null) {
var d = document;
var g = d.createElement('script');
var s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = resourceURL;
g.onload = callback;
s.parentNode.insertBefore(g, s);
}
}
// ---------------------------------------
// Function: initializeOptimoveSDK
// Args: --
// initializes optimove SDK with sdk details provided to you by Product Integration team
// ---------------------------------------
function initializeOptimoveSDK() {
console.log('In initializeOptimoveSDK()');
optimoveSDK.initialize(optimoveSDKToken, optimoveSDKconfigVersion, loadOptimoveSDKFunctions, 'info');
}
// ---------------------------------------
// Function: loadOptimoveSDKFunctions
// Args: status
// Use this function to trigger GTM tags that will run Optimove SDK functions
// ---------------------------------------
function loadOptimoveSDKFunctions(status) {
console.log('In loadOptimoveSDKFunctions() = ' + status);
optimoveSDK.API.reportEvent('Rando_Event', {ua_channel_id:channel})
}
createOptimoveSDK('https://sdk-cdn.optimove.net/websdk/sdk-v'+optimoveSDKVersion+'.js', initializeOptimoveSDK);
</script>
</body>
</html>