@vaadin/vaadin-usage-statistics
Advanced tools
Comparing version 2.0.0-alpha2 to 2.0.0-alpha3
@@ -9,7 +9,17 @@ { | ||
"name": "@vaadin/vaadin-usage-statistics", | ||
"version": "2.0.0-alpha2", | ||
"main": "index.js", | ||
"version": "2.0.0-alpha3", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"browserslist": [ | ||
"last 2 Chrome major versions", | ||
"last 2 Android major versions", | ||
"last 2 Firefox major versions", | ||
"last 2 Edge major versions", | ||
"last 2 Safari major versions", | ||
"last 2 iOS major versions", | ||
"Safari 9", | ||
"iOS 9", | ||
"IE 11" | ||
], | ||
"author": "Vaadin Ltd", | ||
@@ -26,2 +36,3 @@ "license": "Apache-2.0", | ||
}, | ||
"main": "vaadin-usage-statistics.js", | ||
"dependencies": { | ||
@@ -28,0 +39,0 @@ "@vaadin/vaadin-development-mode-detector": "^2.0.0-alpha2" |
import { runIfDevelopmentMode } from '@vaadin/vaadin-development-mode-detector/vaadin-development-mode-detector.js'; | ||
function usageStatistics() { | ||
function maybeGatherAndSendStats() { | ||
/** vaadin-dev-mode:start | ||
class StatisticsGatherer { | ||
constructor(logger) { | ||
this.now = new Date().getTime(); | ||
this.logger = logger; | ||
} | ||
(function () { | ||
'use strict'; | ||
frameworkVersionDetectors() { | ||
return { | ||
'Flow': function () { | ||
if (window.Vaadin && window.Vaadin.Flow && window.Vaadin.Flow.clients) { | ||
var flowVersions = Object.keys(window.Vaadin.Flow.clients) | ||
.map(key => window.Vaadin.Flow.clients[key]) | ||
.filter(client => client.getVersionInfo) | ||
.map(client => client.getVersionInfo().flow); | ||
if (flowVersions.length > 0) { | ||
return flowVersions[0]; | ||
} | ||
} | ||
}, | ||
'Vaadin Framework': function () { | ||
if (window.vaadin && window.vaadin.clients) { | ||
var frameworkVersions = Object.values(window.vaadin.clients) | ||
.filter(client => client.getVersionInfo) | ||
.map(client => client.getVersionInfo().vaadinVersion); | ||
if (frameworkVersions.length > 0) { | ||
return frameworkVersions[0]; | ||
} | ||
} | ||
}, | ||
'AngularJs': function () { | ||
if (window.angular && window.angular.version && window.angular.version) { | ||
return window.angular.version.full; | ||
} | ||
}, | ||
'Angular': function () { | ||
if (window.ng) { | ||
const tags = document.querySelectorAll("[ng-version]"); | ||
if (tags.length > 0) { | ||
return tags[0].getAttribute("ng-version"); | ||
} | ||
return "Unknown"; | ||
} | ||
}, | ||
'Backbone.js': function () { | ||
if (window.Backbone) { | ||
return window.Backbone.VERSION; | ||
} | ||
}, | ||
'React': function () { | ||
var reactSelector = '[data-reactroot], [data-reactid]'; | ||
if (!!document.querySelector(reactSelector)) { | ||
// React does not publish the version by default | ||
return "unknown"; | ||
} | ||
}, | ||
'Ember': function () { | ||
if (window.Em && window.Em.VERSION) { | ||
return window.Em.VERSION; | ||
} else if (window.Ember && window.Ember.VERSION) { | ||
return window.Ember.VERSION; | ||
} | ||
}, | ||
'jQuery': function () { | ||
if (typeof jQuery === 'function' && jQuery.prototype.jquery !== undefined) { | ||
return jQuery.prototype.jquery; | ||
} | ||
}, | ||
'Polymer': function () { | ||
if (window.Polymer && window.Polymer.version) { | ||
return window.Polymer.version; | ||
} | ||
}, | ||
'Vue.js': function () { | ||
if (window.Vue) { | ||
return window.Vue.version; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}; | ||
}(); | ||
get knownVaadinElementNames() { | ||
if (!this._knownVaadinElementNames) { | ||
const names = [ | ||
'vaadin-button', | ||
'vaadin-checkbox', | ||
'vaadin-combo-box', | ||
'vaadin-context-menu', | ||
'vaadin-date-picker', | ||
'vaadin-dialog', | ||
'vaadin-dropdown-menu', | ||
'vaadin-form-layout', | ||
'vaadin-grid', | ||
'vaadin-horizontal-layout', | ||
'vaadin-icons', | ||
'vaadin-item', | ||
'vaadin-list-box', | ||
'vaadin-notification', | ||
'vaadin-password-field', | ||
'vaadin-progress-bar', | ||
'vaadin-radio-button', | ||
'vaadin-split-layout', | ||
'vaadin-tab', | ||
'vaadin-tabs', | ||
'vaadin-text-area', | ||
'vaadin-text-field', | ||
'vaadin-upload', | ||
'vaadin-vertical-layout' | ||
]; | ||
this._knownVaadinElementNames = names; | ||
var StatisticsGatherer = function () { | ||
function StatisticsGatherer(logger) { | ||
classCallCheck(this, StatisticsGatherer); | ||
this.now = new Date().getTime(); | ||
this.logger = logger; | ||
} | ||
return this._knownVaadinElementNames; | ||
} | ||
getUsedVaadinElementVersion(elementName) { | ||
const klass = customElements.get(elementName); | ||
if (klass) { | ||
return klass.version || "0.0.0"; | ||
} | ||
} | ||
getUsedVaadinElements(elements) { | ||
this.knownVaadinElementNames.forEach(elementName => { | ||
const version = this.getUsedVaadinElementVersion(elementName); | ||
if (version) { | ||
elements[elementName] = {version}; | ||
createClass(StatisticsGatherer, [{ | ||
key: 'frameworkVersionDetectors', | ||
value: function frameworkVersionDetectors() { | ||
return { | ||
'Flow': function Flow() { | ||
if (window.Vaadin && window.Vaadin.Flow && window.Vaadin.Flow.clients) { | ||
var flowVersions = Object.keys(window.Vaadin.Flow.clients).map(function (key) { | ||
return window.Vaadin.Flow.clients[key]; | ||
}).filter(function (client) { | ||
return client.getVersionInfo; | ||
}).map(function (client) { | ||
return client.getVersionInfo().flow; | ||
}); | ||
if (flowVersions.length > 0) { | ||
return flowVersions[0]; | ||
} | ||
} | ||
}, | ||
'Vaadin Framework': function VaadinFramework() { | ||
if (window.vaadin && window.vaadin.clients) { | ||
var frameworkVersions = Object.values(window.vaadin.clients).filter(function (client) { | ||
return client.getVersionInfo; | ||
}).map(function (client) { | ||
return client.getVersionInfo().vaadinVersion; | ||
}); | ||
if (frameworkVersions.length > 0) { | ||
return frameworkVersions[0]; | ||
} | ||
} | ||
}, | ||
'AngularJs': function AngularJs() { | ||
if (window.angular && window.angular.version && window.angular.version) { | ||
return window.angular.version.full; | ||
} | ||
}, | ||
'Angular': function Angular() { | ||
if (window.ng) { | ||
var tags = document.querySelectorAll("[ng-version]"); | ||
if (tags.length > 0) { | ||
return tags[0].getAttribute("ng-version"); | ||
} | ||
return "Unknown"; | ||
} | ||
}, | ||
'Backbone.js': function BackboneJs() { | ||
if (window.Backbone) { | ||
return window.Backbone.VERSION; | ||
} | ||
}, | ||
'React': function React() { | ||
var reactSelector = '[data-reactroot], [data-reactid]'; | ||
if (!!document.querySelector(reactSelector)) { | ||
// React does not publish the version by default | ||
return "unknown"; | ||
} | ||
}, | ||
'Ember': function Ember() { | ||
if (window.Em && window.Em.VERSION) { | ||
return window.Em.VERSION; | ||
} else if (window.Ember && window.Ember.VERSION) { | ||
return window.Ember.VERSION; | ||
} | ||
}, | ||
'jQuery': function (_jQuery) { | ||
function jQuery() { | ||
return _jQuery.apply(this, arguments); | ||
} | ||
jQuery.toString = function () { | ||
return _jQuery.toString(); | ||
}; | ||
return jQuery; | ||
}(function () { | ||
if (typeof jQuery === 'function' && jQuery.prototype.jquery !== undefined) { | ||
return jQuery.prototype.jquery; | ||
} | ||
}), | ||
'Polymer': function Polymer() { | ||
if (window.Polymer && window.Polymer.version) { | ||
return window.Polymer.version; | ||
} | ||
}, | ||
'Vue.js': function VueJs() { | ||
if (window.Vue) { | ||
return window.Vue.version; | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
getUsedVaadinThemes(themes) { | ||
[ | ||
'Lumo' | ||
].forEach(themeName => { | ||
const elementName = `vaadin-${themeName.toLowerCase()}-styles`; | ||
const version = this.getUsedVaadinElementVersion(elementName); | ||
if (version) { | ||
themes[themeName] = {version}; | ||
} | ||
}); | ||
} | ||
getFrameworks(frameworks) { | ||
const detectors = this.frameworkVersionDetectors(); | ||
Object.keys((detectors)).forEach(framework => { | ||
const detector = detectors[framework]; | ||
try { | ||
const version = detector(); | ||
if (version) { | ||
frameworks[framework] = { "version": version }; | ||
}, { | ||
key: 'getUsedVaadinElementVersion', | ||
value: function getUsedVaadinElementVersion(elementName) { | ||
var klass = customElements.get(elementName); | ||
if (klass) { | ||
return klass.version || "0.0.0"; | ||
} | ||
} catch (e) { | ||
} | ||
}); | ||
}; | ||
}, { | ||
key: 'getUsedVaadinElements', | ||
value: function getUsedVaadinElements(elements) { | ||
var _this = this; | ||
gather(storage) { | ||
const storedStats = storage.read(); | ||
var gatheredStats = {}; | ||
const types = ["elements", "frameworks", "themes"]; | ||
this.knownVaadinElementNames.forEach(function (elementName) { | ||
var version = _this.getUsedVaadinElementVersion(elementName); | ||
if (version) { | ||
elements[elementName] = { version: version }; | ||
} | ||
}); | ||
} | ||
}, { | ||
key: 'getUsedVaadinThemes', | ||
value: function getUsedVaadinThemes(themes) { | ||
var _this2 = this; | ||
types.forEach(type => { | ||
gatheredStats[type] = {}; | ||
if (!storedStats[type]) { | ||
storedStats[type] = {}; | ||
['Lumo'].forEach(function (themeName) { | ||
var elementName = 'vaadin-' + themeName.toLowerCase() + '-styles'; | ||
var version = _this2.getUsedVaadinElementVersion(elementName); | ||
if (version) { | ||
themes[themeName] = { version: version }; | ||
} | ||
}); | ||
} | ||
}); | ||
}, { | ||
key: 'getFrameworks', | ||
value: function getFrameworks(frameworks) { | ||
var detectors = this.frameworkVersionDetectors(); | ||
Object.keys(detectors).forEach(function (framework) { | ||
var detector = detectors[framework]; | ||
try { | ||
var version = detector(); | ||
if (version) { | ||
frameworks[framework] = { "version": version }; | ||
} | ||
} catch (e) {} | ||
}); | ||
} | ||
}, { | ||
key: 'gather', | ||
value: function gather(storage) { | ||
var storedStats = storage.read(); | ||
var gatheredStats = {}; | ||
var types = ["elements", "frameworks", "themes"]; | ||
var previousStats = JSON.stringify(storedStats); | ||
types.forEach(function (type) { | ||
gatheredStats[type] = {}; | ||
if (!storedStats[type]) { | ||
storedStats[type] = {}; | ||
} | ||
}); | ||
this.getUsedVaadinElements(gatheredStats.elements); | ||
this.getFrameworks(gatheredStats.frameworks); | ||
this.getUsedVaadinThemes(gatheredStats.themes); | ||
var previousStats = JSON.stringify(storedStats); | ||
const now = this.now; | ||
types.forEach(type => { | ||
const keys = Object.keys(gatheredStats[type]); | ||
keys.forEach(key => { | ||
if (!storedStats[type][key] || typeof storedStats[type][key] != typeof {}) { | ||
storedStats[type][key] = { "firstUsed": now }; | ||
this.getUsedVaadinElements(gatheredStats.elements); | ||
this.getFrameworks(gatheredStats.frameworks); | ||
this.getUsedVaadinThemes(gatheredStats.themes); | ||
var now = this.now; | ||
types.forEach(function (type) { | ||
var keys = Object.keys(gatheredStats[type]); | ||
keys.forEach(function (key) { | ||
if (!storedStats[type][key] || _typeof(storedStats[type][key]) != _typeof({})) { | ||
storedStats[type][key] = { "firstUsed": now }; | ||
} | ||
// Discards any previously logged version numebr | ||
storedStats[type][key].version = gatheredStats[type][key].version; | ||
storedStats[type][key].lastUsed = now; | ||
}); | ||
}); | ||
var newStats = JSON.stringify(storedStats); | ||
storage.write(newStats); | ||
if (newStats != previousStats && Object.keys(storedStats).length > 0) { | ||
this.logger.debug("New stats: " + newStats); | ||
} | ||
// Discards any previously logged version numebr | ||
storedStats[type][key].version = gatheredStats[type][key].version; | ||
storedStats[type][key].lastUsed = now; | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: 'knownVaadinElementNames', | ||
get: function get$1() { | ||
if (!this._knownVaadinElementNames) { | ||
var names = ['vaadin-button', 'vaadin-checkbox', 'vaadin-combo-box', 'vaadin-context-menu', 'vaadin-date-picker', 'vaadin-dialog', 'vaadin-dropdown-menu', 'vaadin-form-layout', 'vaadin-grid', 'vaadin-horizontal-layout', 'vaadin-icons', 'vaadin-item', 'vaadin-list-box', 'vaadin-notification', 'vaadin-password-field', 'vaadin-progress-bar', 'vaadin-radio-button', 'vaadin-split-layout', 'vaadin-tab', 'vaadin-tabs', 'vaadin-text-area', 'vaadin-text-field', 'vaadin-upload', 'vaadin-vertical-layout']; | ||
this._knownVaadinElementNames = names; | ||
} | ||
const newStats = JSON.stringify(storedStats); | ||
storage.write(newStats); | ||
if (newStats != previousStats && Object.keys(storedStats).length > 0) { | ||
this.logger.debug("New stats: " + newStats); | ||
return this._knownVaadinElementNames; | ||
} | ||
}]); | ||
return StatisticsGatherer; | ||
}(); | ||
var StatisticsStorage = function () { | ||
function StatisticsStorage(key) { | ||
classCallCheck(this, StatisticsStorage); | ||
this.key = key; | ||
} | ||
}; | ||
} | ||
class StatisticsStorage { | ||
constructor(key) { | ||
this.key = key; | ||
} | ||
read() { | ||
const localStorageStatsString = localStorage.getItem(this.key); | ||
try { | ||
return JSON.parse(localStorageStatsString ? localStorageStatsString : '{}'); | ||
} catch (e) { | ||
return {}; | ||
} | ||
} | ||
write(data) { | ||
localStorage.setItem(this.key, data); | ||
} | ||
clear() { | ||
localStorage.removeItem(this.key); | ||
} | ||
isEmpty() { | ||
const storedStats = this.read(); | ||
var empty = true; | ||
Object.keys(storedStats).forEach(key => { | ||
if (Object.keys(storedStats[key]).length > 0) { | ||
empty = false; | ||
createClass(StatisticsStorage, [{ | ||
key: 'read', | ||
value: function read() { | ||
var localStorageStatsString = localStorage.getItem(this.key); | ||
try { | ||
return JSON.parse(localStorageStatsString ? localStorageStatsString : '{}'); | ||
} catch (e) { | ||
return {}; | ||
} | ||
} | ||
}); | ||
}, { | ||
key: 'write', | ||
value: function write(data) { | ||
localStorage.setItem(this.key, data); | ||
} | ||
}, { | ||
key: 'clear', | ||
value: function clear() { | ||
localStorage.removeItem(this.key); | ||
} | ||
}, { | ||
key: 'isEmpty', | ||
value: function isEmpty() { | ||
var storedStats = this.read(); | ||
var empty = true; | ||
Object.keys(storedStats).forEach(function (key) { | ||
if (Object.keys(storedStats[key]).length > 0) { | ||
empty = false; | ||
} | ||
}); | ||
return empty; | ||
} | ||
return empty; | ||
} | ||
}]); | ||
return StatisticsStorage; | ||
}(); | ||
var StatisticsSender = function () { | ||
function StatisticsSender(url, logger) { | ||
classCallCheck(this, StatisticsSender); | ||
} | ||
class StatisticsSender { | ||
constructor(url, logger) { | ||
this.url = url; | ||
this.logger = logger; | ||
} | ||
this.url = url; | ||
this.logger = logger; | ||
} | ||
send(data, errorHandler) { | ||
const logger = this.logger; | ||
createClass(StatisticsSender, [{ | ||
key: 'send', | ||
value: function send(data, errorHandler) { | ||
var logger = this.logger; | ||
if (navigator.onLine === false) { | ||
logger.debug("Offline, can't send"); | ||
errorHandler(); | ||
return; | ||
} | ||
logger.debug("Sending data to " + this.url); | ||
if (navigator.onLine === false) { | ||
logger.debug("Offline, can't send"); | ||
errorHandler(); | ||
return; | ||
} | ||
logger.debug("Sending data to " + this.url); | ||
var req = new XMLHttpRequest(); | ||
req.withCredentials = true; | ||
req.addEventListener("load", function () { | ||
// Stats sent, nothing more to do | ||
logger.debug("Response: " + req.responseText); | ||
}); | ||
req.addEventListener("error", function () { | ||
logger.debug("Send failed"); | ||
errorHandler(); | ||
}); | ||
req.addEventListener("abort", function () { | ||
logger.debug("Send aborted"); | ||
errorHandler(); | ||
}); | ||
req.open("POST", this.url); | ||
req.setRequestHeader("Content-Type", "application/json"); | ||
req.send(data); | ||
} | ||
} | ||
class StatisticsLogger { | ||
constructor(id) { | ||
this.id = id; | ||
} | ||
var req = new XMLHttpRequest(); | ||
req.withCredentials = true; | ||
req.addEventListener("load", function () { | ||
// Stats sent, nothing more to do | ||
logger.debug("Response: " + req.responseText); | ||
}); | ||
req.addEventListener("error", function () { | ||
logger.debug("Send failed"); | ||
errorHandler(); | ||
}); | ||
req.addEventListener("abort", function () { | ||
logger.debug("Send aborted"); | ||
errorHandler(); | ||
}); | ||
req.open("POST", this.url); | ||
req.setRequestHeader("Content-Type", "application/json"); | ||
req.send(data); | ||
} | ||
}]); | ||
return StatisticsSender; | ||
}(); | ||
_isDebug() { | ||
return localStorage.getItem("vaadin." + this.id + ".debug"); | ||
} | ||
var StatisticsLogger = function () { | ||
function StatisticsLogger(id) { | ||
classCallCheck(this, StatisticsLogger); | ||
debug(msg) { | ||
if (this._isDebug()) { | ||
console.info(this.id + ": " + msg); | ||
this.id = id; | ||
} | ||
} | ||
} | ||
class UsageStatistics { | ||
constructor() { | ||
this.now = new Date(); | ||
this.timeNow = this.now.getTime(); | ||
this.gatherDelay = 10; // Delay between loading this file and gathering stats | ||
this.initialDelay = 24 * 60 * 60; | ||
createClass(StatisticsLogger, [{ | ||
key: '_isDebug', | ||
value: function _isDebug() { | ||
return localStorage.getItem("vaadin." + this.id + ".debug"); | ||
} | ||
}, { | ||
key: 'debug', | ||
value: function debug(msg) { | ||
if (this._isDebug()) { | ||
console.info(this.id + ": " + msg); | ||
} | ||
} | ||
}]); | ||
return StatisticsLogger; | ||
}(); | ||
this.logger = new StatisticsLogger("statistics"); | ||
this.storage = new StatisticsStorage("vaadin.statistics.basket"); | ||
this.gatherer = new StatisticsGatherer(this.logger); | ||
this.sender = new StatisticsSender("https://tools.vaadin.com/usage-stats/submit", this.logger); | ||
var UsageStatistics = function () { | ||
function UsageStatistics() { | ||
classCallCheck(this, UsageStatistics); | ||
} | ||
static get version() { | ||
return '1.0.6-pre.2'; | ||
} | ||
static get firstUseKey() { | ||
return 'vaadin.statistics.firstuse'; | ||
} | ||
static get monthProcessedKey() { | ||
return 'vaadin.statistics.monthProcessed'; | ||
} | ||
static get optOutKey() { | ||
return 'vaadin.statistics.optout'; | ||
} | ||
this.now = new Date(); | ||
this.timeNow = this.now.getTime(); | ||
this.gatherDelay = 10; // Delay between loading this file and gathering stats | ||
this.initialDelay = 24 * 60 * 60; | ||
maybeGatherAndSend() { | ||
if (localStorage.getItem(UsageStatistics.optOutKey)) { | ||
return; | ||
this.logger = new StatisticsLogger("statistics"); | ||
this.storage = new StatisticsStorage("vaadin.statistics.basket"); | ||
this.gatherer = new StatisticsGatherer(this.logger); | ||
this.sender = new StatisticsSender("https://tools.vaadin.com/usage-stats/submit", this.logger); | ||
} | ||
this.gatherer.gather(this.storage); | ||
setTimeout(() => { | ||
this.maybeSend(); | ||
}, this.gatherDelay * 1000); | ||
} | ||
lottery() { | ||
return Math.random() <= 0.05; | ||
} | ||
createClass(UsageStatistics, [{ | ||
key: 'maybeGatherAndSend', | ||
value: function maybeGatherAndSend() { | ||
var _this3 = this; | ||
currentMonth() { | ||
return this.now.getYear() * 12 + this.now.getMonth(); | ||
} | ||
if (localStorage.getItem(UsageStatistics.optOutKey)) { | ||
return; | ||
} | ||
this.gatherer.gather(this.storage); | ||
setTimeout(function () { | ||
_this3.maybeSend(); | ||
}, this.gatherDelay * 1000); | ||
} | ||
}, { | ||
key: 'lottery', | ||
value: function lottery() { | ||
return Math.random() <= 0.05; | ||
} | ||
}, { | ||
key: 'currentMonth', | ||
value: function currentMonth() { | ||
return this.now.getYear() * 12 + this.now.getMonth(); | ||
} | ||
}, { | ||
key: 'maybeSend', | ||
value: function maybeSend() { | ||
var firstUse = Number(localStorage.getItem(UsageStatistics.firstUseKey)); | ||
var monthProcessed = Number(localStorage.getItem(UsageStatistics.monthProcessedKey)); | ||
maybeSend() { | ||
var firstUse = Number(localStorage.getItem(UsageStatistics.firstUseKey)); | ||
const monthProcessed = Number(localStorage.getItem(UsageStatistics.monthProcessedKey)); | ||
if (!firstUse) { | ||
// Use a grace period to avoid interfering with tests, incognito mode etc | ||
firstUse = this.timeNow; | ||
localStorage.setItem(UsageStatistics.firstUseKey, firstUse); | ||
} | ||
if (!firstUse) { | ||
// Use a grace period to avoid interfering with tests, incognito mode etc | ||
firstUse = this.timeNow; | ||
localStorage.setItem(UsageStatistics.firstUseKey, firstUse); | ||
} | ||
if (this.timeNow < firstUse + this.initialDelay * 1000) { | ||
this.logger.debug("No statistics will be sent until the initial delay of " + this.initialDelay + "s has passed"); | ||
return; | ||
} | ||
if (this.currentMonth() <= monthProcessed) { | ||
this.logger.debug("This month has already been processed"); | ||
return; | ||
} | ||
localStorage.setItem(UsageStatistics.monthProcessedKey, this.currentMonth()); | ||
// Use random sampling | ||
if (this.lottery()) { | ||
this.logger.debug("Congratulations, we have a winner!"); | ||
} else { | ||
this.logger.debug("Sorry, no stats from you this time"); | ||
return; | ||
} | ||
if (this.timeNow < (firstUse + this.initialDelay * 1000)) { | ||
this.logger.debug("No statistics will be sent until the initial delay of " + this.initialDelay + "s has passed"); | ||
return; | ||
} | ||
if (this.currentMonth() <= monthProcessed) { | ||
this.logger.debug("This month has already been processed"); | ||
return; | ||
} | ||
localStorage.setItem(UsageStatistics.monthProcessedKey, this.currentMonth()); | ||
// Use random sampling | ||
if (this.lottery()) { | ||
this.logger.debug("Congratulations, we have a winner!"); | ||
} else { | ||
this.logger.debug("Sorry, no stats from you this time"); | ||
return; | ||
} | ||
this.send(); | ||
} | ||
}, { | ||
key: 'send', | ||
value: function send() { | ||
// Ensure we have the latest data | ||
this.gatherer.gather(this.storage); | ||
this.send(); | ||
} | ||
// Read, send and clean up | ||
var data = this.storage.read(); | ||
data["firstUse"] = Number(localStorage.getItem(UsageStatistics.firstUseKey)); | ||
data["usageStatisticsVersion"] = UsageStatistics.version; | ||
var info = 'This request contains usage statistics gathered from the application running in development mode. \n\nStatistics gathering is automatically disabled and excluded from production builds.\n\nFor details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.\n\n\n\n'; | ||
var self = this; | ||
this.sender.send(info + JSON.stringify(data), function () { | ||
// Revert the 'month processed' flag | ||
localStorage.setItem(UsageStatistics.monthProcessedKey, self.currentMonth() - 1); | ||
}); | ||
} | ||
}], [{ | ||
key: 'version', | ||
get: function get$1() { | ||
return '1.0.6-pre.2'; | ||
} | ||
}, { | ||
key: 'firstUseKey', | ||
get: function get$1() { | ||
return 'vaadin.statistics.firstuse'; | ||
} | ||
}, { | ||
key: 'monthProcessedKey', | ||
get: function get$1() { | ||
return 'vaadin.statistics.monthProcessed'; | ||
} | ||
}, { | ||
key: 'optOutKey', | ||
get: function get$1() { | ||
return 'vaadin.statistics.optout'; | ||
} | ||
}]); | ||
return UsageStatistics; | ||
}(); | ||
send() { | ||
// Ensure we have the latest data | ||
this.gatherer.gather(this.storage); | ||
// Read, send and clean up | ||
var data = this.storage.read(); | ||
data["firstUse"] = Number(localStorage.getItem(UsageStatistics.firstUseKey)); | ||
data["usageStatisticsVersion"] = UsageStatistics.version; | ||
const info = 'This request contains usage statistics gathered from the application running in development mode. \n\nStatistics gathering is automatically disabled and excluded from production builds.\n\nFor details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.\n\n\n\n'; | ||
var self = this; | ||
this.sender.send(info + JSON.stringify(data), function () { | ||
// Revert the 'month processed' flag | ||
localStorage.setItem(UsageStatistics.monthProcessedKey, self.currentMonth() - 1); | ||
}); | ||
} | ||
} | ||
try { | ||
new UsageStatistics().maybeGatherAndSend(); | ||
new UsageStatistics().maybeGatherAndSend(); | ||
} catch (e) { | ||
// Intentionally ignored as this is not a problem in the app being developed | ||
// Intentionally ignored as this is not a problem in the app being developed | ||
} | ||
}()); | ||
vaadin-dev-mode:end **/ | ||
} | ||
return runIfDevelopmentMode(usageStatistics); | ||
} | ||
export { usageStatistics }; | ||
export const usageStatistics = function() { | ||
return runIfDevelopmentMode(maybeGatherAndSendStats); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54641
9
802