JBAS-2002 Self-reg googalyitcs on submit/cancel events
authorBill Erickson <berickxx@gmail.com>
Mon, 2 Apr 2018 20:18:31 +0000 (16:18 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Send events to Goog indicating a submit or cancel button event.
Minor cleanup of old commented code.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/openils/var/templates_kcls/opac/register.tt2
Open-ILS/web/js/ui/default/opac/register.js

index 9d3accd..f9d5f60 100644 (file)
@@ -80,11 +80,19 @@ END; # input_field()
   <head>
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
     <title>[% l('[_1]', ctx.page_title) %]</title>
-    <!-- google analytics are now included in the BC imports -->
-    [% INCLUDE 'opac/parts/goog_analytics.tt2' %]
-    <!--
-    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
-    -->
+
+    <!-- testing alternate googalytics invocation -->
+    [%# INCLUDE 'opac/parts/goog_analytics.tt2' %]
+    <script>
+      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
+
+      ga('create', 'UA-3018520-10', 'auto');
+      ga('send', 'pageview');
+    </script>
+
     <script src="[% ctx.media_prefix %]/js/ui/default/common/build/js/jquery.min.js"></script>
     <script type="text/javascript"
       src="[% ctx.media_prefix %]/js/ui/default/opac/register.js"></script>
@@ -641,7 +649,7 @@ END; # input_field()
                 value="[% l('Submit Registration') %]"/>
             </div>
             <div class="grid-cell">
-              <button onclick="location.href='[% complete_url | html %]'; return false">
+              <button onclick="return handleCancel('[% complete_url | html %]')">
                 Cancel and Return
               </button>
             </div>
index 99dbb15..69edf90 100644 (file)
@@ -242,9 +242,26 @@ function onsub() {
         alert(msg);
         return false;
     }
+
+    if (typeof ga === 'function') {
+        console.debug('sending GA Submit event');
+        ga('send', 'event', 'Full Application', 'submit', 'Forms');
+    }
+
     return true;
 }
 
+function handleCancel(url) {
+
+    if (typeof ga === 'function') {
+        console.debug('sending GA Cancel event');
+        ga('send', 'event', 'Full Application', 'cancel', 'Forms');
+    }
+
+    location.href = url;
+    return false; // avoid form submission 
+}
+
 function activity_checker_thread() {
     var start = last_activity.getTime();
     var end = new Date().getTime();