This is an automated email from the ASF dual-hosted git repository.

poorejc pushed a commit to branch FLAGON-434
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git


The following commit(s) were added to refs/heads/FLAGON-434 by this push:
     new 4e9ccd4  [FLAGON-434/441] Pushing feature that stores sessionId in 
session storage and retrieves it whenever a page is reloaded
4e9ccd4 is described below

commit 4e9ccd43f2d924b31bb7b8ab7c803eb231147d61
Author: poorejc <[email protected]>
AuthorDate: Sat Aug 10 00:31:15 2019 -0400

    [FLAGON-434/441] Pushing feature that stores sessionId in session storage 
and retrieves it whenever a page is reloaded
---
 build/UserAleWebExtension/background.js |  1 +
 build/UserAleWebExtension/content.js    | 19 ++++++++++++++-
 build/userale-2.0.2.js                  | 19 ++++++++++++++-
 build/userale-2.0.2.min.js              |  2 +-
 example/index.html                      | 12 ++++++++--
 example/index_form.html                 | 22 ++++++++++++-----
 package-lock.json                       | 42 ++++++++++++++++-----------------
 src/getInitialSettings.js               | 19 ++++++++++++++-
 8 files changed, 103 insertions(+), 33 deletions(-)

diff --git a/build/UserAleWebExtension/background.js 
b/build/UserAleWebExtension/background.js
index 62fbada..d39c251 100644
--- a/build/UserAleWebExtension/background.js
+++ b/build/UserAleWebExtension/background.js
@@ -65,6 +65,7 @@ var ADD_LOG = prefix + 'ADD_LOG';
  * limitations under the License.
  */
 
+
 /**
  * Creates a function to normalize the timestamp of the provided event.
  * @param  {Object} e An event containing a timeStamp property.
diff --git a/build/UserAleWebExtension/content.js 
b/build/UserAleWebExtension/content.js
index 9efa490..894e467 100644
--- a/build/UserAleWebExtension/content.js
+++ b/build/UserAleWebExtension/content.js
@@ -93,12 +93,29 @@ function getInitialSettings() {
   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());
+  settings.sessionID = get('data-session') || getSessionId("userAleSessionId", 
'session_' + String(Date.now()));
 
   return settings;
 }
 
 /**
+ * defines sessionId, stores it in sessionStorage, checks to see if there is a 
sessionId in
+ * storage when script is started. This prevents events like 'submit', which 
refresh page data
+ * from refreshing the current user session
+ *
+ */
+function getSessionId(sessionKey, value){
+  if (sessionStorage.getItem(sessionKey) === null) {
+    var storedSession = value;
+    sessionStorage.setItem(sessionKey, value);
+  } else {
+    storedSession = sessionStorage.getItem(sessionKey);
+  }
+  return storedSession;
+}
+
+
+/**
  * 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.
diff --git a/build/userale-2.0.2.js b/build/userale-2.0.2.js
index f0ba930..eaa0d65 100644
--- a/build/userale-2.0.2.js
+++ b/build/userale-2.0.2.js
@@ -64,12 +64,29 @@ var userale = (function (exports) {
     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());
+    settings.sessionID = get('data-session') || 
getSessionId("userAleSessionId", 'session_' + String(Date.now()));
 
     return settings;
   }
 
   /**
+   * defines sessionId, stores it in sessionStorage, checks to see if there is 
a sessionId in
+   * storage when script is started. This prevents events like 'submit', which 
refresh page data
+   * from refreshing the current user session
+   *
+   */
+  function getSessionId(sessionKey, value){
+    if (sessionStorage.getItem(sessionKey) === null) {
+      var storedSession = value;
+      sessionStorage.setItem(sessionKey, value);
+    } else {
+      storedSession = sessionStorage.getItem(sessionKey);
+    }
+    return storedSession;
+  }
+
+
+  /**
    * 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.
diff --git a/build/userale-2.0.2.min.js b/build/userale-2.0.2.min.js
index 0a3b0c8..8fd2c91 100644
--- a/build/userale-2.0.2.min.js
+++ b/build/userale-2.0.2.min.js
@@ -15,4 +15,4 @@
  * limitations under the License.
  * @preserved
  */
