I got a problems trying to implement google analytics in angular2.
According to information I found and as example, in this post it seems pretty easy. But so far I didn't found any example how to do it not from .html
but from .ts
instead.
I am trying to make a private method with google analytics and then call it in constructor. Something like that.
constructor() {
this.initializeAnalytics();
}
private initializeAnalytics() {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
...
...
}
But just placing google analytics code is not working (Error: supplied parameters do not match any signature of call target
). I probably am doing it in wrong way.
How can I accomplish this?