]> _ Git - fluidbook-html5.git/commitdiff
Added a small note about Matomo stats for future reference.
authorStephen Cameron <stephen@cubedesigners.com>
Wed, 21 Sep 2022 16:17:12 +0000 (18:17 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Wed, 21 Sep 2022 16:17:12 +0000 (18:17 +0200)
js/libs/fluidbook/fluidbook.stats.js

index a6867d0aba4c31bcd4a33783d5c208ff550df900..34f123809423fece396ed8c4605284026e56f39c 100644 (file)
-function FluidbookStats(fluidbook) {\r
-    var $this = this;\r
-    this.fluidbook = fluidbook;\r
-    this.id = this.fluidbook.settings.id;\r
-    this.vid = guid();\r
-    this.relay_url_params = '';\r
-    this.lastTCHash = '';\r
-    this.gaqueue = [];\r
-    if (this.fluidbook.settings.stats) {\r
-        this.worker = new Worker('js/libs/fluidbook/workers/stats.js');\r
-    }\r
-    if (this.fluidbook.settings.statsMatomo) {\r
-        if (this.fluidbook.settings.statsMatomoServer === undefined || this.fluidbook.settings.statsMatomoServer === null) {\r
-            this.fluidbook.settings.statsMatomoServer = '3';\r
-        }\r
-        window._paq = window._paq || [];\r
-        window._paq.push(["setDoNotTrack", true]);\r
-        window._paq.push(['enableHeartBeatTimer']);\r
-        window._paq.push(['enableLinkTracking']);\r
-        (function (siteId, server) {\r
-            var u = "https://stats" + server + ".fluidbook.com/";\r
-            window._paq.push(['setTrackerUrl', u + 'matomo.php']);\r
-            window._paq.push(['setSiteId', siteId]);\r
-            var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];\r
-            g.async = true;\r
-            g.src = u + 'matomo.js';\r
-            s.parentNode.insertBefore(g, s);\r
-        })(this.fluidbook.settings.statsMatomo, this.fluidbook.settings.statsMatomoServer.toString());\r
-    }\r
-    if (this.fluidbook.settings.googleTagManager !== undefined && this.fluidbook.settings.googleTagManager !== '') {\r
-        this.ga = 'gtm';\r
-    } else if (this.fluidbook.settings.googleAnalytics !== '') {\r
-        this.ga = 'gtag';\r
-        this.gaCodes = this.fluidbook.settings.googleAnalytics.split(',');\r
-        if (window.gtag !== undefined) {\r
-            gtag('js', new Date());\r
-        }\r
-        $.each(this.gaCodes, function (k, code) {\r
-            if (window.gtag !== undefined) {\r
-                gtag('config', code, {'send_page_view': false});\r
-            }\r
-        });\r
-        if (this.fluidbook.settings.gtag_additional_code !== '') {\r
-            eval(this.fluidbook.settings.gtag_additional_code);\r
-        }\r
-    } else {\r
-        this.checkGoogleAnalytics();\r
-    }\r
-    if (this.fluidbook.settings.relay_url_params !== '') {\r
-        var e = this.fluidbook.settings.relay_url_params.split(',');\r
-        var p = [];\r
-        $.each(e, function (k, v) {\r
-            v = v.trim();\r
-            if ($_GET[v] !== undefined && $_GET[v] !== null) {\r
-                p.push(v + '=' + encodeURIComponent($_GET[v]));\r
-            }\r
-        });\r
-        this.relay_url_params = p.join('&');\r
-    }\r
-    this.init();\r
-}\r
-\r
-FluidbookStats.prototype = {\r
-    init: function () {\r
-        var $this = this;\r
-        $(document).on(this.fluidbook.input.clickEvent, 'a[data-track]', function () {\r
-            $this.track(6, 0, $(this).attr('data-track'));\r
-            return true;\r
-        });\r
-\r
-        if (this.fluidbook.settings.tagcommander_id) {\r
-            this.initTagCommander();\r
-        }\r
-    },\r
-\r
-    initTagCommander: function () {\r
-        var $this = this;\r
-        $(this.fluidbook).on('fluidbook.hashchange', function (e, data) {\r
-            if (window.location.hash === this.lastTCHash) {\r
-                return;\r
-            }\r
-            this.lastTCHash = window.location.hash;\r
-\r
-            data.shift();\r
-            var hashes = [];\r
-            if (!$this.fluidbook.displayOnePage && data[0] == 'page') {\r
-                var p = parseInt(data[1]);\r
-                if (!isNaN(p)) {\r
-                    var even, odd;\r
-                    if (p % 2 === 0) {\r
-                        even = p;\r
-                        odd = p + 1;\r
-                    } else {\r
-                        odd = p;\r
-                        even = p - 1;\r
-                    }\r
-                    if ($this.fluidbook.settings.tagcommander_plan['page/' + even] !== undefined) {\r
-                        data[1] = even;\r
-                        hashes.push(data.join('/'));\r
-                    }\r
-\r
-                    if ($this.fluidbook.settings.tagcommander_plan['page/' + odd] !== undefined) {\r
-                        data[1] = odd;\r
-                        hashes.push(data.join('/'));\r
-                    }\r
-                }\r
-            } else {\r
-                hashes.push(data.join('/'));\r
-            }\r
-\r
-            var custom_vars = {};\r
-            if (window.location.toString().indexOf('workshop.fluidbook.com') >= 0) {\r
-                custom_vars.env_work = 'pre-prod';\r
-            }\r
-\r
-\r
-            $.each(hashes, function (k, hash) {\r
-                if ($this.fluidbook.settings.tagcommander_plan[hash]) {\r
-                    setTimeout(function () {\r
-                        window.tc_vars = {};\r
-                        var location = window.location.toString().split("#")[0];\r
-                        location += '#/' + hash;\r
-                        custom_vars.url = location;\r
-\r
-                        $.extend(window.tc_vars, $this.fluidbook.settings.tagcommander_default_vars, custom_vars, $this.fluidbook.settings.tagcommander_plan[hash]);\r
-                        console.info('Tag commander', window.tc_vars);\r
-                        try {\r
-                            var o = {events: {}};\r
-                            o.events[$this.fluidbook.settings.tagcommander_event_page] = [{}, {}];\r
-                            tC.container.reload(o);\r
-                        } catch (e) {\r
-                            console.error(e);\r
-                        }\r
-                    }, 500 * k)\r
-\r
-                }\r
-            });\r
-\r
-\r
-        });\r
-    },\r
-\r
-    track: function (type, page, extra) {\r
-        if (!this.fluidbook.support.hasNetwork() || this.fluidbook.nointerface) {\r
-            return;\r
-        }\r
-\r
-        if (this.fluidbook.settings.stats) {\r
-            try {\r
-                this.trackFluidbook(type, page, extra);\r
-            } catch (e) {\r
-\r
-            }\r
-        }\r
-        if (this.fluidbook.settings.statsMatomo) {\r
-            try {\r
-                this.trackMatomo(type, page, extra);\r
-            } catch (e) {\r
-\r
-            }\r
-        }\r
-        try {\r
-            this.trackGoogleAnalytics(type, page, extra);\r
-        } catch (e) {\r
-            console.log(e);\r
-        }\r
-    },\r
-\r
-    checkGoogleAnalytics: function () {\r
-        if (this.ga !== false && this.ga !== undefined) {\r
-            return;\r
-        }\r
-        if ('gtag' in window) {\r
-            this.ga = 'gtag';\r
-        } else if ('ga' in window && "getAll" in window.ga) {\r
-            this.ga = 'ga';\r
-        } else {\r
-            this.ga = false;\r
-        }\r
-\r
-        if (this.ga !== false && this.gaqueue.length > 0) {\r
-            var $this = this;\r
-            $.each(this.gaqueue, function (k, v) {\r
-                $this.trackGoogleAnalytics(v[0], v[1], v[2], v[3]);\r
-            });\r
-            this.gaqueue = [];\r
-        }\r
-    },\r
-\r
-    trackMatomo(type, page, extra, url) {\r
-        if (url === undefined) {\r
-            url = window.location;\r
-        }\r
-        switch (type) {\r
-            case 0: // Change page\r
-                window._paq.push(['setCustomUrl', '/page/' + page]);\r
-                window._paq.push(['trackPageView', 'View page ' + page]);\r
-                break;\r
-            case 10: // Open Book\r
-                window._paq.push(['setCustomUrl', '/']);\r
-                window._paq.push(['trackPageView', 'Open fluidbook']);\r
-                break;\r
-            case 14: // Open chapters menu\r
-                window._paq.push(['trackEvent', 'menu', 'click', 'chapters']);\r
-                break;\r
-            case 6: // Click a link in a page\r
-                window._paq.push(['trackEvent', 'link', 'click', extra]);\r
-                window._paq.push(['trackLink', extra]);\r
-                break;\r
-            case 1: // Search\r
-                window._paq.push(['trackSiteSearch', extra]);\r
-                break;\r
-            case 3: // Print\r
-                window._paq.push(['trackEvent', 'menu', 'click', 'print']);\r
-                break;\r
-            case 5: // Share\r
-            case 12: // Facebook\r
-            case 13: // Twitter\r
-                window._paq.push(['trackEvent', 'share', 'send', extra]);\r
-                break;\r
-            case 7: // PDF\r
-            case 8: // Partial PDF\r
-                window._paq.push(['trackEvent', 'menu', 'click', 'download']);\r
-                break;\r
-            case 4: // Bookmarks\r
-                window._paq.push(['trackEvent', 'bookmark', 'page', 'page ' + page]);\r
-                break;\r
-            case 9: // Extras\r
-                window._paq.push(['trackEvent', 'extra', 'click', extra]);\r
-                break;\r
-            case 2:// Zoom\r
-                window._paq.push(['trackEvent', 'zoom', 'page', page]);\r
-                break;\r
-            case 11:// Video\r
-                window._paq.push(['trackEvent', 'video', 'view', extra]);\r
-                break;\r
-            case 15://\r
-                window._paq.push(['trackEvent', 'cart', 'addproduct', extra]);\r
-        }\r
-    },\r
-\r
-    trackGoogleAnalytics: function (type, page, extra, url) {\r
-        this.checkGoogleAnalytics();\r
-\r
-        if (url === undefined) {\r
-            url = location.pathname + location.search + location.hash\r
-        }\r
-        if (this.ga === false) {\r
-            this.gaqueue.push([type, page, extra, url]);\r
-            return;\r
-        }\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', extra);\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
-            case 15://\r
-                this._ga('event', 'cart', 'addproduct', extra);\r
-        }\r
-    },\r
-\r
-    _ga: function (a0, a1, a2, a3, a4) {\r
-        console.log('_ga', a0, a1, a2, a3, a4);\r
-        var args = Array.prototype.slice.call(arguments);\r
-        if (this.ga === 'gtm') {\r
-            var dl = {};\r
-            if (a0 === 'pageview') {\r
-                dl.event = 'pageview';\r
-                if (a1 !== undefined) {\r
-                    dl.location = a1;\r
-                }\r
-            } else if (a0 === 'event') {\r
-                dl.event = a1;\r
-                dl.eventLabel = a3;\r
-                dl.eventAction = a2;\r
-            }\r
-            dataLayer.push(dl);\r
-        } else if (this.ga === 'gtag') {\r
-            var f, o, a;\r
-            o = {};\r
-            if (a0 === 'pageview') {\r
-                f = 'event';\r
-                o = {};\r
-                a = 'page_view';\r
-                if (a1 !== undefined) {\r
-                    o.page_path = a1;\r
-                }\r
-            } else if (a0 === 'event') {\r
-                f = 'event';\r
-                a = a2;\r
-                o.event_category = a1;\r
-                o.event_label = a3;\r
-            }\r
-\r
-            $.each(this.gaCodes, function (k, code) {\r
-                var data = $.extend({send_to: code}, o)\r
-                gtag(f, a, data);\r
-            });\r
-        } else if (this.ga === 'ga') {\r
-            $.each(ga.getAll(), function (k, tracker) {\r
-                try {\r
-                    tracker.send.apply(tracker, args);\r
-                } catch (e) {\r
-                }\r
-            });\r
-        }\r
-    },\r
-\r
-    trackFluidbook: function (type, page, extra) {\r
-        if (page == undefined) {\r
-            page = 0;\r
-        }\r
-        if (extra == undefined) {\r
-            extra = '';\r
-        }\r
-\r
-        var $this = this;\r
-\r
-\r
-        var data = {\r
-            id: $this.id, vid: $this.vid, type: type, page: page, str: extra, time: new Date().getTime()\r
-        };\r
-\r
-        setTimeout(function () {\r
-            $this.fluidbook.networkControl.executeWhenNetwork(function (cb) {\r
-                $this.worker.postMessage(data);\r
-                setTimeout(cb, 100);\r
-            }, false);\r
-        }, 2500);\r
-    }\r
-};\r
-\r
+function FluidbookStats(fluidbook) {
+    var $this = this;
+    this.fluidbook = fluidbook;
+    this.id = this.fluidbook.settings.id;
+    this.vid = guid();
+    this.relay_url_params = '';
+    this.lastTCHash = '';
+    this.gaqueue = [];
+    if (this.fluidbook.settings.stats) {
+        this.worker = new Worker('js/libs/fluidbook/workers/stats.js');
+    }
+    if (this.fluidbook.settings.statsMatomo) {
+        if (this.fluidbook.settings.statsMatomoServer === undefined || this.fluidbook.settings.statsMatomoServer === null) {
+            this.fluidbook.settings.statsMatomoServer = '3';
+        }
+        window._paq = window._paq || [];
+        window._paq.push(["setDoNotTrack", true]);
+        window._paq.push(['enableHeartBeatTimer']);
+        window._paq.push(['enableLinkTracking']);
+        (function (siteId, server) {
+            var u = "https://stats" + server + ".fluidbook.com/";
+            window._paq.push(['setTrackerUrl', u + 'matomo.php']);
+            window._paq.push(['setSiteId', siteId]);
+            var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
+            g.async = true;
+            g.src = u + 'matomo.js';
+            s.parentNode.insertBefore(g, s);
+        })(this.fluidbook.settings.statsMatomo, this.fluidbook.settings.statsMatomoServer.toString());
+    }
+    if (this.fluidbook.settings.googleTagManager !== undefined && this.fluidbook.settings.googleTagManager !== '') {
+        this.ga = 'gtm';
+    } else if (this.fluidbook.settings.googleAnalytics !== '') {
+        this.ga = 'gtag';
+        this.gaCodes = this.fluidbook.settings.googleAnalytics.split(',');
+        if (window.gtag !== undefined) {
+            gtag('js', new Date());
+        }
+        $.each(this.gaCodes, function (k, code) {
+            if (window.gtag !== undefined) {
+                gtag('config', code, {'send_page_view': false});
+            }
+        });
+        if (this.fluidbook.settings.gtag_additional_code !== '') {
+            eval(this.fluidbook.settings.gtag_additional_code);
+        }
+    } else {
+        this.checkGoogleAnalytics();
+    }
+    if (this.fluidbook.settings.relay_url_params !== '') {
+        var e = this.fluidbook.settings.relay_url_params.split(',');
+        var p = [];
+        $.each(e, function (k, v) {
+            v = v.trim();
+            if ($_GET[v] !== undefined && $_GET[v] !== null) {
+                p.push(v + '=' + encodeURIComponent($_GET[v]));
+            }
+        });
+        this.relay_url_params = p.join('&');
+    }
+    this.init();
+}
+
+FluidbookStats.prototype = {
+    init: function () {
+        var $this = this;
+        $(document).on(this.fluidbook.input.clickEvent, 'a[data-track]', function () {
+            $this.track(6, 0, $(this).attr('data-track'));
+            return true;
+        });
+
+        if (this.fluidbook.settings.tagcommander_id) {
+            this.initTagCommander();
+        }
+    },
+
+    initTagCommander: function () {
+        var $this = this;
+        $(this.fluidbook).on('fluidbook.hashchange', function (e, data) {
+            if (window.location.hash === this.lastTCHash) {
+                return;
+            }
+            this.lastTCHash = window.location.hash;
+
+            data.shift();
+            var hashes = [];
+            if (!$this.fluidbook.displayOnePage && data[0] == 'page') {
+                var p = parseInt(data[1]);
+                if (!isNaN(p)) {
+                    var even, odd;
+                    if (p % 2 === 0) {
+                        even = p;
+                        odd = p + 1;
+                    } else {
+                        odd = p;
+                        even = p - 1;
+                    }
+                    if ($this.fluidbook.settings.tagcommander_plan['page/' + even] !== undefined) {
+                        data[1] = even;
+                        hashes.push(data.join('/'));
+                    }
+
+                    if ($this.fluidbook.settings.tagcommander_plan['page/' + odd] !== undefined) {
+                        data[1] = odd;
+                        hashes.push(data.join('/'));
+                    }
+                }
+            } else {
+                hashes.push(data.join('/'));
+            }
+
+            var custom_vars = {};
+            if (window.location.toString().indexOf('workshop.fluidbook.com') >= 0) {
+                custom_vars.env_work = 'pre-prod';
+            }
+
+
+            $.each(hashes, function (k, hash) {
+                if ($this.fluidbook.settings.tagcommander_plan[hash]) {
+                    setTimeout(function () {
+                        window.tc_vars = {};
+                        var location = window.location.toString().split("#")[0];
+                        location += '#/' + hash;
+                        custom_vars.url = location;
+
+                        $.extend(window.tc_vars, $this.fluidbook.settings.tagcommander_default_vars, custom_vars, $this.fluidbook.settings.tagcommander_plan[hash]);
+                        console.info('Tag commander', window.tc_vars);
+                        try {
+                            var o = {events: {}};
+                            o.events[$this.fluidbook.settings.tagcommander_event_page] = [{}, {}];
+                            tC.container.reload(o);
+                        } catch (e) {
+                            console.error(e);
+                        }
+                    }, 500 * k)
+
+                }
+            });
+
+
+        });
+    },
+
+    track: function (type, page, extra) {
+        if (!this.fluidbook.support.hasNetwork() || this.fluidbook.nointerface) {
+            return;
+        }
+
+        if (this.fluidbook.settings.stats) {
+            try {
+                this.trackFluidbook(type, page, extra);
+            } catch (e) {
+
+            }
+        }
+        if (this.fluidbook.settings.statsMatomo) {
+            try {
+                this.trackMatomo(type, page, extra);
+            } catch (e) {
+
+            }
+        }
+        try {
+            this.trackGoogleAnalytics(type, page, extra);
+        } catch (e) {
+            console.log(e);
+        }
+    },
+
+    checkGoogleAnalytics: function () {
+        if (this.ga !== false && this.ga !== undefined) {
+            return;
+        }
+        if ('gtag' in window) {
+            this.ga = 'gtag';
+        } else if ('ga' in window && "getAll" in window.ga) {
+            this.ga = 'ga';
+        } else {
+            this.ga = false;
+        }
+
+        if (this.ga !== false && this.gaqueue.length > 0) {
+            var $this = this;
+            $.each(this.gaqueue, function (k, v) {
+                $this.trackGoogleAnalytics(v[0], v[1], v[2], v[3]);
+            });
+            this.gaqueue = [];
+        }
+    },
+
+    trackMatomo(type, page, extra, url) {
+        if (url === undefined) {
+            url = window.location;
+        }
+        switch (type) {
+            case 0: // Change page
+                window._paq.push(['setCustomUrl', '/page/' + page]);
+                window._paq.push(['trackPageView', 'View page ' + page]);
+                break;
+            case 10: // Open Book
+                window._paq.push(['setCustomUrl', '/']); // Note: this shows as "/index" in the Matomo page URL reports (unless in flat view)
+                window._paq.push(['trackPageView', 'Open fluidbook']);
+                break;
+            case 14: // Open chapters menu
+                window._paq.push(['trackEvent', 'menu', 'click', 'chapters']);
+                break;
+            case 6: // Click a link in a page
+                window._paq.push(['trackEvent', 'link', 'click', extra]);
+                window._paq.push(['trackLink', extra]);
+                break;
+            case 1: // Search
+                window._paq.push(['trackSiteSearch', extra]);
+                break;
+            case 3: // Print
+                window._paq.push(['trackEvent', 'menu', 'click', 'print']);
+                break;
+            case 5: // Share
+            case 12: // Facebook
+            case 13: // Twitter
+                window._paq.push(['trackEvent', 'share', 'send', extra]);
+                break;
+            case 7: // PDF
+            case 8: // Partial PDF
+                window._paq.push(['trackEvent', 'menu', 'click', 'download']);
+                break;
+            case 4: // Bookmarks
+                window._paq.push(['trackEvent', 'bookmark', 'page', 'page ' + page]);
+                break;
+            case 9: // Extras
+                window._paq.push(['trackEvent', 'extra', 'click', extra]);
+                break;
+            case 2:// Zoom
+                window._paq.push(['trackEvent', 'zoom', 'page', page]);
+                break;
+            case 11:// Video
+                window._paq.push(['trackEvent', 'video', 'view', extra]);
+                break;
+            case 15://
+                window._paq.push(['trackEvent', 'cart', 'addproduct', extra]);
+        }
+    },
+
+    trackGoogleAnalytics: function (type, page, extra, url) {
+        this.checkGoogleAnalytics();
+
+        if (url === undefined) {
+            url = location.pathname + location.search + location.hash
+        }
+        if (this.ga === false) {
+            this.gaqueue.push([type, page, extra, url]);
+            return;
+        }
+
+        switch (type) {
+            case 0: // Change page
+                this._ga('pageview', url);
+                break;
+            case 10: // Open Book
+                this._ga('pageview');
+                break;
+            case 14: // Open chapters menu
+                this._ga('event', 'menu', 'click', 'chapters');
+                break;
+            case 6: // Click a link in a page
+                this._ga('event', 'link', 'click', extra);
+                break;
+            case 1: // Search
+                var l = document.createElement('a');
+                l.href = window.location.toString();
+                if (l.search == '') {
+                    l.search = '?';
+                } else {
+                    l.search += '&';
+                }
+                l.search = 'q=' + extra;
+                this._ga('pageview', l.pathname + l.search + l.hash);
+                break;
+            case 3: // Print
+                this._ga('event', 'menu', 'click', 'print');
+                break;
+            case 5: // Share
+            case 12: // Facebook
+            case 13: // Twitter
+                this._ga('event', 'share', 'send', extra);
+                break;
+            case 7: // PDF
+            case 8: // Partial PDF
+                this._ga('event', 'menu', 'click', 'download');
+                break;
+            case 4: // Bookmarks
+                this._ga('event', 'bookmark', 'page', 'page ' + page);
+                break;
+            case 9: // Extras
+                this._ga('event', 'extra', 'click', extra);
+                break;
+            case 2:// Zoom
+                this._ga('event', 'zoom', 'page', page);
+                break;
+            case 11:// Video
+                this._ga('event', 'video', 'view', extra);
+                break;
+            case 15://
+                this._ga('event', 'cart', 'addproduct', extra);
+        }
+    },
+
+    _ga: function (a0, a1, a2, a3, a4) {
+        console.log('_ga', a0, a1, a2, a3, a4);
+        var args = Array.prototype.slice.call(arguments);
+        if (this.ga === 'gtm') {
+            var dl = {};
+            if (a0 === 'pageview') {
+                dl.event = 'pageview';
+                if (a1 !== undefined) {
+                    dl.location = a1;
+                }
+            } else if (a0 === 'event') {
+                dl.event = a1;
+                dl.eventLabel = a3;
+                dl.eventAction = a2;
+            }
+            dataLayer.push(dl);
+        } else if (this.ga === 'gtag') {
+            var f, o, a;
+            o = {};
+            if (a0 === 'pageview') {
+                f = 'event';
+                o = {};
+                a = 'page_view';
+                if (a1 !== undefined) {
+                    o.page_path = a1;
+                }
+            } else if (a0 === 'event') {
+                f = 'event';
+                a = a2;
+                o.event_category = a1;
+                o.event_label = a3;
+            }
+
+            $.each(this.gaCodes, function (k, code) {
+                var data = $.extend({send_to: code}, o)
+                gtag(f, a, data);
+            });
+        } else if (this.ga === 'ga') {
+            $.each(ga.getAll(), function (k, tracker) {
+                try {
+                    tracker.send.apply(tracker, args);
+                } catch (e) {
+                }
+            });
+        }
+    },
+
+    trackFluidbook: function (type, page, extra) {
+        if (page == undefined) {
+            page = 0;
+        }
+        if (extra == undefined) {
+            extra = '';
+        }
+
+        var $this = this;
+
+
+        var data = {
+            id: $this.id, vid: $this.vid, type: type, page: page, str: extra, time: new Date().getTime()
+        };
+
+        setTimeout(function () {
+            $this.fluidbook.networkControl.executeWhenNetwork(function (cb) {
+                $this.worker.postMessage(data);
+                setTimeout(cb, 100);
+            }, false);
+        }, 2500);
+    }
+};
+