]> _ Git - fluidbook-html5.git/commitdiff
fix #2152 @6
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 24 Jul 2018 13:55:59 +0000 (15:55 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 24 Jul 2018 13:55:59 +0000 (15:55 +0200)
js/libs/fluidbook/fluidbook.bookmarks.js
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.links.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.stats.js
js/libs/fluidbook/fluidbook.zoom.js
js/main.js

index b2db7212ddfac6e1085a1a311659e4959b352bdb..dc46359490e1d2c542ce7c123e9a7a2c99c33c23 100644 (file)
@@ -94,7 +94,7 @@ FluidbookBookmarks.prototype = {
         var re = 0;
         for (var i = 0; i < this.bookmarks.length; i++) {
             var b = this.bookmarks[i];
-            if(b>this.fluidbook.getMaxPage()){
+            if (b > this.fluidbook.getMaxPage()) {
                 continue;
             }
             if (rs == 0) {
@@ -264,7 +264,7 @@ FluidbookBookmarks.prototype = {
     },
     getLinkedPages: function (page) {
         var group = this.getGroupOfPage(page);
-        console.log('group : '+group);
+        console.log('group : ' + group);
         if (group === -1 || isNaN(group)) {
             return [];
         }
@@ -280,14 +280,14 @@ FluidbookBookmarks.prototype = {
             var page = pages[i];
 
             if (!cornersOnly) {
-                console.log('add bookmark on  page '+page);
                 this.bookmarks.push(page);
             }
         }
         if (!cornersOnly) {
-            console.log('bookmark added');
             this.updateBookmarks();
-            // TODO add stats call
+            if (pages.length > 0) {
+                this.fluidbook.stats.track(4, pages[0]);
+            }
         }
     },
     setCornersEnabled: function (page, enabled) {
index 02dc460349d9a528ca9371fe7b6eacf7564f83a7..42dcda634a7dc840de3b05e573e353f91d70538f 100644 (file)
@@ -872,10 +872,12 @@ Fluidbook.prototype = {
     },
 
     print: function (button) {
+        this.stats.track(3);
         return this.openPDF(button, true);
     },
 
     downloadPDF: function (button) {
+        this.stats.track(7);
         return this.openPDF(button, false)
     },
 
index d45affc7e996f65241945a6cb82857b7aebf3f14..261e540591888e58e681b6ab0d13dec6ffd66d64 100644 (file)
@@ -287,6 +287,8 @@ FluidbookLinks.prototype = {
             // Hide close button initially so it only shows when zoom finishes.
             $(".zoomPopupClose").css('opacity', 0);
 
+            $this.fluidbook.stats.track(2, $this.fluidbook.currentPage);
+
             // Display close button after zoom animation has finished
             setTimeout(function () {
                 $(".zoomPopupClose").css('opacity', 1);
index d6d8af300b063856aa7baf5c877006497409e755..f3d8f29e39ebdef341a927aad0d99549165d9895 100644 (file)
@@ -395,6 +395,7 @@ FluidbookMenu.prototype = {
         if (callback != undefined) {
             callback();
         }
+        this.fluidbook.stats.track(14);
     },
     openExternalChapters: function (callback) {
         var view = '<div class="caption">' + this.closeButton() + '</div>';
@@ -407,6 +408,7 @@ FluidbookMenu.prototype = {
         if (callback != undefined) {
             callback();
         }
+        this.fluidbook.stats.track(14);
     },
     openIndex: function (title, group, closeAll, callback) {
         var c = !closeAll ? ' one' : '';
@@ -531,7 +533,7 @@ FluidbookMenu.prototype = {
                     h = hh;
                     fullscreen = true;
                 }
-                forceHeight=true;
+                forceHeight = true;
                 break;
             case 'cart':
                 w = 1024;
index 497341527b6ab1a422296114b74116353e7eaa22..2b6732bdeadc966175a7b5ac7a9425ce5dbe1a77 100644 (file)
@@ -2,6 +2,19 @@ function FluidbookStats(fluidbook) {
     this.fluidbook = fluidbook;\r
     this.id = this.fluidbook.datas.id;\r
     this.vid = guid();\r
+    if (this.fluidbook.datas.googleAnalytics !== '') {\r
+        this.ga = 'gtag';\r
+        this.gaCodes = this.fluidbook.datas.googleAnalytics.split(',');\r
+        $.each(this.gaCodes, function (k, code) {\r
+            gtag('config', code, {'send_page_view': false});\r
+        });\r
+    } else {\r
+        if ('ga' in window) {\r
+            this.ga = 'ga';\r
+        } else {\r
+            this.ga = false;\r
+        }\r
+    }\r
     this.init();\r
 }\r
 \r
@@ -13,31 +26,110 @@ FluidbookStats.prototype = {
             return true;\r
         });\r
     },\r
-    trackPageChange: function () {\r
+\r
+    track: function (type, page, extra) {\r
         if (!this.fluidbook.support.hasNetwork()) {\r
             return;\r
         }\r
-        try {\r
-            if (_gaq == undefined) {\r
-                return;\r
+\r
+        if (this.fluidbook.datas.stats) {\r
+            this.trackFluidbook(type, page, extra);\r
+        }\r
+        this.trackGoogleAnalytics(type, page, extra);\r
+    },\r
+\r
+    trackGoogleAnalytics: function (type, page, extra) {\r
+        if (this.ga === false) {\r
+            return;\r
+        }\r
+\r
+        var url = location.pathname + location.search + location.hash\r
+\r
+        switch (type) {\r
+            case 0: // Change page\r
+                this._ga('pageview', url);\r
+                break;\r
+            case 10: // Open Book\r
+                this._ga('pageview');\r
+                break;\r
+            case 14: // Open chapters menu\r
+                this._ga('event', 'menu', 'click', 'chapters');\r
+                break;\r
+            case 6: // Click a link in a page\r
+                this._ga('event', 'link', 'click', extra);\r
+                break;\r
+            case 1: // Search\r
+                var l = document.createElement('a');\r
+                l.href = window.location.toString();\r
+                if (l.search == '') {\r
+                    l.search = '?';\r
+                } else {\r
+                    l.search += '&';\r
+                }\r
+                l.search = 'q=' + extra;\r
+                this._ga('pageview', l.pathname + l.search + l.hash);\r
+                break;\r
+            case 3: // Print\r
+                this._ga('event', 'menu', 'click', 'print');\r
+                break;\r
+            case 5: // Share\r
+            case 12: // Facebook\r
+            case 13: // Twitter\r
+                this._ga('event', 'share', 'send', type);\r
+                break;\r
+            case 7: // PDF\r
+            case 8: // Partial PDF\r
+                this._ga('event', 'menu', 'click', 'download');\r
+                break;\r
+            case 4: // Bookmarks\r
+                this._ga('event', 'bookmark', 'page', 'page ' + page);\r
+                break;\r
+            case 9: // Extras\r
+                this._ga('event', 'extra', 'click', extra);\r
+                break;\r
+            case 2:// Zoom\r
+                this._ga('event', 'zoom', 'page', page);\r
+                break;\r
+            case 11:// Video\r
+                this._ga('event', 'video', 'view', extra);\r
+                break;\r
+        }\r
+    },\r
+\r
+    _ga: function (a0, a1, a2, a3, a4) {\r
+        var args = Array.prototype.slice.call(arguments);\r
+        if (this.ga == 'gtag') {\r
+            var f, o, c, a;\r
+            o = {};\r
+            if (a0 === 'pageview') {\r
+                f = 'config';\r
+                c = true;\r
+                o = {};\r
+                if (a1 !== undefined) {\r
+                    o.page_path = a1;\r
+                }\r
+            } else if (a0 === 'event') {\r
+                f = 'event';\r
+                c = false;\r
+                a = a2;\r
+                o.event_category = a1;\r
+                o.event_label = a3;\r
             }\r
-            var page = location.pathname + location.search + location.hash;\r
-            if (_gatrackers != undefined) {\r
-                $.each(_gatrackers, function (k, v) {\r
-                    _gaq.push([v + '._trackPageview', page]);\r
+\r
+            if (c) {\r
+                $.each(this.gaCodes, function (k, code) {\r
+                    gtag(f, code, o);\r
                 });\r
             } else {\r
-                _gaq.push(['_trackPageview', page]);\r
+                gtag(f, a, o);\r
             }\r
-        } catch (err) {\r
-\r
+        } else if (this.ga == 'ga') {\r
+            args.unshift('send');\r
+            window['ga'].apply(null, args);\r
         }\r
     },\r
-    track: function (type, page, extra) {\r
-        if (!this.fluidbook.support.hasNetwork()) {\r
-            return;\r
-        }\r
 \r
+    trackFluidbook: function (type, page, extra) {\r
         if (page == undefined) {\r
             page = 0;\r
         }\r
@@ -64,5 +156,6 @@ FluidbookStats.prototype = {
             }\r
         });\r
     }\r
+    ,\r
 };\r
 \r
index a169c6320420ccf44f02d591afe4eaf319c59a93..5aeed86c659304209ca48e1b9a49d94b77ce9278 100644 (file)
@@ -38,6 +38,8 @@ FluidbookZoom.prototype = {
 
 
     setZoom: function (zoom, direction, end) {
+        var origZoom = this.zoom;
+
         if (end == undefined) {
             end = false;
         }
@@ -73,6 +75,10 @@ FluidbookZoom.prototype = {
         }
         this.zoom = zoom;
         this.updateZoom();
+
+        if (origZoom == 1 && this.zoom > 1) {
+            this.fluidbook.stats.track(2, this.currentPage);
+        }
     },
 
     setTransition: function (transition) {
index 799dee43e6c0781ad453722e9b3bcaa1dd60dca9..bf85ffe53809ce18c187b0a5ac84c8047ec6fd38 100644 (file)
@@ -295,7 +295,6 @@ try {
             if (maskHashChange) {
                 return;
             }
-            fluidbook.stats.trackPageChange();
             fluidbook.changeAddress();
             return false;
         });