Skip to content

Commit

Permalink
Need to use window.ga (#195)
Browse files Browse the repository at this point in the history
* Need to use window.ga

* No need to import
  • Loading branch information
azizhk authored Jan 24, 2019
1 parent 072fbfc commit fb7d957
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/utils/analytics/ga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import isBrowser from "is-in-browser";
declare global {
interface Window {
GoogleAnalyticsObject: string;
ga: UniversalAnalytics.ga;
}
}

export function initGoogleAnalytics(gaId: string) {
if (isBrowser) {
((s, o, g) => {
window.GoogleAnalyticsObject = "ga";
ga =
ga ||
window.ga =
window.ga ||
(() => {
(ga.q = ga.q || []).push(arguments);
(window.ga.q = window.ga.q || []).push(arguments);
});
ga.l = Date.now();
window.ga.l = Date.now();
const a = s.createElement(o) as HTMLScriptElement;
const m = s.getElementsByTagName(o)[0];
a.async = true;
a.src = g;
if (m.parentNode) m.parentNode.insertBefore(a, m);
})(document, "script", "https://www.google-analytics.com/analytics.js");

ga("create", gaId, "auto");
ga("send", "pageview");
window.ga("create", gaId, "auto");
window.ga("send", "pageview");
}
}

1 comment on commit fb7d957

@vercel
Copy link

@vercel vercel bot commented on fb7d957 Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://pebble-uhjxgbamih.now.sh to the following alias.

Please sign in to comment.