mirror of https://github.com/garritfra/garrit.xyz
garritfra
5 years ago
6 changed files with 65 additions and 32 deletions
@ -1,5 +1,8 @@
|
||||
import React from "react"; |
||||
import ReactDOM from "react-dom"; |
||||
import App from "../src/App"; |
||||
import AnalyticsProvider from "../src/util/AnalyticsProvider"; |
||||
|
||||
AnalyticsProvider.getInstance(); |
||||
|
||||
ReactDOM.render(<App />, document.getElementById("root")); |
||||
|
@ -0,0 +1,39 @@
|
||||
export default class AnalyticsProvider { |
||||
static instance; |
||||
|
||||
constructor() { |
||||
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") { |
||||
} else { |
||||
window.ga = |
||||
window.ga || |
||||
function() { |
||||
(ga.q = ga.q || []).push(arguments); |
||||
}; |
||||
ga.l = +new Date(); |
||||
ga("create", "UA-122968527-1", "auto"); |
||||
ga("send", "pageview"); |
||||
|
||||
window.dataLayer = window.dataLayer || []; |
||||
function gtag() { |
||||
dataLayer.push(arguments); |
||||
} |
||||
gtag("js", new Date()); |
||||
|
||||
gtag("config", "UA-122968527-1"); |
||||
} |
||||
} |
||||
static getInstance() { |
||||
if (!AnalyticsProvider.instance) { |
||||
AnalyticsProvider.instance = new AnalyticsProvider(); |
||||
// ... any one time initialization goes here ...
|
||||
} |
||||
return AnalyticsProvider.instance; |
||||
} |
||||
|
||||
logEvent(category, action, label) { |
||||
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") { |
||||
} else { |
||||
ga("send", "event", category, action, label); |
||||
} |
||||
} |
||||
} |
@ -1,21 +0,0 @@
|
||||
import { Analytics } from "analytics"; |
||||
import GoogleAnalyticsPlugin from "analytics-plugin-ga"; |
||||
|
||||
export default class AnalyticsProvider { |
||||
private static instance: AnalyticsProvider; |
||||
public analytics: any; |
||||
|
||||
private constructor() { |
||||
this.analytics = Analytics({ |
||||
app: "garrit-franke", |
||||
plugins: [GoogleAnalyticsPlugin({ trackingId: "UA-122968527-1" })] |
||||
}); |
||||
} |
||||
static getInstance() { |
||||
if (!AnalyticsProvider.instance) { |
||||
AnalyticsProvider.instance = new AnalyticsProvider(); |
||||
// ... any one time initialization goes here ...
|
||||
} |
||||
return AnalyticsProvider.instance; |
||||
} |
||||
} |
Loading…
Reference in new issue