Skip to content

Commit

Permalink
added title to pageview / fixed duplicates (#917)
Browse files Browse the repository at this point in the history
* 👾 added title to pageview / fixed duplicates

* 👾 added pss tracking in component update
  • Loading branch information
mgiraldo authored Jul 23, 2018
1 parent 1127581 commit e9e421a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Details extends React.Component {
// Google Analytics tracking for exhibit home view event
componentDidMount() {
this.trackEvent();
Router.onRouteChangeComplete = url => this.trackEvent();
}

trackEvent() {
Expand Down
1 change: 0 additions & 1 deletion components/ItemComponents/Content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Content extends React.Component {
componentDidMount() {
this.trackItemView();
this.bindClickThroughEvent();
Router.onRouteChangeComplete = url => this.trackItemView();
}

trackItemView() {
Expand Down
9 changes: 7 additions & 2 deletions components/MainLayout/components/MinimalLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SkipToContent from "shared/SkipToContent";
import PageHeader from "../PageHeader";

import * as gtag from "lib/gtag";
import { getFullPath } from "lib";
import { getFullPath, getCurrentFullUrl } from "lib";

import { SITE_ENV } from "constants/env";

Expand All @@ -21,9 +21,14 @@ class MinimalLayout extends React.Component {

trackPageview() {
const fullPath = getFullPath();
const fullUrl = getCurrentFullUrl();

if (fullPath !== this.lastTrackedPath) {
gtag.pageview(fullPath);
gtag.pageview({
path: fullPath,
url: fullUrl,
title: this.props.pageTitle
});
this.lastTrackedPath = fullPath;
}
}
Expand Down
12 changes: 8 additions & 4 deletions components/MainLayout/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import Router from "next/router";

import Helmet from "react-helmet";

import DPLAHead from "components/DPLAHead";
import SkipToContent from "shared/SkipToContent";
import SmallScreenHeader from "./components/SmallScreenHeader";
Expand All @@ -10,22 +10,26 @@ import PageHeader from "./components/PageHeader";
import Footer from "./components/Footer";

import * as gtag from "lib/gtag";
import { getFullPath } from "lib";
import { getFullPath, getCurrentFullUrl } from "lib";

import { SITE_ENV } from "constants/env";

class MainLayout extends React.Component {
// Google Analytics tracking for MainLayout-using pages
componentDidMount() {
this.trackPageview();
Router.onRouteChangeComplete = url => this.trackPageview();
}

trackPageview() {
const fullPath = getFullPath();
const fullUrl = getCurrentFullUrl();

if (fullPath !== this.lastTrackedPath) {
gtag.pageview(fullPath);
gtag.pageview({
path: fullPath,
url: fullUrl,
title: this.props.pageTitle
});
this.lastTrackedPath = fullPath;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ class ContentAndMetadata extends React.Component {
// now collapse it
this.setState({ isOpen: false });
this.trackSourceView();
Router.onRouteChangeComplete = url => this.trackSourceView();
}

componentDidUpdate() {
this.trackSourceView();
}

componentWillReceiveProps() {
Expand Down
6 changes: 4 additions & 2 deletions lib/gtag.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { gaTrackingId } from "constants/env";

// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const pageview = url => {
export const pageview = ({ url, path, title }) => {
window.gtag("config", gaTrackingId, {
page_location: url
page_location: url,
page_path: path,
page_title: title
});
};

Expand Down
7 changes: 6 additions & 1 deletion pages/exhibitions/exhibition/section/subsection.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ class Subsection extends React.Component {

trackPageview() {
const fullPath = getFullPath();
const fullUrl = getCurrentFullUrl();

if (fullPath !== this.lastTrackedPath) {
gtag.pageview(fullPath);
gtag.pageview({
path: fullPath,
url: fullUrl,
title: this.props.section.title
});
this.lastTrackedPath = fullPath;
}
}
Expand Down

0 comments on commit e9e421a

Please sign in to comment.