-var userale=function(n){"use strict";var a,i,u,l,s,c,d,f,t="2.0.2";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 m=null,p=null;function 
o(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))}}( [...]
\ No newline at end of file
+var userale=function(n){"use strict";var a,i,u,l,s,c,d,f,e="2.0.2";function 
t(n,o){Object.keys(o).forEach(function(e){if("userFromParams"===e){var 
t=function(e){var t=new 
RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)"),n=window.location.href.match(t);return 
n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," 
")):null}(o[e]);t&&(n.userId=t)}n[e]=o[e]})}var m=null,p=null;function 
o(e,t){if(!i.on)return!1;var n=null;t&&(n=t(e));var 
o=function(e){return{milli:Math.floor(e),micro:Number((e%1).toFixed(3))}}( [...]
\ No newline at end of file
diff --git a/example/index.html b/example/index.html
index 2aa7cf7..ddd4a66 100644
--- a/example/index.html
+++ b/example/index.html
@@ -24,11 +24,19 @@ limitations under the License.
     data-version="2.0.2"
     data-tool="Apache UserALE.js Example"
   ></script>
+<!--
+  <script type="text/javascript">
+    const changeMe = "me";
+    window.userale.options({
+      "userId": changeMe
+    })
+  </script>
+-->
 <!--Try out a UserALE.js filter!
     <script type="text/javascript">
     window.userale.filter(function (log) {
-      var type_array = ['mouseup', 'mouseover', 'dblclick', 'blur', 'focus']
-      var logType_array = ['interval']
+      var type_array = ['mouseup', 'mouseover', 'dblclick', 'blur', 'focus'];
+      var logType_array = ['interval'];
       return !type_array.includes(log.type) && 
!logType_array.includes(log.logType);
     });
   </script>
diff --git a/example/index_form.html b/example/index_form.html
index 7095e3d..33f8aa3 100644
--- a/example/index_form.html
+++ b/example/index_form.html
@@ -26,14 +26,24 @@ limitations under the License.
     data-tool="Apache UserALE.js Example"
   ></script>
     <script type="text/javascript">
-    window.userale.filter(function (log) {
-      var type_array = ['mouseup', 'mousedown', 'dblclick', 'blur']
-      var logType_array = ['interval']
-      return !type_array.includes(log.type) && 
!logType_array.includes(log.logType);
-    });
-  </script>
+        window.userale.filter(function (log) {
+            var type_array = ['mouseup', 'mousedown', 'dblclick', 'blur'];
+            var logType_array = ['interval'];
+            return !type_array.includes(log.type) && 
!logType_array.includes(log.logType);
+        });
+    </script>
+
 </head>
 <body>
+
+
+<script type="text/javascript">
+    const changeMe = "me";
+    window.userale.options({
+        "userId": changeMe
+    })
+</script>
+
   <br>
   <br>
   <br>
diff --git a/package-lock.json b/package-lock.json
index 891118e..187b11f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -112,9 +112,9 @@
       "dev": true
     },
     "@types/node": {
-      "version": "12.6.9",
-      "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.9.tgz";,
-      "integrity": 
"sha512-+YB9FtyxXGyD54p8rXwWaN1EWEyar5L58GlGWgtH2I9rGmLGBQcw63+0jw+ujqVavNuO47S1ByAjm9zdHMnskw==",
+      "version": "12.7.1",
+      "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.1.tgz";,
+      "integrity": 
"sha512-aK9jxMypeSrhiYofWWBf/T7O+KwaiAHzM4sveCdWPn71lzUSMimRnKzhXDKfKwV1kWoBo2P1aGgaIYGLf9/ljw==",
       "dev": true
     },
     "abab": {
@@ -1501,9 +1501,9 @@
       }
     },
     "caniuse-lite": {
-      "version": "1.0.30000988",
-      "resolved": 
"https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000988.tgz";,
-      "integrity": 
"sha512-lPj3T8poYrRc/bniW5SQPND3GRtSrQdUM/R4mCYTbZxyi3jQiggLvZH4+BYUuX0t4TXjU+vMM7KFDQg+rSzZUQ==",
+      "version": "1.0.30000989",
+      "resolved": 
"https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz";,
+      "integrity": 
"sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==",
       "dev": true
     },
     "capture-stack-trace": {
@@ -2190,9 +2190,9 @@
       "dev": true
     },
     "electron-to-chromium": {
-      "version": "1.3.214",
-      "resolved": 
"https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.214.tgz";,
-      "integrity": 
"sha512-SU9yyql6uA0Fc8bWR7sCYNGBtxkC+tQb6UaC7ReaadN42Kx7Ka+dzx3lAIm9Ock+ULEawJuTFcVB2x34uOCg0Q==",
+      "version": "1.3.221",
+      "resolved": 
"https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.221.tgz";,
+      "integrity": 
"sha512-YbNA7KgCvLq9ZaEa7wpYP7IP4LrJ4+b36oeF1lYBSJ0zVGVN7uo3Ct9qDUm/M3VDOWj03RVgsMFF8PdL8UjhzA==",
       "dev": true
     },
     "emoji-regex": {
@@ -6335,9 +6335,9 @@
       }
     },
     "rollup": {
-      "version": "1.19.2",
-      "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.19.2.tgz";,
-      "integrity": 
"sha512-nH8Sr5MMhdq+Se4w9RsJiwIFJ7eHNt+UyqR8a1WKlP36+ruJnzRoXMeSXicdRScAyDhrdQQR7GUX6W41qHlp+A==",
+      "version": "1.19.4",
+      "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.19.4.tgz";,
+      "integrity": 
"sha512-G24w409GNj7i/Yam2cQla6qV2k6Nug8bD2DZg9v63QX/cH/dEdbNJg8H4lUm5M1bRpPKRUC465Rm9H51JTKOfQ==",
       "dev": true,
       "requires": {
         "@types/estree": "0.0.39",
@@ -6543,17 +6543,17 @@
       "dev": true
     },
     "sinon": {
-      "version": "7.3.2",
-      "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.3.2.tgz";,
-      "integrity": 
"sha512-thErC1z64BeyGiPvF8aoSg0LEnptSaWE7YhdWWbWXgelOyThent7uKOnnEh9zBxDbKixtr5dEko+ws1sZMuFMA==",
+      "version": "7.4.1",
+      "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.4.1.tgz";,
+      "integrity": 
"sha512-7s9buHGHN/jqoy/v4bJgmt0m1XEkCEd/tqdHXumpBp0JSujaT4Ng84JU5wDdK4E85ZMq78NuDe0I3NAqXY8TFg==",
       "dev": true,
       "requires": {
         "@sinonjs/commons": "^1.4.0",
         "@sinonjs/formatio": "^3.2.1",
-        "@sinonjs/samsam": "^3.3.1",
+        "@sinonjs/samsam": "^3.3.2",
         "diff": "^3.5.0",
-        "lolex": "^4.0.1",
-        "nise": "^1.4.10",
+        "lolex": "^4.2.0",
+        "nise": "^1.5.1",
         "supports-color": "^5.5.0"
       },
       "dependencies": {
@@ -7244,9 +7244,9 @@
       "dev": true
     },
     "type": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/type/-/type-1.0.1.tgz";,
-      "integrity": 
"sha512-MAM5dBMJCJNKs9E7JXo4CXRAansRfG0nlJxW7Wf6GZzSOvH31zClSaHdIMWLehe/EGMBkqeC55rrkaOr5Oo7Nw==",
+      "version": "1.0.3",
+      "resolved": "https://registry.npmjs.org/type/-/type-1.0.3.tgz";,
+      "integrity": 
"sha512-51IMtNfVcee8+9GJvj0spSuFcZHe9vSib6Xtgsny1Km9ugyz2mbS08I3rsUIRYgJohFRFU1160sgRodYz378Hg==",
       "dev": true
     },
     "type-check": {
diff --git a/src/getInitialSettings.js b/src/getInitialSettings.js
index 218fbc4..051cddc 100644
--- a/src/getInitialSettings.js
+++ b/src/getInitialSettings.js
@@ -41,12 +41,29 @@ export function getInitialSettings() {
   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());
+  settings.sessionID = get('data-session') || getSessionId("userAleSessionId", 
'session_' + String(Date.now()));
 
   return settings;
 }
 
 /**
+ * defines sessionId, stores it in sessionStorage, checks to see if there is a 
sessionId in
+ * storage when script is started. This prevents events like 'submit', which 
refresh page data
+ * from refreshing the current user session
+ *
+ */
+export function getSessionId(sessionKey, value){
+  if (sessionStorage.getItem(sessionKey) === null) {
+    var storedSession = value;
+    sessionStorage.setItem(sessionKey, value);
+  } else {
+    storedSession = sessionStorage.getItem(sessionKey);
+  }
+  return storedSession;
+}
+
+
+/**
  * 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.

Reply via email to