You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by po...@apache.org on 2019/06/14 18:50:30 UTC
[incubator-flagon-useralejs] branch master updated: [FLAGON-340]
updates to roll-up, hopefully fixes builds on jenkins
This is an automated email from the ASF dual-hosted git repository.
poorejc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
The following commit(s) were added to refs/heads/master by this push:
new 792c24a [FLAGON-340] updates to roll-up, hopefully fixes builds on jenkins
792c24a is described below
commit 792c24aaa4ab5111a070d7e5d9b1267d90cf8375
Author: poorejc <po...@apache.org>
AuthorDate: Fri Jun 14 14:50:10 2019 -0400
[FLAGON-340] updates to roll-up, hopefully fixes builds on jenkins
---
build/UserAleWebExtension/background.js | 77 +-
build/UserAleWebExtension/content.js | 130 ++-
build/UserAleWebExtension/options.js | 19 +-
build/userale-2.0.0.js | 1441 ++++++++++++++++---------------
build/userale-2.0.0.min.js | 2 +-
gulpfile.js | 27 +-
package-lock.json | 61 +-
package.json | 4 +-
8 files changed, 944 insertions(+), 817 deletions(-)
diff --git a/build/UserAleWebExtension/background.js b/build/UserAleWebExtension/background.js
index 736717b..67bdf06 100644
--- a/build/UserAleWebExtension/background.js
+++ b/build/UserAleWebExtension/background.js
@@ -48,6 +48,23 @@ var prefix = 'USERALE_';
var CONFIG_CHANGE = prefix + 'CONFIG_CHANGE';
var ADD_LOG = prefix + 'ADD_LOG';
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/**
* Creates a function to normalize the timestamp of the provided event.
* @param {Object} e An event containing a timeStamp property.
@@ -71,11 +88,11 @@ function timeStampScale(e) {
var navStart = performance.timing.navigationStart;
tsScaler = function (ts) {
return ts + navStart;
- }
+ };
} else {
tsScaler = function (ts) {
return ts;
- }
+ };
}
} else {
tsScaler = function () { return Date.now(); };
@@ -101,38 +118,6 @@ function timeStampScale(e) {
* limitations under the License.
*/
-var logs$1;
-var config$1;
-
-// Interval Logging Globals
-var intervalID;
-var intervalType;
-var intervalPath;
-var intervalTimer;
-var intervalCounter;
-var intervalLog;
-
-var filterHandler = null;
-var mapHandler = null;
-
-/**
- * Assigns the config and log container to be used by the logging functions.
- * @param {Array} newLogs Log container.
- * @param {Object} newConfig Configuration to use while logging.
- */
-function initPackager(newLogs, newConfig) {
- logs$1 = newLogs;
- config$1 = newConfig;
- filterHandler = null;
- mapHandler = null;
- intervalID = null;
- intervalType = null;
- intervalPath = null;
- intervalTimer = null;
- intervalCounter = 0;
- intervalLog = null;
-}
-
/**
* Extract the millisecond and microsecond portions of a timestamp.
* @param {Number} timeStamp The timestamp to split into millisecond and microsecond fields.
@@ -218,7 +203,7 @@ function sendOnClose(logs, config) {
if (logs.length > 0) {
sendLogs(logs, config.url, 1);
}
- })
+ });
}
}
@@ -248,6 +233,23 @@ function sendLogs(logs, url, retries) {
req.send(data);
}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
// inherent dependency on globals.js, loaded by the webext
// browser is defined in firefox, but not in chrome. In chrome, they use
@@ -291,8 +293,6 @@ function storeCallback(item) {
toolName: item.toolName,
toolVersion: item.toolVersion
});
-
- initPackager(logs, config);
initSender(logs, config);
}
@@ -335,7 +335,6 @@ browser.runtime.onMessage.addListener(function (message) {
toolName: message.payload.toolName,
toolVersion: message.payload.toolVersion
});
- initPackager(logs, updatedConfig);
initSender(logs, updatedConfig);
dispatchTabMessage(message);
})();
@@ -419,4 +418,4 @@ browser.tabs.onZoomChange.addListener(function (e) {
/*
eslint-enable
- */
\ No newline at end of file
+ */
diff --git a/build/UserAleWebExtension/content.js b/build/UserAleWebExtension/content.js
index f1d4f94..2e97929 100644
--- a/build/UserAleWebExtension/content.js
+++ b/build/UserAleWebExtension/content.js
@@ -48,7 +48,7 @@ var prefix = 'USERALE_';
var CONFIG_CHANGE = prefix + 'CONFIG_CHANGE';
var ADD_LOG = prefix + 'ADD_LOG';
-var version$1 = "2.0.0";
+var version = "2.0.0";
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -121,11 +121,11 @@ function timeStampScale(e) {
var navStart = performance.timing.navigationStart;
tsScaler = function (ts) {
return ts + navStart;
- }
+ };
} else {
tsScaler = function (ts) {
return ts;
- }
+ };
}
} else {
tsScaler = function () { return Date.now(); };
@@ -203,8 +203,8 @@ function getUserIdFromParams(param) {
* limitations under the License.
*/
-var logs$1;
-var config$1;
+var logs;
+var config;
// Interval Logging Globals
var intervalID;
@@ -225,14 +225,15 @@ function setLogFilter(callback) {
filterHandler = callback;
}
+
/**
* Assigns the config and log container to be used by the logging functions.
* @param {Array} newLogs Log container.
* @param {Object} newConfig Configuration to use while logging.
*/
function initPackager(newLogs, newConfig) {
- logs$1 = newLogs;
- config$1 = newConfig;
+ logs = newLogs;
+ config = newConfig;
filterHandler = null;
mapHandler = null;
intervalID = null;
@@ -250,7 +251,7 @@ function initPackager(newLogs, newConfig) {
* @return {boolean} Whether the event was logged.
*/
function packageLog(e, detailFcn) {
- if (!config$1.on) {
+ if (!config.on) {
return false;
}
@@ -260,7 +261,7 @@ function packageLog(e, detailFcn) {
}
var timeFields = extractTimeFields(
- (e.timeStamp && e.timeStamp > 0) ? config$1.time(e.timeStamp) : Date.now()
+ (e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now()
);
var log = {
@@ -273,11 +274,11 @@ function packageLog(e, detailFcn) {
'logType': 'raw',
'userAction' : true,
'details' : details,
- 'userId' : config$1.userId,
- 'toolVersion' : config$1.version,
- 'toolName' : config$1.toolName,
- 'useraleVersion': config$1.useraleVersion,
- 'sessionID': config$1.sessionID
+ 'userId' : config.userId,
+ 'toolVersion' : config.version,
+ 'toolName' : config.toolName,
+ 'useraleVersion': config.useraleVersion,
+ 'sessionID': config.sessionID
};
if ((typeof filterHandler === 'function') && !filterHandler(log)) {
@@ -288,7 +289,7 @@ function packageLog(e, detailFcn) {
log = mapHandler(log);
}
- logs$1.push(log);
+ logs.push(log);
return true;
}
@@ -315,7 +316,7 @@ function packageIntervalLog(e) {
var target = getSelector(e.target);
var path = buildPath(e);
var type = e.type;
- var timestamp = Math.floor((e.timeStamp && e.timeStamp > 0) ? config$1.time(e.timeStamp) : Date.now());
+ var timestamp = Math.floor((e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now());
// Init - this should only happen once on initialization
if (intervalID == null) {
@@ -342,11 +343,11 @@ function packageIntervalLog(e) {
'targetChange': intervalID !== target,
'typeChange': intervalType !== type,
'userAction': false,
- 'userId': config$1.userId,
- 'toolVersion': config$1.version,
- 'toolName': config$1.toolName,
- 'useraleVersion': config$1.useraleVersion,
- 'sessionID': config$1.sessionID
+ 'userId': config.userId,
+ 'toolVersion': config.version,
+ 'toolName': config.toolName,
+ 'useraleVersion': config.useraleVersion,
+ 'sessionID': config.sessionID
};
if (typeof filterHandler === 'function' && !filterHandler(intervalLog)) {
@@ -357,7 +358,7 @@ function packageIntervalLog(e) {
intervalLog = mapHandler(intervalLog);
}
- logs$1.push(intervalLog);
+ logs.push(intervalLog);
// Reset
intervalID = target;
@@ -418,7 +419,7 @@ function buildPath(e) {
if (e.path) {
path = e.path;
} else {
- var ele = e.target
+ var ele = e.target;
while(ele) {
path.push(ele);
ele = ele.parentElement;
@@ -444,6 +445,23 @@ function selectorizePath(path) {
return pathSelectors;
}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
var events;
var bufferBools;
var bufferedEvents;
@@ -613,7 +631,7 @@ function sendOnClose(logs, config) {
if (logs.length > 0) {
sendLogs(logs, config.url, 1);
}
- })
+ });
}
}
@@ -643,18 +661,36 @@ function sendLogs(logs, url, retries) {
req.send(data);
}
-var config = {};
-var logs = [];
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var config$1 = {};
+var logs$1 = [];
var started = false;
+
// Start up Userale
-config.on = false;
-config.useraleVersion = version$1;
+config$1.on = false;
+config$1.useraleVersion = version;
-configure(config, getInitialSettings());
-initPackager(logs, config);
+configure(config$1, getInitialSettings());
+initPackager(logs$1, config$1);
-if (config.autostart) {
- setup(config);
+if (config$1.autostart) {
+ setup(config$1);
}
/**
@@ -669,7 +705,7 @@ function setup(config) {
if (state === 'interactive' || state === 'complete') {
attachHandlers(config);
- initSender(logs, config);
+ initSender(logs$1, config);
started = config.on = true;
} else {
setup(config);
@@ -678,17 +714,16 @@ function setup(config) {
}
}
-
/**
* Used to start the logging process if the
* autostart configuration option is set to false.
*/
function start() {
if (!started) {
- setup(config);
+ setup(config$1);
}
- config.on = true;
+ config$1.on = true;
}
/**
@@ -699,12 +734,29 @@ function start() {
*/
function options(newConfig) {
if (newConfig !== undefined) {
- configure(config, newConfig);
+ configure(config$1, newConfig);
}
- return config;
+ return config$1;
}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
// browser is defined in firefox, but not in chrome. In chrome, they use
// the 'chrome' global instead. Let's map it to browser so we don't have
// to have if-conditions all over the place.
@@ -760,4 +812,4 @@ browser.runtime.onMessage.addListener(function (message) {
/*
eslint-enable
- */
\ No newline at end of file
+ */
diff --git a/build/UserAleWebExtension/options.js b/build/UserAleWebExtension/options.js
index 97fa03f..dcf27c9 100644
--- a/build/UserAleWebExtension/options.js
+++ b/build/UserAleWebExtension/options.js
@@ -47,6 +47,23 @@ var prefix = 'USERALE_';
var CONFIG_CHANGE = prefix + 'CONFIG_CHANGE';
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
if (chrome) {
browser = chrome;
}
@@ -87,4 +104,4 @@ document.addEventListener("submit", function() {
saveOptions();
});
-/* eslint-enable */
\ No newline at end of file
+/* eslint-enable */
diff --git a/build/userale-2.0.0.js b/build/userale-2.0.0.js
index 87fdc5b..b69900f 100644
--- a/build/userale-2.0.0.js
+++ b/build/userale-2.0.0.js
@@ -16,705 +16,742 @@
* @preserved
*/
-(function (exports) {
- 'use strict';
-
- var version$1 = "2.0.0";
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /**
- * Extracts the initial configuration settings from the
- * currently executing script tag.
- * @return {Object} The extracted configuration object
- */
- function getInitialSettings() {
- var settings = {};
-
- var script = document.currentScript || (function () {
- var scripts = document.getElementsByTagName('script');
- return scripts[scripts.length - 1];
- })();
-
- var get = script ? script.getAttribute.bind(script) : function() { return null; };
-
- settings.autostart = get('data-autostart') === 'false' ? false : true;
- settings.url = get('data-url') || 'http://localhost:8000';
- settings.transmitInterval = +get('data-interval') || 5000;
- settings.logCountThreshold = +get('data-threshold') || 5;
- settings.userId = get('data-user') || null;
- settings.version = get('data-version') || null;
- settings.logDetails = get('data-log-details') === 'true' ? true : false;
- settings.resolution = +get('data-resolution') || 500;
- settings.toolName = get('data-tool') || null;
- settings.userFromParams = get('data-user-from-params') || null;
- settings.time = timeStampScale(document.createEvent('CustomEvent'));
- settings.sessionID = get('data-session') || 'session_' + String(Date.now());
-
- return settings;
- }
-
- /**
- * Creates a function to normalize the timestamp of the provided event.
- * @param {Object} e An event containing a timeStamp property.
- * @return {timeStampScale~tsScaler} The timestamp normalizing function.
- */
- function timeStampScale(e) {
- if (e.timeStamp && e.timeStamp > 0) {
- var delta = Date.now() - e.timeStamp;
- /**
- * Returns a timestamp depending on various browser quirks.
- * @param {?Number} ts A timestamp to use for normalization.
- * @return {Number} A normalized timestamp.
- */
- var tsScaler;
-
- if (delta < 0) {
- tsScaler = function () {
- return e.timeStamp / 1000;
- };
- } else if (delta > e.timeStamp) {
- var navStart = performance.timing.navigationStart;
- tsScaler = function (ts) {
- return ts + navStart;
- }
- } else {
- tsScaler = function (ts) {
- return ts;
- }
- }
- } else {
- tsScaler = function () { return Date.now(); };
- }
-
- return tsScaler;
- }
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /**
- * Shallow merges the first argument with the second.
- * Retrieves/updates the userid if userFromParams is provided.
- * @param {Object} config Current configuration object to be merged into.
- * @param {Object} newConfig Configuration object to merge into the current config.
- */
- function configure(config, newConfig) {
- Object.keys(newConfig).forEach(function(option) {
- if (option === 'userFromParams') {
- var userId = getUserIdFromParams(newConfig[option]);
- if (userId) {
- config.userId = userId;
- }
- }
- config[option] = newConfig[option];
- });
- }
-
- /**
- * Attempts to extract the userid from the query parameters of the URL.
- * @param {string} param The name of the query parameter containing the userid.
- * @return {string|null} The extracted/decoded userid, or null if none is found.
- */
- function getUserIdFromParams(param) {
- var userField = param;
- var regex = new RegExp('[?&]' + userField + '(=([^&#]*)|&|#|$)');
- var results = window.location.href.match(regex);
-
- if (results && results[2]) {
- return decodeURIComponent(results[2].replace(/\+/g, ' '));
- } else {
- return null;
- }
- }
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- var logs$1;
- var config$1;
-
- // Interval Logging Globals
- var intervalID;
- var intervalType;
- var intervalPath;
- var intervalTimer;
- var intervalCounter;
- var intervalLog;
-
- var filterHandler = null;
- var mapHandler = null;
-
- /**
- * Assigns a handler to filter logs out of the queue.
- * @param {Function} callback The handler to invoke when logging.
- */
- function setLogFilter(callback) {
- filterHandler = callback;
- }
-
- /**
- * Assigns a handler to transform logs from their default structure.
- * @param {Function} callback The handler to invoke when logging.
- */
- function setLogMapper(callback) {
- mapHandler = callback;
- }
-
-
- /**
- * Assigns the config and log container to be used by the logging functions.
- * @param {Array} newLogs Log container.
- * @param {Object} newConfig Configuration to use while logging.
- */
- function initPackager(newLogs, newConfig) {
- logs$1 = newLogs;
- config$1 = newConfig;
- filterHandler = null;
- mapHandler = null;
- intervalID = null;
- intervalType = null;
- intervalPath = null;
- intervalTimer = null;
- intervalCounter = 0;
- intervalLog = null;
- }
-
- /**
- * Transforms the provided event into a log and appends it to the log container.
- * @param {Object} e The event to be logged.
- * @param {Function} detailFcn The function to extract additional log parameters from the event.
- * @return {boolean} Whether the event was logged.
- */
- function packageLog(e, detailFcn) {
- if (!config$1.on) {
- return false;
- }
-
- var details = null;
- if (detailFcn) {
- details = detailFcn(e);
- }
-
- var timeFields = extractTimeFields(
- (e.timeStamp && e.timeStamp > 0) ? config$1.time(e.timeStamp) : Date.now()
- );
-
- var log = {
- 'target' : getSelector(e.target),
- 'path' : buildPath(e),
- 'clientTime' : timeFields.milli,
- 'microTime' : timeFields.micro,
- 'location' : getLocation(e),
- 'type' : e.type,
- 'logType': 'raw',
- 'userAction' : true,
- 'details' : details,
- 'userId' : config$1.userId,
- 'toolVersion' : config$1.version,
- 'toolName' : config$1.toolName,
- 'useraleVersion': config$1.useraleVersion,
- 'sessionID': config$1.sessionID
- };
-
- if ((typeof filterHandler === 'function') && !filterHandler(log)) {
- return false;
- }
-
- if (typeof mapHandler === 'function') {
- log = mapHandler(log);
- }
-
- logs$1.push(log);
-
- return true;
- }
-
- /**
- * Extract the millisecond and microsecond portions of a timestamp.
- * @param {Number} timeStamp The timestamp to split into millisecond and microsecond fields.
- * @return {Object} An object containing the millisecond
- * and microsecond portions of the timestamp.
- */
- function extractTimeFields(timeStamp) {
- return {
- milli: Math.floor(timeStamp),
- micro: Number((timeStamp % 1).toFixed(3)),
- };
- }
-
- /**
- * Track intervals and gather details about it.
- * @param {Object} e
- * @return boolean
- */
- function packageIntervalLog(e) {
- var target = getSelector(e.target);
- var path = buildPath(e);
- var type = e.type;
- var timestamp = Math.floor((e.timeStamp && e.timeStamp > 0) ? config$1.time(e.timeStamp) : Date.now());
-
- // Init - this should only happen once on initialization
- if (intervalID == null) {
- intervalID = target;
- intervalType = type;
- intervalPath = path;
- intervalTimer = timestamp;
- intervalCounter = 0;
- }
-
- if (intervalID !== target || intervalType !== type) {
- // When to create log? On transition end
- // @todo Possible for intervalLog to not be pushed in the event the interval never ends...
-
- intervalLog = {
- 'target': intervalID,
- 'path': intervalPath,
- 'count': intervalCounter,
- 'duration': timestamp - intervalTimer, // microseconds
- 'startTime': intervalTimer,
- 'endTime': timestamp,
- 'type': intervalType,
- 'logType': 'interval',
- 'targetChange': intervalID !== target,
- 'typeChange': intervalType !== type,
- 'userAction': false,
- 'userId': config$1.userId,
- 'toolVersion': config$1.version,
- 'toolName': config$1.toolName,
- 'useraleVersion': config$1.useraleVersion,
- 'sessionID': config$1.sessionID
- };
-
- if (typeof filterHandler === 'function' && !filterHandler(intervalLog)) {
- return false;
- }
-
- if (typeof mapHandler === 'function') {
- intervalLog = mapHandler(intervalLog);
- }
-
- logs$1.push(intervalLog);
-
- // Reset
- intervalID = target;
- intervalType = type;
- intervalPath = path;
- intervalTimer = timestamp;
- intervalCounter = 0;
- }
-
- // Interval is still occuring, just update counter
- if (intervalID == target && intervalType == type) {
- intervalCounter = intervalCounter + 1;
- }
-
- return true;
- }
-
- /**
- * Extracts coordinate information from the event
- * depending on a few browser quirks.
- * @param {Object} e The event to extract coordinate information from.
- * @return {Object} An object containing nullable x and y coordinates for the event.
- */
- function getLocation(e) {
- if (e.pageX != null) {
- return { 'x' : e.pageX, 'y' : e.pageY };
- } else if (e.clientX != null) {
- return { 'x' : document.documentElement.scrollLeft + e.clientX, 'y' : document.documentElement.scrollTop + e.clientY };
- } else {
- return { 'x' : null, 'y' : null };
- }
- }
-
- /**
- * Builds a string CSS selector from the provided element
- * @param {HTMLElement} ele The element from which the selector is built.
- * @return {string} The CSS selector for the element, or Unknown if it can't be determined.
- */
- function getSelector(ele) {
- if (ele.localName) {
- return ele.localName + (ele.id ? ('#' + ele.id) : '') + (ele.className ? ('.' + ele.className) : '');
- } else if (ele.nodeName) {
- return ele.nodeName + (ele.id ? ('#' + ele.id) : '') + (ele.className ? ('.' + ele.className) : '');
- } else if (ele && ele.document && ele.location && ele.alert && ele.setInterval) {
- return "Window";
- } else {
- return "Unknown";
- }
- }
-
- /**
- * Builds an array of elements from the provided event target, to the root element.
- * @param {Object} e Event from which the path should be built.
- * @return {HTMLElement[]} Array of elements, starting at the event target, ending at the root element.
- */
- function buildPath(e) {
- var path = [];
- if (e.path) {
- path = e.path;
- } else {
- var ele = e.target
- while(ele) {
- path.push(ele);
- ele = ele.parentElement;
- }
- }
-
- return selectorizePath(path);
- }
-
- /**
- * Builds a CSS selector path from the provided list of elements.
- * @param {HTMLElement[]} path Array of HTMLElements from which the path should be built.
- * @return {string[]} Array of string CSS selectors.
- */
- function selectorizePath(path) {
- var i = 0;
- var pathEle;
- var pathSelectors = [];
- while (pathEle = path[i]) {
- pathSelectors.push(getSelector(pathEle));
- ++i;
- }
- return pathSelectors;
- }
-
- var events;
- var bufferBools;
- var bufferedEvents;
- //@todo: Investigate drag events and their behavior
- var intervalEvents = ['click', 'focus', 'blur', 'input', 'change', 'mouseover', 'submit'];
- var windowEvents = ['load', 'blur', 'focus'];
-
- /**
- * Maps an event to an object containing useful information.
- * @param {Object} e Event to extract data from
- */
- function extractMouseEvent(e) {
- return {
- 'clicks' : e.detail,
- 'ctrl' : e.ctrlKey,
- 'alt' : e.altKey,
- 'shift' : e.shiftKey,
- 'meta' : e.metaKey
- };
- }
-
- /**
- * Defines the way information is extracted from various events.
- * Also defines which events we will listen to.
- * @param {Object} config Configuration object to read from.
- */
- function defineDetails(config) {
- // Events list
- // Keys are event types
- // Values are functions that return details object if applicable
- events = {
- 'click' : extractMouseEvent,
- 'dblclick' : extractMouseEvent,
- 'mousedown' : extractMouseEvent,
- 'mouseup' : extractMouseEvent,
- 'focus' : null,
- 'blur' : null,
- 'input' : config.logDetails ? function(e) { return { 'value' : e.target.value }; } : null,
- 'change' : config.logDetails ? function(e) { return { 'value' : e.target.value }; } : null,
- 'dragstart' : null,
- 'dragend' : null,
- 'drag' : null,
- 'drop' : null,
- 'keydown' : config.logDetails ? function(e) { return { 'key' : e.keyCode, 'ctrl' : e.ctrlKey, 'alt' : e.altKey, 'shift' : e.shiftKey, 'meta' : e.metaKey }; } : null,
- 'mouseover' : null,
- 'submit' : null
- };
-
- bufferBools = {};
- bufferedEvents = {
- 'wheel' : function(e) { return { 'x' : e.deltaX, 'y' : e.deltaY, 'z' : e.deltaZ }; },
- 'scroll' : function() { return { 'x' : window.scrollX, 'y' : window.scrollY }; },
- 'resize' : function() { return { 'width' : window.outerWidth, 'height' : window.outerHeight }; }
- };
- }
-
- /**
- * Hooks the event handlers for each event type of interest.
- * @param {Object} config Configuration object to use.
- * @return {boolean} Whether the operation succeeded
- */
- function attachHandlers(config) {
- defineDetails(config);
-
- Object.keys(events).forEach(function(ev) {
- document.addEventListener(ev, function(e) {
- packageLog(e, events[ev]);
- }, true);
- });
-
- intervalEvents.forEach(function(ev) {
- document.addEventListener(ev, function(e) {
- packageIntervalLog(e);
- }, true);
- });
-
- Object.keys(bufferedEvents).forEach(function(ev) {
- bufferBools[ev] = true;
-
- window.addEventListener(ev, function(e) {
- if (bufferBools[ev]) {
- bufferBools[ev] = false;
- packageLog(e, bufferedEvents[ev]);
- setTimeout(function() { bufferBools[ev] = true; }, config.resolution);
- }
- }, true);
- });
-
- windowEvents.forEach(function(ev) {
- window.addEventListener(ev, function(e) {
- packageLog(e, function() { return { 'window' : true }; });
- }, true);
- });
-
- return true;
- }
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- var sendIntervalId = null;
-
- /**
- * Initializes the log queue processors.
- * @param {Array} logs Array of logs to append to.
- * @param {Object} config Configuration object to use when logging.
- */
- function initSender(logs, config) {
- if (sendIntervalId !== null) {
- clearInterval(sendIntervalId);
- }
-
- sendIntervalId = sendOnInterval(logs, config);
- sendOnClose(logs, config);
- }
-
- /**
- * Checks the provided log array on an interval, flushing the logs
- * if the queue has reached the threshold specified by the provided config.
- * @param {Array} logs Array of logs to read from.
- * @param {Object} config Configuration object to be read from.
- * @return {Number} The newly created interval id.
- */
- function sendOnInterval(logs, config) {
- return setInterval(function() {
- if (!config.on) {
- return;
- }
-
- if (logs.length >= config.logCountThreshold) {
- sendLogs(logs.slice(0), config.url, 0); // Send a copy
- logs.splice(0); // Clear array reference (no reassignment)
- }
- }, config.transmitInterval);
- }
-
- /**
- * Attempts to flush the remaining logs when the window is closed.
- * @param {Array} logs Array of logs to be flushed.
- * @param {Object} config Configuration object to be read from.
- */
- function sendOnClose(logs, config) {
- if (!config.on) {
- return;
- }
-
- if (navigator.sendBeacon) {
- window.addEventListener('unload', function() {
- navigator.sendBeacon(config.url, JSON.stringify(logs));
- });
- } else {
- window.addEventListener('beforeunload', function() {
- if (logs.length > 0) {
- sendLogs(logs, config.url, 1);
- }
- })
- }
- }
-
- /**
- * Sends the provided array of logs to the specified url,
- * retrying the request up to the specified number of retries.
- * @param {Array} logs Array of logs to send.
- * @param {string} url URL to send the POST request to.
- * @param {Number} retries Maximum number of attempts to send the logs.
- */
- function sendLogs(logs, url, retries) {
- var req = new XMLHttpRequest();
-
- var data = JSON.stringify(logs);
-
- req.open('POST', url);
- req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
-
- req.onreadystatechange = function() {
- if (req.readyState === 4 && req.status !== 200) {
- if (retries > 0) {
- sendLogs(logs, url, retries--);
- }
- }
- };
-
- req.send(data);
- }
-
- var config = {};
- var logs = [];
- exports.started = false;
- // Start up Userale
- config.on = false;
- config.useraleVersion = version$1;
-
- configure(config, getInitialSettings());
- initPackager(logs, config);
-
- if (config.autostart) {
- setup(config);
- }
-
- /**
- * Hooks the global event listener, and starts up the
- * logging interval.
- * @param {Object} config Configuration settings for the logger
- */
- function setup(config) {
- if (!exports.started) {
- setTimeout(function() {
- var state = document.readyState;
-
- if (state === 'interactive' || state === 'complete') {
- attachHandlers(config);
- initSender(logs, config);
- exports.started = config.on = true;
- } else {
- setup(config);
- }
- }, 100);
- }
- }
-
-
- // Export the Userale API
- var version = version$1;
-
- /**
- * Used to start the logging process if the
- * autostart configuration option is set to false.
- */
- function start() {
- if (!exports.started) {
- setup(config);
- }
-
- config.on = true;
- }
-
- /**
- * Halts the logging process. Logs will no longer be sent.
- */
- function stop() {
- config.on = false;
- }
-
- /**
- * Updates the current configuration
- * object with the provided values.
- * @param {Object} newConfig The configuration options to use.
- * @return {Object} Returns the updated configuration.
- */
- function options(newConfig) {
- if (newConfig !== undefined) {
- configure(config, newConfig);
- }
-
- return config;
- }
-
- /**
- * Appends a log to the log queue.
- * @param {Object} customLog The log to append.
- * @return {boolean} Whether the operation succeeded.
- */
- function log(customLog) {
- if (customLog !== null && typeof customLog === 'object') {
- logs.push(customLog);
- return true;
- } else {
- return false;
- }
- }
-
- exports.version = version;
- exports.start = start;
- exports.stop = stop;
- exports.options = options;
- exports.log = log;
- exports.map = setLogMapper;
- exports.filter = setLogFilter;
-
-}((this.userale = this.userale || {})));
\ No newline at end of file
+var userale = (function (exports) {
+ 'use strict';
+
+ var version = "2.0.0";
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /**
+ * Extracts the initial configuration settings from the
+ * currently executing script tag.
+ * @return {Object} The extracted configuration object
+ */
+ function getInitialSettings() {
+ var settings = {};
+
+ var script = document.currentScript || (function () {
+ var scripts = document.getElementsByTagName('script');
+ return scripts[scripts.length - 1];
+ })();
+
+ var get = script ? script.getAttribute.bind(script) : function() { return null; };
+
+ settings.autostart = get('data-autostart') === 'false' ? false : true;
+ settings.url = get('data-url') || 'http://localhost:8000';
+ settings.transmitInterval = +get('data-interval') || 5000;
+ settings.logCountThreshold = +get('data-threshold') || 5;
+ settings.userId = get('data-user') || null;
+ settings.version = get('data-version') || null;
+ settings.logDetails = get('data-log-details') === 'true' ? true : false;
+ settings.resolution = +get('data-resolution') || 500;
+ settings.toolName = get('data-tool') || null;
+ settings.userFromParams = get('data-user-from-params') || null;
+ settings.time = timeStampScale(document.createEvent('CustomEvent'));
+ settings.sessionID = get('data-session') || 'session_' + String(Date.now());
+
+ return settings;
+ }
+
+ /**
+ * Creates a function to normalize the timestamp of the provided event.
+ * @param {Object} e An event containing a timeStamp property.
+ * @return {timeStampScale~tsScaler} The timestamp normalizing function.
+ */
+ function timeStampScale(e) {
+ if (e.timeStamp && e.timeStamp > 0) {
+ var delta = Date.now() - e.timeStamp;
+ /**
+ * Returns a timestamp depending on various browser quirks.
+ * @param {?Number} ts A timestamp to use for normalization.
+ * @return {Number} A normalized timestamp.
+ */
+ var tsScaler;
+
+ if (delta < 0) {
+ tsScaler = function () {
+ return e.timeStamp / 1000;
+ };
+ } else if (delta > e.timeStamp) {
+ var navStart = performance.timing.navigationStart;
+ tsScaler = function (ts) {
+ return ts + navStart;
+ };
+ } else {
+ tsScaler = function (ts) {
+ return ts;
+ };
+ }
+ } else {
+ tsScaler = function () { return Date.now(); };
+ }
+
+ return tsScaler;
+ }
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /**
+ * Shallow merges the first argument with the second.
+ * Retrieves/updates the userid if userFromParams is provided.
+ * @param {Object} config Current configuration object to be merged into.
+ * @param {Object} newConfig Configuration object to merge into the current config.
+ */
+ function configure(config, newConfig) {
+ Object.keys(newConfig).forEach(function(option) {
+ if (option === 'userFromParams') {
+ var userId = getUserIdFromParams(newConfig[option]);
+ if (userId) {
+ config.userId = userId;
+ }
+ }
+ config[option] = newConfig[option];
+ });
+ }
+
+ /**
+ * Attempts to extract the userid from the query parameters of the URL.
+ * @param {string} param The name of the query parameter containing the userid.
+ * @return {string|null} The extracted/decoded userid, or null if none is found.
+ */
+ function getUserIdFromParams(param) {
+ var userField = param;
+ var regex = new RegExp('[?&]' + userField + '(=([^&#]*)|&|#|$)');
+ var results = window.location.href.match(regex);
+
+ if (results && results[2]) {
+ return decodeURIComponent(results[2].replace(/\+/g, ' '));
+ } else {
+ return null;
+ }
+ }
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ var logs;
+ var config;
+
+ // Interval Logging Globals
+ var intervalID;
+ var intervalType;
+ var intervalPath;
+ var intervalTimer;
+ var intervalCounter;
+ var intervalLog;
+
+ var filterHandler = null;
+ var mapHandler = null;
+
+ /**
+ * Assigns a handler to filter logs out of the queue.
+ * @param {Function} callback The handler to invoke when logging.
+ */
+ function setLogFilter(callback) {
+ filterHandler = callback;
+ }
+
+ /**
+ * Assigns a handler to transform logs from their default structure.
+ * @param {Function} callback The handler to invoke when logging.
+ */
+ function setLogMapper(callback) {
+ mapHandler = callback;
+ }
+
+
+ /**
+ * Assigns the config and log container to be used by the logging functions.
+ * @param {Array} newLogs Log container.
+ * @param {Object} newConfig Configuration to use while logging.
+ */
+ function initPackager(newLogs, newConfig) {
+ logs = newLogs;
+ config = newConfig;
+ filterHandler = null;
+ mapHandler = null;
+ intervalID = null;
+ intervalType = null;
+ intervalPath = null;
+ intervalTimer = null;
+ intervalCounter = 0;
+ intervalLog = null;
+ }
+
+ /**
+ * Transforms the provided event into a log and appends it to the log container.
+ * @param {Object} e The event to be logged.
+ * @param {Function} detailFcn The function to extract additional log parameters from the event.
+ * @return {boolean} Whether the event was logged.
+ */
+ function packageLog(e, detailFcn) {
+ if (!config.on) {
+ return false;
+ }
+
+ var details = null;
+ if (detailFcn) {
+ details = detailFcn(e);
+ }
+
+ var timeFields = extractTimeFields(
+ (e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now()
+ );
+
+ var log = {
+ 'target' : getSelector(e.target),
+ 'path' : buildPath(e),
+ 'clientTime' : timeFields.milli,
+ 'microTime' : timeFields.micro,
+ 'location' : getLocation(e),
+ 'type' : e.type,
+ 'logType': 'raw',
+ 'userAction' : true,
+ 'details' : details,
+ 'userId' : config.userId,
+ 'toolVersion' : config.version,
+ 'toolName' : config.toolName,
+ 'useraleVersion': config.useraleVersion,
+ 'sessionID': config.sessionID
+ };
+
+ if ((typeof filterHandler === 'function') && !filterHandler(log)) {
+ return false;
+ }
+
+ if (typeof mapHandler === 'function') {
+ log = mapHandler(log);
+ }
+
+ logs.push(log);
+
+ return true;
+ }
+
+ /**
+ * Extract the millisecond and microsecond portions of a timestamp.
+ * @param {Number} timeStamp The timestamp to split into millisecond and microsecond fields.
+ * @return {Object} An object containing the millisecond
+ * and microsecond portions of the timestamp.
+ */
+ function extractTimeFields(timeStamp) {
+ return {
+ milli: Math.floor(timeStamp),
+ micro: Number((timeStamp % 1).toFixed(3)),
+ };
+ }
+
+ /**
+ * Track intervals and gather details about it.
+ * @param {Object} e
+ * @return boolean
+ */
+ function packageIntervalLog(e) {
+ var target = getSelector(e.target);
+ var path = buildPath(e);
+ var type = e.type;
+ var timestamp = Math.floor((e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now());
+
+ // Init - this should only happen once on initialization
+ if (intervalID == null) {
+ intervalID = target;
+ intervalType = type;
+ intervalPath = path;
+ intervalTimer = timestamp;
+ intervalCounter = 0;
+ }
+
+ if (intervalID !== target || intervalType !== type) {
+ // When to create log? On transition end
+ // @todo Possible for intervalLog to not be pushed in the event the interval never ends...
+
+ intervalLog = {
+ 'target': intervalID,
+ 'path': intervalPath,
+ 'count': intervalCounter,
+ 'duration': timestamp - intervalTimer, // microseconds
+ 'startTime': intervalTimer,
+ 'endTime': timestamp,
+ 'type': intervalType,
+ 'logType': 'interval',
+ 'targetChange': intervalID !== target,
+ 'typeChange': intervalType !== type,
+ 'userAction': false,
+ 'userId': config.userId,
+ 'toolVersion': config.version,
+ 'toolName': config.toolName,
+ 'useraleVersion': config.useraleVersion,
+ 'sessionID': config.sessionID
+ };
+
+ if (typeof filterHandler === 'function' && !filterHandler(intervalLog)) {
+ return false;
+ }
+
+ if (typeof mapHandler === 'function') {
+ intervalLog = mapHandler(intervalLog);
+ }
+
+ logs.push(intervalLog);
+
+ // Reset
+ intervalID = target;
+ intervalType = type;
+ intervalPath = path;
+ intervalTimer = timestamp;
+ intervalCounter = 0;
+ }
+
+ // Interval is still occuring, just update counter
+ if (intervalID == target && intervalType == type) {
+ intervalCounter = intervalCounter + 1;
+ }
+
+ return true;
+ }
+
+ /**
+ * Extracts coordinate information from the event
+ * depending on a few browser quirks.
+ * @param {Object} e The event to extract coordinate information from.
+ * @return {Object} An object containing nullable x and y coordinates for the event.
+ */
+ function getLocation(e) {
+ if (e.pageX != null) {
+ return { 'x' : e.pageX, 'y' : e.pageY };
+ } else if (e.clientX != null) {
+ return { 'x' : document.documentElement.scrollLeft + e.clientX, 'y' : document.documentElement.scrollTop + e.clientY };
+ } else {
+ return { 'x' : null, 'y' : null };
+ }
+ }
+
+ /**
+ * Builds a string CSS selector from the provided element
+ * @param {HTMLElement} ele The element from which the selector is built.
+ * @return {string} The CSS selector for the element, or Unknown if it can't be determined.
+ */
+ function getSelector(ele) {
+ if (ele.localName) {
+ return ele.localName + (ele.id ? ('#' + ele.id) : '') + (ele.className ? ('.' + ele.className) : '');
+ } else if (ele.nodeName) {
+ return ele.nodeName + (ele.id ? ('#' + ele.id) : '') + (ele.className ? ('.' + ele.className) : '');
+ } else if (ele && ele.document && ele.location && ele.alert && ele.setInterval) {
+ return "Window";
+ } else {
+ return "Unknown";
+ }
+ }
+
+ /**
+ * Builds an array of elements from the provided event target, to the root element.
+ * @param {Object} e Event from which the path should be built.
+ * @return {HTMLElement[]} Array of elements, starting at the event target, ending at the root element.
+ */
+ function buildPath(e) {
+ var path = [];
+ if (e.path) {
+ path = e.path;
+ } else {
+ var ele = e.target;
+ while(ele) {
+ path.push(ele);
+ ele = ele.parentElement;
+ }
+ }
+
+ return selectorizePath(path);
+ }
+
+ /**
+ * Builds a CSS selector path from the provided list of elements.
+ * @param {HTMLElement[]} path Array of HTMLElements from which the path should be built.
+ * @return {string[]} Array of string CSS selectors.
+ */
+ function selectorizePath(path) {
+ var i = 0;
+ var pathEle;
+ var pathSelectors = [];
+ while (pathEle = path[i]) {
+ pathSelectors.push(getSelector(pathEle));
+ ++i;
+ }
+ return pathSelectors;
+ }
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ var events;
+ var bufferBools;
+ var bufferedEvents;
+ //@todo: Investigate drag events and their behavior
+ var intervalEvents = ['click', 'focus', 'blur', 'input', 'change', 'mouseover', 'submit'];
+ var windowEvents = ['load', 'blur', 'focus'];
+
+ /**
+ * Maps an event to an object containing useful information.
+ * @param {Object} e Event to extract data from
+ */
+ function extractMouseEvent(e) {
+ return {
+ 'clicks' : e.detail,
+ 'ctrl' : e.ctrlKey,
+ 'alt' : e.altKey,
+ 'shift' : e.shiftKey,
+ 'meta' : e.metaKey
+ };
+ }
+
+ /**
+ * Defines the way information is extracted from various events.
+ * Also defines which events we will listen to.
+ * @param {Object} config Configuration object to read from.
+ */
+ function defineDetails(config) {
+ // Events list
+ // Keys are event types
+ // Values are functions that return details object if applicable
+ events = {
+ 'click' : extractMouseEvent,
+ 'dblclick' : extractMouseEvent,
+ 'mousedown' : extractMouseEvent,
+ 'mouseup' : extractMouseEvent,
+ 'focus' : null,
+ 'blur' : null,
+ 'input' : config.logDetails ? function(e) { return { 'value' : e.target.value }; } : null,
+ 'change' : config.logDetails ? function(e) { return { 'value' : e.target.value }; } : null,
+ 'dragstart' : null,
+ 'dragend' : null,
+ 'drag' : null,
+ 'drop' : null,
+ 'keydown' : config.logDetails ? function(e) { return { 'key' : e.keyCode, 'ctrl' : e.ctrlKey, 'alt' : e.altKey, 'shift' : e.shiftKey, 'meta' : e.metaKey }; } : null,
+ 'mouseover' : null,
+ 'submit' : null
+ };
+
+ bufferBools = {};
+ bufferedEvents = {
+ 'wheel' : function(e) { return { 'x' : e.deltaX, 'y' : e.deltaY, 'z' : e.deltaZ }; },
+ 'scroll' : function() { return { 'x' : window.scrollX, 'y' : window.scrollY }; },
+ 'resize' : function() { return { 'width' : window.outerWidth, 'height' : window.outerHeight }; }
+ };
+ }
+
+ /**
+ * Hooks the event handlers for each event type of interest.
+ * @param {Object} config Configuration object to use.
+ * @return {boolean} Whether the operation succeeded
+ */
+ function attachHandlers(config) {
+ defineDetails(config);
+
+ Object.keys(events).forEach(function(ev) {
+ document.addEventListener(ev, function(e) {
+ packageLog(e, events[ev]);
+ }, true);
+ });
+
+ intervalEvents.forEach(function(ev) {
+ document.addEventListener(ev, function(e) {
+ packageIntervalLog(e);
+ }, true);
+ });
+
+ Object.keys(bufferedEvents).forEach(function(ev) {
+ bufferBools[ev] = true;
+
+ window.addEventListener(ev, function(e) {
+ if (bufferBools[ev]) {
+ bufferBools[ev] = false;
+ packageLog(e, bufferedEvents[ev]);
+ setTimeout(function() { bufferBools[ev] = true; }, config.resolution);
+ }
+ }, true);
+ });
+
+ windowEvents.forEach(function(ev) {
+ window.addEventListener(ev, function(e) {
+ packageLog(e, function() { return { 'window' : true }; });
+ }, true);
+ });
+
+ return true;
+ }
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ var sendIntervalId = null;
+
+ /**
+ * Initializes the log queue processors.
+ * @param {Array} logs Array of logs to append to.
+ * @param {Object} config Configuration object to use when logging.
+ */
+ function initSender(logs, config) {
+ if (sendIntervalId !== null) {
+ clearInterval(sendIntervalId);
+ }
+
+ sendIntervalId = sendOnInterval(logs, config);
+ sendOnClose(logs, config);
+ }
+
+ /**
+ * Checks the provided log array on an interval, flushing the logs
+ * if the queue has reached the threshold specified by the provided config.
+ * @param {Array} logs Array of logs to read from.
+ * @param {Object} config Configuration object to be read from.
+ * @return {Number} The newly created interval id.
+ */
+ function sendOnInterval(logs, config) {
+ return setInterval(function() {
+ if (!config.on) {
+ return;
+ }
+
+ if (logs.length >= config.logCountThreshold) {
+ sendLogs(logs.slice(0), config.url, 0); // Send a copy
+ logs.splice(0); // Clear array reference (no reassignment)
+ }
+ }, config.transmitInterval);
+ }
+
+ /**
+ * Attempts to flush the remaining logs when the window is closed.
+ * @param {Array} logs Array of logs to be flushed.
+ * @param {Object} config Configuration object to be read from.
+ */
+ function sendOnClose(logs, config) {
+ if (!config.on) {
+ return;
+ }
+
+ if (navigator.sendBeacon) {
+ window.addEventListener('unload', function() {
+ navigator.sendBeacon(config.url, JSON.stringify(logs));
+ });
+ } else {
+ window.addEventListener('beforeunload', function() {
+ if (logs.length > 0) {
+ sendLogs(logs, config.url, 1);
+ }
+ });
+ }
+ }
+
+ /**
+ * Sends the provided array of logs to the specified url,
+ * retrying the request up to the specified number of retries.
+ * @param {Array} logs Array of logs to send.
+ * @param {string} url URL to send the POST request to.
+ * @param {Number} retries Maximum number of attempts to send the logs.
+ */
+ function sendLogs(logs, url, retries) {
+ var req = new XMLHttpRequest();
+
+ var data = JSON.stringify(logs);
+
+ req.open('POST', url);
+ req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
+
+ req.onreadystatechange = function() {
+ if (req.readyState === 4 && req.status !== 200) {
+ if (retries > 0) {
+ sendLogs(logs, url, retries--);
+ }
+ }
+ };
+
+ req.send(data);
+ }
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ var config$1 = {};
+ var logs$1 = [];
+ exports.started = false;
+
+ // Start up Userale
+ config$1.on = false;
+ config$1.useraleVersion = version;
+
+ configure(config$1, getInitialSettings());
+ initPackager(logs$1, config$1);
+
+ if (config$1.autostart) {
+ setup(config$1);
+ }
+
+ /**
+ * Hooks the global event listener, and starts up the
+ * logging interval.
+ * @param {Object} config Configuration settings for the logger
+ */
+ function setup(config) {
+ if (!exports.started) {
+ setTimeout(function() {
+ var state = document.readyState;
+
+ if (state === 'interactive' || state === 'complete') {
+ attachHandlers(config);
+ initSender(logs$1, config);
+ exports.started = config.on = true;
+ } else {
+ setup(config);
+ }
+ }, 100);
+ }
+ }
+
+
+ // Export the Userale API
+ var version$1 = version;
+
+ /**
+ * Used to start the logging process if the
+ * autostart configuration option is set to false.
+ */
+ function start() {
+ if (!exports.started) {
+ setup(config$1);
+ }
+
+ config$1.on = true;
+ }
+
+ /**
+ * Halts the logging process. Logs will no longer be sent.
+ */
+ function stop() {
+ config$1.on = false;
+ }
+
+ /**
+ * Updates the current configuration
+ * object with the provided values.
+ * @param {Object} newConfig The configuration options to use.
+ * @return {Object} Returns the updated configuration.
+ */
+ function options(newConfig) {
+ if (newConfig !== undefined) {
+ configure(config$1, newConfig);
+ }
+
+ return config$1;
+ }
+
+ /**
+ * Appends a log to the log queue.
+ * @param {Object} customLog The log to append.
+ * @return {boolean} Whether the operation succeeded.
+ */
+ function log(customLog) {
+ if (customLog !== null && typeof customLog === 'object') {
+ logs$1.push(customLog);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ exports.filter = setLogFilter;
+ exports.log = log;
+ exports.map = setLogMapper;
+ exports.options = options;
+ exports.start = start;
+ exports.stop = stop;
+ exports.version = version$1;
+
+ return exports;
+
+}({}));
diff --git a/build/userale-2.0.0.min.js b/build/userale-2.0.0.min.js
index 9555609..caed367 100644
--- a/build/userale-2.0.0.min.js
+++ b/build/userale-2.0.0.min.js
@@ -15,4 +15,4 @@
* limitations under the License.
* @preserved
*/
-!function(n){"use strict";var a,i,u,l,s,c,d,f,t="2.0.0";function e(n,o){Object.keys(o).forEach(function(t){if("userFromParams"===t){var e=function(t){var e=new RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)"),n=window.location.href.match(e);return n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):null}(o[t]);e&&(n.userId=e)}n[t]=o[t]})}var o,r,m,p=null,v=null;function h(t,e){if(!i.on)return!1;var n=null;e&&(n=e(t));var o=function(t){return{milli:Math.floor(t),micro:Number((t%1).toFixed(3))}}(t.tim [...]
\ No newline at end of file
+var userale=function(n){"use strict";var a,i,u,l,s,c,d,f,t="2.0.0";function e(n,o){Object.keys(o).forEach(function(t){if("userFromParams"===t){var e=function(t){var e=new RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)"),n=window.location.href.match(e);return n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):null}(o[t]);e&&(n.userId=e)}n[t]=o[t]})}var o,r,m,p=null,v=null;function g(t,e){if(!i.on)return!1;var n=null;e&&(n=e(t));var o=function(t){return{milli:Math.floor(t),micro:Number((t%1).toFixed( [...]
\ No newline at end of file
diff --git a/gulpfile.js b/gulpfile.js
index 4d772cb..42b7753 100755
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -43,7 +43,7 @@ gulp.task('clean', function() {
// Build the module with Rollup
gulp.task('rollup', function() {
return rollup({
- entry : 'src/main.js',
+ input : 'src/main.js',
plugins : [
license({
banner: 'Licensed to the Apache Software Foundation (ASF) under one or more\n' +
@@ -67,9 +67,9 @@ gulp.task('rollup', function() {
})
.then(function(bundle) {
return bundle.write({
+ file : 'build/' + userale + '.js',
format : 'iife',
- moduleName : 'userale',
- dest : 'build/' + userale + '.js'
+ name: 'userale'
});
});
});
@@ -78,15 +78,16 @@ gulp.task('rollup', function() {
// Build the module with Rollup
gulp.task('rollup-web-ext-content', function() {
return rollup({
- entry : 'src/' + userAleWebExtDirName + '/content.js',
+ input : 'src/' + userAleWebExtDirName + '/content.js',
plugins : [
json()
]
})
.then(function(bundle) {
return bundle.write({
- moduleName : 'user-ale-ext-content',
- dest : 'build/' + userAleWebExtDirName + '/content.js'
+ file : 'build/' + userAleWebExtDirName + '/content.js',
+ name : 'user-ale-ext-content',
+ format : 'esm'
});
});
});
@@ -94,15 +95,16 @@ gulp.task('rollup-web-ext-content', function() {
// Build the module with Rollup
gulp.task('rollup-web-ext-background', function() {
return rollup({
- entry : 'src/' + userAleWebExtDirName + '/background.js',
+ input : 'src/' + userAleWebExtDirName + '/background.js',
plugins : [
json()
]
})
.then(function(bundle) {
return bundle.write({
- moduleName : 'user-ale-ext-background',
- dest : 'build/' + userAleWebExtDirName + '/background.js'
+ file : 'build/' + userAleWebExtDirName + '/background.js',
+ name : 'user-ale-ext-background',
+ format : 'esm'
});
});
});
@@ -110,15 +112,16 @@ gulp.task('rollup-web-ext-background', function() {
// Build the module with Rollup
gulp.task('rollup-web-ext-options', function() {
return rollup({
- entry : 'src/' + userAleWebExtDirName + '/options.js',
+ input : 'src/' + userAleWebExtDirName + '/options.js',
plugins : [
json()
]
})
.then(function(bundle) {
return bundle.write({
- moduleName : 'user-ale-ext-options',
- dest : 'build/' + userAleWebExtDirName + '/options.js'
+ file : 'build/' + userAleWebExtDirName + '/options.js',
+ name : 'user-ale-ext-options',
+ format : "esm"
});
});
});
diff --git a/package-lock.json b/package-lock.json
index 31243e2..0fceb5f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4,6 +4,18 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@types/estree": {
+ "version": "0.0.39",
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
+ "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==",
+ "dev": true
+ },
+ "@types/node": {
+ "version": "12.0.8",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.8.tgz",
+ "integrity": "sha512-b8bbUOTwzIY3V5vDTY1fIJ+ePKDUBqt2hC2woVGotdQQhG/2Sh62HOKHrT7ab+VerXAcPyAiTEipPu/FsreUtg==",
+ "dev": true
+ },
"abab": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz",
@@ -1820,12 +1832,13 @@
}
},
"d": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz",
- "integrity": "sha1-dUu1v+VUUdpppYuU1F9MWwRi1Y8=",
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz",
+ "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==",
"dev": true,
"requires": {
- "es5-ext": "^0.10.9"
+ "es5-ext": "^0.10.50",
+ "type": "^1.0.1"
}
},
"dargs": {
@@ -2134,9 +2147,9 @@
"dev": true
},
"electron-to-chromium": {
- "version": "1.3.158",
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.158.tgz",
- "integrity": "sha512-wJsJaWsViNQ129XPGmyO5gGs1jPMHr9vffjHAhUje1xZbEzQcqbENdvfyRD9q8UF0TgFQFCCUbaIpJarFbvsIg==",
+ "version": "1.3.159",
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.159.tgz",
+ "integrity": "sha512-bhiEr8/A97GUBcUzNb9MFNhzQOjakbKmEKBEAa6UMY45zG2e8PM63LOgAPXEJE9bQiaQH6nOdYiYf8X821tZjQ==",
"dev": true
},
"encodeurl": {
@@ -6413,31 +6426,31 @@
}
},
"rollup": {
- "version": "0.26.7",
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.26.7.tgz",
- "integrity": "sha1-EodbyDoO6N3PSzvPMPK3fWBlLdc=",
+ "version": "1.15.5",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.15.5.tgz",
+ "integrity": "sha512-Dix1YCY6BlsVK20SjQHBjKqxW2K+lqNr6BlCKxtdZuYqmUWLm8NzKHdrJyiFFjUO2hSI4wiC7apE+jAkDA3fEQ==",
"dev": true,
"requires": {
- "chalk": "^1.1.1",
- "minimist": "^1.2.0",
- "source-map-support": "^0.4.0"
+ "@types/estree": "0.0.39",
+ "@types/node": "^12.0.8",
+ "acorn": "^6.1.1"
},
"dependencies": {
- "minimist": {
- "version": "1.2.0",
- "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
- "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
+ "acorn": {
+ "version": "6.1.1",
+ "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz",
+ "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==",
"dev": true
}
}
},
"rollup-plugin-json": {
- "version": "2.3.1",
- "resolved": "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-2.3.1.tgz",
- "integrity": "sha512-alQQQVPo2z9pl6LSK8QqyDlWwCH5KeE8YxgQv7fa/SeTxz+gQe36jBjcha7hQW68MrVh9Ms71EQaMZDAG3w2yw==",
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-3.1.0.tgz",
+ "integrity": "sha512-BlYk5VspvGpjz7lAwArVzBXR60JK+4EKtPkCHouAWg39obk9S61hZYJDBfMK+oitPdoe11i69TlxKlMQNFC/Uw==",
"dev": true,
"requires": {
- "rollup-pluginutils": "^2.0.1"
+ "rollup-pluginutils": "^2.3.1"
}
},
"rollup-plugin-license": {
@@ -7277,6 +7290,12 @@
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"dev": true
},
+ "type": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/type/-/type-1.0.1.tgz",
+ "integrity": "sha512-MAM5dBMJCJNKs9E7JXo4CXRAansRfG0nlJxW7Wf6GZzSOvH31zClSaHdIMWLehe/EGMBkqeC55rrkaOr5Oo7Nw==",
+ "dev": true
+ },
"type-check": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
diff --git a/package.json b/package.json
index 4cffa9f..cc84606 100755
--- a/package.json
+++ b/package.json
@@ -54,8 +54,8 @@
"gulp-uglify": "^3.0.1",
"jsdom": "^8.4.0",
"nodemon": "^1.9.2",
- "rollup": "^0.26.0",
- "rollup-plugin-json": "^2.0.1",
+ "rollup": "^1.3.2",
+ "rollup-plugin-json": "^3.1.0",
"sinon": "^1.17.6",
"rollup-plugin-license": "^0.9.0",
"uglify-es": "^3.3.9",