Skip to content

Instantly share code, notes, and snippets.

@chodorowicz
Last active April 16, 2021 13:48
Show Gist options
  • Save chodorowicz/5f1b1e563b45aefe1b68f090699dc661 to your computer and use it in GitHub Desktop.
Save chodorowicz/5f1b1e563b45aefe1b68f090699dc661 to your computer and use it in GitHub Desktop.
TypeScript + Google Analytics = ❤️
function initAnalytics() {
(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");
ga("create", "UA-XXXXXXXX-X", "auto");
ga("send", "pageview");
}
export { initAnalytics };
/* tslint:disable ban-comma-operator only-arrow-functions */
function initAnalytics() {
(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");
ga("create", "UA-XXXXXXXX-X", "auto");
ga("send", "pageview");
}
export { initAnalytics };
/* tslint:disable ban-comma-operator only-arrow-functions */
function initAnalytics() {
(function(i, s, o: "script", g, r: "ga", a?: HTMLScriptElement, m?: Element) {
i.GoogleAnalyticsObject = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date().getTime());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = true;
a.src = g;
if (m.parentNode !== null) {
m.parentNode.insertBefore(a, m);
}
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-XXXXXXXX-X", "auto");
ga("send", "pageview");
}
export { initAnalytics };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment