Commit 5e52d113 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Add rudimentary tracking script and uglify to smallinize it

parent a9dfca22
......@@ -24,3 +24,10 @@ tilastokeskus-*.tar
# ElixirLS cache
.elixir_ls
node_modules
.vscode
# Compiled static files
/priv/static/*
!/priv/static/.gitkeep
{
"name": "tilastokeskus",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"commander": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==",
"dev": true
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"uglify-es": {
"version": "3.3.9",
"resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz",
"integrity": "sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ==",
"dev": true,
"requires": {
"commander": "~2.13.0",
"source-map": "~0.6.1"
}
}
}
}
{
"name": "tilastokeskus",
"version": "0.1.0",
"description": "Tilastokeskus analytics script",
"main": "priv/static/track.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"build": "uglifyjs -m --ie8 --ecma 5 --safari10 --timings -o priv/static/track.js static/track.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/Nicd/tilastokeskus.git"
},
"keywords": [
"analytics"
],
"author": "Mikko Ahlroth <mikko.ahlroth@gmail.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://gitlab.com/Nicd/tilastokeskus/issues"
},
"homepage": "https://gitlab.com/Nicd/tilastokeskus#README",
"devDependencies": {
"uglify-es": "^3.3.9"
}
}
\ No newline at end of file
/*
License for the docReady function below, from: https://github.com/jfriend00/docReady
The MIT License (MIT)
Copyright (c) 2014, John Friend
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
(function (funcName, baseObj) {
"use strict";
// The public function name defaults to window.docReady
// but you can modify the last line of this function to pass in a different object or method name
// if you want to put them in a different namespace and those will be used instead of
// window.docReady(...)
funcName = funcName || "docReady";
baseObj = baseObj || window;
var readyList = [];
var readyFired = false;
var readyEventHandlersInstalled = false;
// call this when the document is ready
// this function protects itself against being called more than once
function ready() {
if (!readyFired) {
// this must be set to true before we start calling callbacks
readyFired = true;
for (var i = 0; i < readyList.length; i++) {
// if a callback here happens to add new ready handlers,
// the docReady() function will see that it already fired
// and will schedule the callback to run right after
// this event loop finishes so all handlers will still execute
// in order and no new ones will be added to the readyList
// while we are processing the list
readyList[i].fn.call(window, readyList[i].ctx);
}
// allow any closures held by these functions to free
readyList = [];
}
}
function readyStateChange() {
if (document.readyState === "complete") {
ready();
}
}
// This is the one public interface
// docReady(fn, context);
// the context argument is optional - if present, it will be passed
// as an argument to the callback
baseObj[funcName] = function (callback, context) {
if (typeof callback !== "function") {
throw new TypeError("callback for docReady(fn) must be a function");
}
// if ready has already fired, then just schedule the callback
// to fire asynchronously, but right away
if (readyFired) {
setTimeout(function () { callback(context); }, 1);
return;
} else {
// add the function and context to the list
readyList.push({ fn: callback, ctx: context });
}
// if document already ready to go, schedule the ready function to run
// IE only safe when readyState is "complete", others safe when readyState is "interactive"
if (document.readyState === "complete" || (!document.attachEvent && document.readyState === "interactive")) {
setTimeout(ready, 1);
} else if (!readyEventHandlersInstalled) {
// otherwise if we don't have event handlers installed, install them
if (document.addEventListener) {
// first choice is DOMContentLoaded event
document.addEventListener("DOMContentLoaded", ready, false);
// backup is window load event
window.addEventListener("load", ready, false);
} else {
// must be IE
document.attachEvent("onreadystatechange", readyStateChange);
window.attachEvent("onload", ready);
}
readyEventHandlersInstalled = true;
}
}
})("docReady", window);
(function () {
if (!('XMLHttpRequest' in window)) {
window.XMLHttpRequest = function () {
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
function send() {
var data = {};
if ('screen' in window && 'width' in window.screen) {
data['screen_width'] = window.screen.width;
data['screen_height'] = window.screen.height;
}
data.tz_offset = (new Date()).getTimezoneOffset();
var data_parts = [];
function add_part(source, key, parts) {
if (key in source) parts.push(key + '=' + encodeURIComponent(data[key]));
}
add_part(data, 'screen_width', data_parts);
add_part(data, 'screen_height', data_parts);
add_part(data, 'tz_offset', data_parts);
var data_str = data_parts.join('&');
if ('tilastokeskus_url' in window) {
var req = new XMLHttpRequest();
req.open('POST', window.tilastokeskus_url);
req.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
req.send(data_str);
}
else if ('console' in window) {
console.log('Tilastokeskus URL not set, would have sent data:', data_str);
}
}
// Send when DOM is hopefully available
docReady(send);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment