Use the Magnolia CMS 5 tag/snippet manager app to keep organised your tracking snippets ( and test with node.js)

In a couple of days german version of Linux Magasin will ship a bundle of latest Magnolia CMS with a couple of apps.
One of those apps is a so called tag or snippet manager that allows you to easily maintain you analytic tags.
In this post we will explain you how to use it without having to register to an analytics tool with a simple node.js scipt.

Open the tag manager app:
add a tag
Edit the tag as follows:
image2
Insert the following script in the tag content:


jQuery.noConflict();
jQuery( document ).ready(function( $ ) {
$.get( "http://127.0.0.1:1337", { origin: window.location.pathname } );
});

image3
Run the minimal analytics server !

/**
 * Created with IntelliJ IDEA.
 * User: kdewitte
 * Date: 12/02/14
 * Time: 13:52
 * To change this template use File | Settings | File Templates.
 */
 
var url = require('url');
var http = require('http');
var map  = {};
 
 
function nicify(map){
    var buff="";
    for(key in map){
       buff+="<h3>"+key+"</h3>"
       buff+=" was clicked <b>"+map[key]+"</b> times";
       buff+="<br />";
    }
   return buff+"";
}
 
http.createServer(function (req, res) {
        var parsedUrl = url.parse(req.url, true); // true to get query as object
        var queryAsObject = parsedUrl.query;
        switch(parsedUrl.pathname){
            case '/dashboard':
                switch(queryAsObject.format){
                    case 'pretty':
                        res.writeHead(200, {'Content-Type': 'text/html'});
                        res.end(nicify(map));
                        break;
                    default:
                        res.writeHead(200, {'Content-Type': 'text/json'});
                        res.end(JSON.stringify(map));
                }
                break;
            default:
                var origin = queryAsObject.origin;
                var value = map[origin];
                if(value!=null){
                    value++;
                    map[origin]=value;
                }else{
                    map[origin]=1;
                }
                console.log(JSON.stringify(map));
                res.writeHead(200, {'Content-Type': 'text/plain'});
                res.end(JSON.stringify(map));
                break;
        }
}
).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Check the results:
image4

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: