I'm currently trying to do something like Google Analytics and make a data-transfer/tracking script using Javascript.
My approach is, that I want to make a short script/snippet to implement on a site like Google Analytics' tracking script - this part is quite easy.
The problem is, that with Google analytics, they're creating a ga-variable in the snippet (the code on the website), and the setting variables like this:
ga('create', 'TRACK-ID');
ga('send', 'something', 'something);
The JavaScript-snippet that is inserted in the HTML-pages is (just like Google Analytics'):
(function(i, s, o, g, r, a, m){
i['ChurnimizerTrackObj'] = r;
i[r] = i[r] || function(){
(i[r].q = i[r].q || []).push(arguments);
},
i[r].l = 1 * new Date();
o = o || "script";
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'cm.js', 'ga');
ga('send', 'test');
ga('create', 'TR-XXXXXX');
Well, I can make the ga-variable and insert an alert event in my "local"-file (the JS-file, that should do all the logic), but I can't get to why my function isn't working as the above? My local file is:
(
function(){
alert("something");
(
return (function(a, b, c){
alert("test");
switch(a){
case "create":
alert("A is create");
case "send":
alert("A is send");
}
alert(a);
})()
);
}
)();
The problem is, that when I use the function "ga", it won't alert either the create-alert or the send-alert.
EDIT 1:
WHAT I want to know is, how I can get the function parameters from the "ga" variable in the local file?
My alerts with the static messages is fired correctly - but my approach to returning a function and alerting it's parameters just leaves the parameter-values as "undefined", where I wan't them to be "send", "create" and so on.
EDIT 2:
What I want is to pass variables from the Snippet to the local javascript-file by just writing the variable name ga as a function name. Like:
ga('send', 'someStr', 'someVal');
How do I get to the state, where I can use my ga-variable as a function setting some information in the local file? :-)
ga('send', 'something', 'something);typo? BTW, I can't understand what you trying to achieve.