Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
breakoutModefull-width
languagehtml
<!--@@ Location of places mouseflow implemented: 
       https://victoriauniversity.atlassian.net/wiki/spaces/BAU/pages/93458019/Mouseflow+tracking+update @@-->

<!-- Mouseflow Current 1913605 -->
<script type="text/javascript">
    const mouseflowAssetId = "%asset_name% %asset_assetid%"; // Used for debugging on the front end
    var _mfq = _mfq || [];

    var currentHostname = window.location.hostname;
    var currentPathname = window.location.pathname;
    var mouseflowPathcurrentQueries  = window.location.hostname + window.location.pathname; // Set as default. Excludes all query stringssearch;

    // Edit path for mouseflowPath
    // Alias intranet.wgtn.ac.nz/staff to intranet.wgtn.ac.nz ONLY if intranet.wgtn.ac.nz is present
    if (currentHostname.indexOf("intranet") >= 0 && (currentPathname.indexOf("/staff/") === 0 || currentPathname === "/staff")) {
        console.log("Removing /staff from mouseflowPath");
        currentPathname = currentPathname.substring("/staff".length);
    }

    // Remove _nocache
    if (currentPathname.indexOf("/_nocache") >= 0) {
        console.log("Remove _nocache from mouseflowPath");
        currentPathname = currentPathname.substring(0, currentPathname.indexOf("/_nocache"));
    }
    // Remove /home
    if (currentPathname.search(/\/home$/) >= 0) {
        console.log("Remove /home from mouseflowPath");
        currentPathname = currentPathname.substring(0, currentPathname.search(/\/home$/));
    }

    // As extra precaution, remove trailing /
    if (currentPathname.charAt(currentPathname.length - 1) === "/") {
        console.log("Removing trailing / from mouseflowPath");
        currentPathname = currentPathname.substring(0, -1);
    }

    var mouseflowPath = currentHostname + currentPathname; // This excludes queries. Add + currentQueries to include them
    
    // Adding exceptions for staff and student toolbars
    if (currentQueries.search(/mytools(&|$)/) >= 0) {
        console.log("Setting mouseflowPath to mytools without path");
        mouseflowPath = currentHostname + "?mytools";
    } else if (currentQueries.search(/toolbar(&|$)/) >= 0) {
        console.log("Setting mouseflowPath to toolbar without path");
        mouseflowPath = currentHostname + "?toolbar";
    }
    
    console.log("mouseflowPath: " + mouseflowPath);

    (function () {
        var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true;

        // Check whether intranet or www
        if (currentHostnamewindow.location.hostname.indexOf("intranet") >= 0 // On intranet
            || currentPathnamewindow.location.pathname.indexOf("/staff/") === 0 || window.location.pathname === "/staff" // Catch for some situations where /staff/ is used instead of intranet. E.g. on cms.wgtn.ac.nz
        ) {
            console.log("Load intranet mouseflow");
            mf.src = "//cdn.mouseflow.com/projects/741e0e81-8c7c-4934-a0b3-76f524f9a10a.js";

        } else {
            console.log("Load regularwgtn mouseflow");
            mf.src = "//cdn.mouseflow.com/projects/4a7ff1cf-f5b8-4dd8-95da-13bfe4f4e580.js";
        }
        console.log(mf);
        // document.getElementsByTagName("head")[0].appendChild(mf);

        // Adds key to recording with original url if it has been changed
        if(mouseflowPath !== window.location.href.substring(window.location.protocol.length + 2)) {
            _mfq.push(["setVariable", 'originalUrl', window.location.href]);
        }
    })();

</script>