· 6 years ago · Oct 07, 2019, 05:56 PM
1if (!(window.isMobileApp || window.isMobileAppDeprecated)) {
2 +function(a, p, P, b, y) {
3 a.appboy = {};
4 a.appboyQueue = [];
5
6 var s = [
7 'initialize',
8 'destroy',
9 'getDeviceId',
10 'toggleAppboyLogging',
11 'setLogger',
12 'openSession',
13 'changeUser',
14 'requestImmediateDataFlush',
15 'requestFeedRefresh',
16 'subscribeToFeedUpdates',
17 'requestContentCardsRefresh',
18 'subscribeToContentCardsUpdates',
19 'logCardImpressions',
20 'logCardClick',
21 'logCardDismissal',
22 'logFeedDisplayed',
23 'logContentCardsDisplayed',
24 'logInAppMessageImpression',
25 'logInAppMessageClick',
26 'logInAppMessageButtonClick',
27 'logInAppMessageHtmlClick',
28 'subscribeToNewInAppMessages',
29 'subscribeToInAppMessage',
30 'removeSubscription',
31 'removeAllSubscriptions',
32 'logCustomEvent',
33 'logPurchase',
34 'isPushSupported',
35 'isPushBlocked',
36 'isPushGranted',
37 'isPushPermissionGranted',
38 'registerAppboyPushMessages',
39 'unregisterAppboyPushMessages',
40 'trackLocation',
41 'stopWebTracking',
42 'resumeWebTracking',
43 'wipeData',
44 'ab',
45 'ab.DeviceProperties',
46 'ab.User',
47 'ab.User.Genders',
48 'ab.User.NotificationSubscriptionTypes',
49 'ab.User.prototype.getUserId',
50 'ab.User.prototype.setFirstName',
51 'ab.User.prototype.setLastName',
52 'ab.User.prototype.setEmail',
53 'ab.User.prototype.setGender',
54 'ab.User.prototype.setDateOfBirth',
55 'ab.User.prototype.setCountry',
56 'ab.User.prototype.setHomeCity',
57 'ab.User.prototype.setLanguage',
58 'ab.User.prototype.setEmailNotificationSubscriptionType',
59 'ab.User.prototype.setPushNotificationSubscriptionType',
60 'ab.User.prototype.setPhoneNumber',
61 'ab.User.prototype.setAvatarImageUrl',
62 'ab.User.prototype.setLastKnownLocation',
63 'ab.User.prototype.setUserAttribute',
64 'ab.User.prototype.setCustomUserAttribute',
65 'ab.User.prototype.addToCustomAttributeArray',
66 'ab.User.prototype.removeFromCustomAttributeArray',
67 'ab.User.prototype.incrementCustomUserAttribute',
68 'ab.User.prototype.addAlias',
69 'ab.User.prototype.setCustomLocationAttribute',
70 'ab.InAppMessage',
71 'ab.InAppMessage.SlideFrom',
72 'ab.InAppMessage.ClickAction',
73 'ab.InAppMessage.DismissType',
74 'ab.InAppMessage.OpenTarget',
75 'ab.InAppMessage.ImageStyle',
76 'ab.InAppMessage.TextAlignment',
77 'ab.InAppMessage.Orientation',
78 'ab.InAppMessage.CropType',
79 'ab.InAppMessage.prototype.subscribeToClickedEvent',
80 'ab.InAppMessage.prototype.subscribeToDismissedEvent',
81 'ab.InAppMessage.prototype.removeSubscription',
82 'ab.InAppMessage.prototype.removeAllSubscriptions',
83 'ab.InAppMessage.prototype.closeMessage',
84 'ab.InAppMessage.Button',
85 'ab.InAppMessage.Button.prototype.subscribeToClickedEvent',
86 'ab.InAppMessage.Button.prototype.removeSubscription',
87 'ab.InAppMessage.Button.prototype.removeAllSubscriptions',
88 'ab.SlideUpMessage',
89 'ab.ModalMessage',
90 'ab.FullScreenMessage',
91 'ab.HtmlMessage',
92 'ab.ControlMessage',
93 'ab.Feed',
94 'ab.Feed.prototype.getUnreadCardCount',
95 'ab.ContentCards',
96 'ab.ContentCards.prototype.getUnviewedCardCount',
97 'ab.Card',
98 'ab.ClassicCard',
99 'ab.CaptionedImage',
100 'ab.Banner',
101 'ab.ControlCard',
102 'ab.WindowUtils',
103 'display',
104 'display.automaticallyShowNewInAppMessages',
105 'display.showInAppMessage',
106 'display.showFeed',
107 'display.destroyFeed',
108 'display.toggleFeed',
109 'display.showContentCards',
110 'display.hideContentCards',
111 'display.toggleContentCards',
112 'sharedLib',
113 ];
114
115 for (var i = 0; i < s.length; i++) {
116 var m = s[i];
117 var k = a.appboy;
118 var l = m.split('.');
119
120 for (var j = 0; j < l.length - 1; j++) {
121 k = k[l[j]];
122 }
123
124 k[l[j]] = new Function(
125 'return function ' + m.replace(/\./g, '_') + '()' +
126 '{ window.appboyQueue.push(arguments); return true; }'
127 )();
128 }
129
130 window.appboy.getUser = function() {
131 return new window.appboy.ab.User();
132 };
133
134 window.appboy.getCachedFeed = function() {
135 return new window.appboy.ab.Feed();
136 };
137
138 window.appboy.getCachedContentCards = function() {
139 return new window.appboy.ab.ContentCards();
140 };
141
142 (y = p.createElement(P)).type = 'text/javascript';
143 y.src = 'https://js.appboycdn.com/web-sdk/2.4/appboy.min.js';
144 y.async = 1;
145 (b = p.getElementsByTagName(P)[0]).parentNode.insertBefore(y, b);
146 }(window, document, 'script');
147
148 window.appboy.initialize({{Braze API Key}}, {
149 baseUrl: {{Braze Base URL}},
150 enableLogging: {{Environment Name}} === 'Cris',
151 manageServiceWorkerExternally: true,
152 });
153
154 window.appboy.subscribeToInAppMessage(function(inAppMessage) {
155 var message = inAppMessage[0];
156 var shouldDisplay = true;
157
158 if (
159 message !== null &&
160 inAppMessage instanceof window.appboy.ab.InAppMessage
161 ) {
162 var msgId = inAppMessage.extras['msg-id'];
163
164 if (msgId === 'push-primer') {
165 if (
166 !window.appboy.isPushSupported() ||
167 window.appboy.isPushPermissionGranted() ||
168 window.appboy.isPushBlocked()
169 ) {
170 shouldDisplay = false;
171 }
172
173 if (inAppMessage.buttons[0] !== null) {
174 inAppMessage.buttons[0].subscribeToClickedEvent(function() {
175 window.appboy.registerAppboyPushMessages();
176 });
177 }
178 }
179 }
180
181 if (shouldDisplay) {
182 window.appboy.display.showInAppMessage(message);
183 }
184 });
185
186 if (window.userId && window.userId !== 'null') {
187 window.appboy.changeUser(window.userId);
188 }
189
190 window.appboy.openSession();
191}