web-manager 3.2.0 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +67 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -172,14 +172,29 @@ function Manager() {
172
172
  });
173
173
 
174
174
  // Mouse leave event
175
- document.addEventListener('mouseleave', function() {
175
+ document.addEventListener('mouseleave', function () {
176
176
  showExitPopup(self);
177
177
  });
178
178
 
179
179
  // Window blur event
180
- window.addEventListener('blur', function() {
180
+ window.addEventListener('blur', function () {
181
181
  showExitPopup(self);
182
182
  });
183
+
184
+ // Re-focus events
185
+ window.addEventListener('focus', function () {
186
+ refreshNewVersion(self);
187
+ });
188
+ window.addEventListener('online', function () {
189
+ refreshNewVersion(self);
190
+ });
191
+ setInterval(function () {
192
+ refreshNewVersion(self);
193
+ }, self.properties.meta.environment === 'development'
194
+ ? 1000
195
+ : (1000 * 60 * 60 * 24 * 7)
196
+ );
197
+
183
198
  }
184
199
 
185
200
  function _authStateHandler(self, user) {
@@ -415,7 +430,7 @@ function Manager() {
415
430
  message: 'Get 15% off your purchase of our <strong>Premium plans</strong>. <br><br> Get access to all features and unlimited usage.',
416
431
  okButton: {
417
432
  text: 'Claim 15% Discount',
418
- link: '/pricing?utm_source=exitpopup&utm_medium=popup&utm_campaign=exitpopup',
433
+ link: '/pricing?utm_source=exit-popup&utm_medium=popup&utm_campaign={pathname}',
419
434
  },
420
435
  },
421
436
  },
@@ -545,8 +560,11 @@ function Manager() {
545
560
  var pagePathname = window.location.pathname;
546
561
  var redirect = false;
547
562
 
548
- self.properties.page.queryString.forEach(function(value, key) {
549
- if (key.startsWith('utm_')) {
563
+ var previousUTMTimestamp = new Date(store.get('utm.timestamp', 0));
564
+ var UTMDifferenceInHours = (new Date() - previousUTMTimestamp) / 36e5;
565
+
566
+ self.properties.page.queryString.forEach(function (value, key) {
567
+ if (key.startsWith('utm_') && UTMDifferenceInHours > 72) {
550
568
  store.set('utm.tags.' + key, value);
551
569
  store.set('utm.timestamp', new Date().toISOString());
552
570
  }
@@ -1082,17 +1100,19 @@ function Manager() {
1082
1100
  function showExitPopup(self) {
1083
1101
  var exitPopupSettings = self.properties.options.exitPopup;
1084
1102
 
1085
- if (!exitPopupSettings.enabled) return;
1103
+ if (!exitPopupSettings.enabled) {
1104
+ return;
1105
+ };
1086
1106
 
1087
1107
  var lastTriggered = new Date(storage.get('exitPopup.lastTriggered', 0));
1088
1108
  var now = new Date();
1089
1109
  var diff = now - lastTriggered;
1090
1110
 
1091
- if (diff < exitPopupSettings.config.timeout) return;
1111
+ if (diff < exitPopupSettings.config.timeout) {
1112
+ return;
1113
+ };
1092
1114
 
1093
1115
  showBootstrapModal(exitPopupSettings);
1094
-
1095
- storage.set('exitPopup.lastTriggered', now.toISOString());
1096
1116
  }
1097
1117
 
1098
1118
  function showBootstrapModal(exitPopupSettings) {
@@ -1100,7 +1120,9 @@ function Manager() {
1100
1120
  ? exitPopupSettings.config.handler()
1101
1121
  : true;
1102
1122
 
1103
- if (!proceed) { return }
1123
+ if (!proceed) {
1124
+ return;
1125
+ }
1104
1126
 
1105
1127
  var $el = document.getElementById('modal-exit-popup');
1106
1128
  try {
@@ -1113,15 +1135,49 @@ function Manager() {
1113
1135
  var $okButton = $el.querySelector('.modal-footer .btn-primary');
1114
1136
  var config = exitPopupSettings.config;
1115
1137
 
1138
+ var link = config.okButton.link
1139
+ .replace(/{pathname}/ig, window.location.pathname)
1140
+
1116
1141
  $title.innerHTML = config.title;
1117
1142
  $message.innerHTML = config.message;
1118
1143
  $okButton.innerHTML = config.okButton.text;
1119
- $okButton.setAttribute('href', config.okButton.link);
1144
+ $okButton.setAttribute('href', link);
1145
+
1146
+ storage.set('exitPopup.lastTriggered', new Date().toISOString());
1120
1147
  } catch (e) {
1121
1148
  console.warn(e);
1122
1149
  }
1123
1150
  }
1124
1151
 
1152
+ function refreshNewVersion(self) {
1153
+ console.log('refreshNewVersion()');
1154
+
1155
+ fetch('/@output/build/build.json' + '?cb=' + new Date().getTime())
1156
+ .then(function (res) {
1157
+ if (res.ok) {
1158
+ return res.json();
1159
+ } else {
1160
+ throw new Error('Bad response');
1161
+ }
1162
+ })
1163
+ .then(function (data) {
1164
+ var buildTime = new Date(data['npm-build'].timestamp_utc);
1165
+ var startTime = self.properties.page.startTime;
1166
+
1167
+ if (buildTime > startTime) {
1168
+ // console.log('refreshNewVersion(): Refreshing...');
1169
+
1170
+ window.onbeforeunload = function () {
1171
+ return undefined;
1172
+ }
1173
+ window.location.reload(true);
1174
+ }
1175
+ })
1176
+ .catch(function (e) {
1177
+ console.error(e);
1178
+ })
1179
+ }
1180
+
1125
1181
  /*
1126
1182
  EXTERNAL LIBS
1127
1183
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.2.00",
3
+ "version": "3.2.2",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "index.js",
6
6
  "scripts": {