Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy'd #2210

Merged
merged 4 commits into from
Nov 21, 2018
Merged

proxy'd #2210

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions source/js/analytics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ReactGA from 'react-ga';

export default {
initialize: function() {
var _dntStatus = navigator.doNotTrack || navigator.msDoNotTrack;
Expand Down Expand Up @@ -30,10 +28,7 @@ export default {
if (!window.ga) {
return;
}

window.ga('send', category, 'navigation', action, label);


window.ga('send', 'event', 'navigation', 'page footer cta', document.querySelectorAll('.cms h1').length > 0 ? document.querySelectorAll('.cms h1')[0].innerText + ' - footer cta' : '');
}
};
28 changes: 11 additions & 17 deletions source/js/buyers-guide/bg-main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactGA from 'react-ga';
import ReactGA from './react-ga-proxy.js';

import primaryNav from './components/primary-nav/primary-nav.js';
import CreepVote from './components/creep-vote/creep-vote.jsx';
Expand All @@ -11,14 +11,10 @@ import Filter from './components/filter/filter.jsx';
import HomepageSlider from './homepage-c-slider.js';
import ProductGA from './product-analytics.js';

import DNT from './dnt.js';

let main = {
init() {
if (DNT.allowTracking) {
ReactGA.initialize(`UA-87658599-6`);
ReactGA.pageview(window.location.pathname);
}
ReactGA.initialize(`UA-87658599-6`);
ReactGA.pageview(window.location.pathname);

this.enableCopyLinks();
this.injectReactComponents();
Expand Down Expand Up @@ -51,7 +47,7 @@ let main = {
button.classList.toggle(`open`);
help.classList.toggle(`open`);

if (help.classList.contains(`open`) && DNT.allowTracking) {
if (help.classList.contains(`open`)) {
ReactGA.event({
category: `product`,
action: `expand accordion tap`,
Expand All @@ -71,16 +67,14 @@ let main = {
element.addEventListener(`click`, (event) => {
event.preventDefault();

if (DNT.allowTracking) {
let productBox = document.querySelector(`.product-detail .h1-heading`);
let productTitle = productBox ? productBox.textContent : `unknown product`;
let productBox = document.querySelector(`.product-detail .h1-heading`);
let productTitle = productBox ? productBox.textContent : `unknown product`;

ReactGA.event({
category: `product`,
action: `copy link tap`,
label: `copy link ${productTitle}`
});
}
ReactGA.event({
category: `product`,
action: `copy link tap`,
label: `copy link ${productTitle}`
});

let textArea = document.createElement(`textarea`);

Expand Down
15 changes: 6 additions & 9 deletions source/js/buyers-guide/components/filter/filter.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactGA from 'react-ga';
import DNT from '../../dnt.js';
import ReactGA from '../../react-ga-proxy.js';

/**
* A simple class for radio-group-looking things.
Expand Down Expand Up @@ -85,13 +84,11 @@ export default class Filter extends React.Component {
this.updateWithCSSvalues(update);
this.setState(update);

if(DNT.allowTracking) {
ReactGA.event({
category: `buyersguide`,
action: `filter set`,
label: `filter on homepage`
});
}
ReactGA.event({
category: `buyersguide`,
action: `filter set`,
label: `filter on homepage`
});
}
}

Expand Down
13 changes: 4 additions & 9 deletions source/js/buyers-guide/components/social-share/social-share.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactGA from 'react-ga';
import DNT from '../../dnt.js';
import ReactGA from '../../react-ga-proxy';

const SocialShareLink = (props) => {
let classes = `social-button`;
Expand Down Expand Up @@ -35,13 +34,9 @@ const SocialShareLink = (props) => {
link = `mailto:?&body=${encodeURIComponent(shareText)}`;
}

let trackShareAction = () => {};

if (DNT.allowTracking) {
trackShareAction = () => {
ReactGA.event(shareEvent);
};
}
let trackShareAction = () => {
ReactGA.event(shareEvent);
};

return <a target="_blank" className={classes} href={link} onClick={trackShareAction}><span class="sr-only">{srLabel}</span></a>;
};
Expand Down
2 changes: 1 addition & 1 deletion source/js/buyers-guide/product-analytics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactGA from 'react-ga';
import ReactGA from './react-ga-proxy';
import DNT from './dnt.js';

function getElementGAInformation(pageTitle, productName) {
Expand Down
14 changes: 14 additions & 0 deletions source/js/buyers-guide/react-ga-proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import DNT from './dnt.js';
import ReactGA from 'react-ga';

// A no-operation object with the same API surface
// as ReactGA, for when tracking is not appreciated:
const noop = {
initialize: () => {},
pageview: () => {},
event: () => {}
};

const TrackingObject = DNT.allowTracking ? ReactGA : noop;

export default TrackingObject;