Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Switch from autotrack to react-ga to get analytics working with next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sedubois committed Jan 18, 2017
1 parent 0c9f9aa commit a9d2bce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -13,13 +13,13 @@
"dependencies": {
"apollo-client": "^0.7.2",
"auth0-lock": "^10.7.2",
"autotrack": "^1.0.3",
"graphql-anywhere": "^2.0.0",
"graphql-tag": "^1.1.2",
"next": "^2.0.0-beta",
"nprogress": "^0.2.0",
"path-match": "^1.2.4",
"react-apollo": "^0.8.1",
"react-ga": "^2.1.2",
"react-player": "^0.14.1",
"smooch": "^3.9.3",
"uuid": "^3.0.1"
Expand Down
23 changes: 8 additions & 15 deletions util/analytics.js
@@ -1,28 +1,21 @@
import { ANALYTICS_TRACKING_ID } from '../config';
import { IS_BROWSER } from '../util/website';

let ReactGA;
if (IS_BROWSER) {
ReactGA = require('react-ga'); // eslint-disable-line global-require
}

export function configureAnalytics() {
if (IS_BROWSER) {
// eslint-disable-next-line
window.ga = window.ga || function () {(ga.q = ga.q || []).push(arguments)};ga.l = +new Date;
/* global ga: true */
ga('create', ANALYTICS_TRACKING_ID, 'auto');
ga('require', 'urlChangeTracker');
/* eslint-disable global-require */
require('autotrack/lib/plugins/clean-url-tracker');
ga('require', 'cleanUrlTracker');
require('autotrack/lib/plugins/outbound-form-tracker');
ga('require', 'outboundFormTracker');
require('autotrack/lib/plugins/outbound-link-tracker');
/* eslint-enable global-require */
ga('require', 'outboundLinkTracker');
ReactGA.initialize(ANALYTICS_TRACKING_ID);
}
}

export function pageView() {
if (IS_BROWSER) {
const page = window.location.pathname;
ga('set', 'page', page);
ga('send', 'pageview');
ReactGA.set({ page });
ReactGA.pageview(page);
}
}
43 changes: 8 additions & 35 deletions yarn.lock
Expand Up @@ -249,14 +249,6 @@ auth0-lock@^10.7.2:
trim "0.0.1"
url-join "^1.1.0"

autotrack@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/autotrack/-/autotrack-1.0.3.tgz#9caef961eb9899cfe369e43d4340655233c4ac15"
dependencies:
debounce "^1.0.0"
dom-utils "^0.4.0"
object-assign "^4.1.0"

aws-sign2@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"
Expand Down Expand Up @@ -1251,20 +1243,10 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

date-now@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-1.0.1.tgz#bb7d086438debe4182a485fb3df3fbfb99d6153c"

date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"

debounce@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.0.0.tgz#0948af513d2e4ce407916f8506a423d3f9cf72d8"
dependencies:
date-now "1.0.1"

debug@2.2.0, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@~2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
Expand Down Expand Up @@ -1354,10 +1336,6 @@ doctrine@1.5.0, doctrine@^1.2.2:
esutils "^2.0.2"
isarray "^1.0.0"

dom-utils@^0.4.0:
version "0.4.1"
resolved "https://registry.yarnpkg.com/dom-utils/-/dom-utils-0.4.1.tgz#22f1dbaf5fddecfc0525f2c07e92695744054f5d"

dom-walk@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
Expand Down Expand Up @@ -2452,20 +2430,13 @@ isobject@^2.0.0:
dependencies:
isarray "1.0.0"

isomorphic-fetch@2.2.0:
isomorphic-fetch@2.2.0, isomorphic-fetch@^2.1.1:
version "2.2.0"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.0.tgz#8a834c42f415535285651ff9742dde64f3ab532d"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isomorphic-fetch@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
Expand Down Expand Up @@ -3570,6 +3541,12 @@ react-dom@15.4.2, "react-dom@^15.0.0 || ^16.0.0":
loose-envify "^1.1.0"
object-assign "^4.1.0"

react-ga@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.1.2.tgz#7af206c5e8761d7176e15773fe826acdb70ac653"
dependencies:
object-assign "^4.0.1"

react-hot-loader@3.0.0-beta.6:
version "3.0.0-beta.6"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-3.0.0-beta.6.tgz#463fac0bfc8b63a8385258af20c91636abce75f4"
Expand Down Expand Up @@ -4453,18 +4430,14 @@ util@0.10.3, util@^0.10.3:
dependencies:
inherits "2.0.1"

uuid@2.0.1:
uuid@2.0.1, uuid@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.1.tgz#c2a30dedb3e535d72ccf82e343941a50ba8533ac"

uuid@3.0.1, uuid@^3.0.0, uuid@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"

uuid@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"

validate-npm-package-license@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"
Expand Down

0 comments on commit a9d2bce

Please sign in to comment.