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

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/master by this push:
     new 0865e81  [OPENMEETINGS-2472] js improvements
0865e81 is described below

commit 0865e81e1a7bb24e107e883a7885d5b80a25d384
Author: Maxim Solodovnik <solomax...@gmail.com>
AuthorDate: Sun Oct 4 11:30:38 2020 +0700

    [OPENMEETINGS-2472] js improvements
---
 .../apache/openmeetings/web/pages/BasePage.java    |  4 ++--
 .../org/apache/openmeetings/web/pages/om-ga.js     | 22 ++++++++--------------
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/BasePage.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/BasePage.java
index dbb1010..0c993f0 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/BasePage.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/BasePage.java
@@ -140,8 +140,8 @@ public abstract class BasePage extends 
AsyncUrlFragmentAwarePage {
                                        return 
List.of(JavaScriptHeaderItem.forUrl("https://www.googletagmanager.com/gtag/js?id=";
 + getGaCode()).setAsync(true));
                                }
                        })));
-                       StringBuilder script = new StringBuilder("initGA('");
-                       
script.append(getGaCode()).append("');").append(isMainPage() ? "initHash()" : 
"gtagEvent()").append(';');
+                       StringBuilder script = new StringBuilder("initGA('")
+                                       .append(getGaCode()).append("', 
").append(isMainPage()).append(");");
                        response.render(OnDomReadyHeaderItem.forScript(script));
                }
                
response.render(CssHeaderItem.forReference(FontAwesome5CssReference.instance()));
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/om-ga.js 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/om-ga.js
index b3d6f99..2e3068d 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/om-ga.js
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/pages/om-ga.js
@@ -1,18 +1,12 @@
 /* Licensed under the Apache License, Version 2.0 (the "License") 
http://www.apache.org/licenses/LICENSE-2.0 */
-window.dataLayer = window.dataLayer || [];
-function gtag() {
-       dataLayer.push(arguments);
-}
-function gtagEvent() {
-       gtag('event', 'pageview', {page: location.pathname, hash: 
location.hash});
-}
-function initGA(code) {
+function initGA(code, hash) {
+       window.dataLayer = window.dataLayer || [];
+       const gtag = () => dataLayer.push(arguments)
+               , newPage = () => gtag('config', code, {'page_path': 
location.pathname + location.hash});
        gtag('js', new Date());
 
-       gtag('config', code);
-}
-function initHash() {
-       gtagEvent();
-
-       $(window).off('hashchange').on('hashchange', gtagEvent);
+       newPage();
+       if (hash) {
+               $(window).off('hashchange').on('hashchange', newPage);
+       }
 }

Reply via email to