Skip to content

Commit

Permalink
Merge pull request #1455 from alisman/fixGA
Browse files Browse the repository at this point in the history
Fix google analytics. 3rd party analytics library was interfering wit…
  • Loading branch information
alisman authored Sep 14, 2018
2 parents 631e56a + 369231a commit 3cbf4d8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 81 deletions.
7 changes: 4 additions & 3 deletions end-to-end-tests/specs/home.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/appBootstrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { getHost } from './shared/api/urls';
import { validateParametersPatientView } from './shared/lib/validateParameters';
import AppConfig from "appConfig";
import browser from 'bowser';
import './shared/lib/tracking';

import 'script-loader!raven-js/dist/raven.js';
import {correctPatientUrl} from "shared/lib/urlCorrection";
import {activateAnalytics} from "shared/lib/tracking";


if (localStorage.localdev === 'true' || localStorage.localdist === 'true') {
Expand Down Expand Up @@ -174,6 +175,8 @@ window.routingStore = routingStore;

let render = () => {

activateAnalytics();

const rootNode = document.getElementById("reactRoot");

ReactDOM.render(
Expand Down
6 changes: 0 additions & 6 deletions src/pages/resultsView/ResultsViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import ResultsViewOncoprint from "shared/components/oncoprint/ResultsViewOncopri
import QuerySummary from "./querySummary/QuerySummary";
import {QueryStore} from "../../shared/components/query/QueryStore";
import Loader from "../../shared/components/loadingIndicator/LoadingIndicator";
import {getGAInstance} from "../../shared/lib/tracking";
import ExpressionWrapper from "./expression/ExpressionWrapper";
import CoExpressionTabContainer from "./coExpression/CoExpressionTabContainer";
import EnrichmentsTab from 'pages/resultsView/enrichments/EnrichmentsTab';
Expand Down Expand Up @@ -170,11 +169,6 @@ export default class ResultsViewPage extends React.Component<IResultsViewPagePro
$('a#data-download-result-tab').parent().hide();
}

if (win.cancerStudyIdList !== 'null') {
getGAInstance().event('results view', 'show', { eventLabel: win.cancerStudyIdList });
} else if (_.includes(['all','null'],win.cancerStudyId) === false) {
getGAInstance().event('results view', 'show', { eventLabel: win.cancerStudyId });
}
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ let getBlankPage = function(){
return <div />
}

console.log(getBasePath());

export const makeRoutes = (routing) => {
return (<Route path="/" component={Container}>
<Route path="/home" getComponent={lazyLoadComponent(HomePage)}/>
Expand Down
95 changes: 26 additions & 69 deletions src/shared/lib/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import analytics from 'universal-ga';
import $ from 'jquery';
import * as _ from 'lodash';
import mixpanel from 'mixpanel-browser';
import AppConfig from "appConfig";

Expand All @@ -9,70 +7,10 @@ interface trackingCodes {
mixpanel?:string;
};

export function getGAInstance(){
return analytics.name('newGA');
}

const win = (window as any);

function setCustomTrackingEvents(){

// tabs on result page

$('#tabs').on('click','.ui-tabs-nav a', function(){
getGAInstance().screenview($(this).text() + ' tab');
getGAInstance().event('results tab', 'show', { eventLabel: $(this).text() });
const studies = _.map(win.resultsViewPageStore.studies.result,'studyId').join(',');
mixpanel.track(`results tab clicked (${$(this).text()})`,{ tab:$(this).text() ,studyIds:studies });
});

$("#pancancer_study_summary").on('click','.pillTabs a', (e)=>{
const text = $(e.currentTarget).text();
const studies = _.map(win.resultsViewPageStore.studies.result,'studyId').join(',');
mixpanel.track(`cancer type summary gene tab (${text})`,{ tab:text, studyIds:studies });
});


if ($(".studyContainer").length > 0) {

const matches = window.location.search.match(/id=([a-z_]*)/);
const studyName = (matches && matches[1]) ? matches[1] : "";

let interactionCount = 0;

$(".studyContainer").on("click",".dc-chart",(e)=>{

getGAInstance().event('study view filter', 'click', {
eventLabel: e.currentTarget.id,
dimension1: studyName,
metric1:interactionCount
});
interactionCount++;
});

$("body").on("click","div[id^='qtip-chart-']",(e)=>{
getGAInstance().event('study view filter', 'click', {
eventLabel: e.currentTarget.id,
dimension1: studyName,
metric1: interactionCount
});
interactionCount++;
});

$(".studyContainer").on("click",
"#iviz-header-left-patient-select, .share-virtual-study, #iviz-header-left-patient-select, #iviz-header-left-case-download, #iviz-header-left-1, #custom-case-input-button, #iviz_add_chart_chosen",
(e)=>{
var name = e.currentTarget.id || e.currentTarget.className;
getGAInstance().event('study view button', 'click', {
eventLabel: name,
dimension1: studyName
});
}
);


}


}

Expand Down Expand Up @@ -116,19 +54,38 @@ const conditions = [

];


let trackingEnabled = false;

const tracking = {

trackerName:'newGA',

trackPageView(){
if (win.ga && trackingEnabled)
win.ga(`${this.trackerName}.send`, 'pageview');
},

createTracker(code:string){
if (win.ga && trackingEnabled)
win.ga('create', code, 'auto', this.trackerName);
},

};

export default tracking;


/*
* for simplicity all tracking code fires on all instances of portal
* but actual calls to google api are only made for given hosts
*/
function activateAnalytics(){
export function activateAnalytics(){

let trackingCodes: trackingCodes | undefined;

conditions.forEach((config:any)=>{ trackingCodes = trackingCodes || ((config.condition()) ? config.trackingCodes() : undefined) });

if (trackingCodes && !localStorage.e2etest) {
if (trackingCodes && !window.navigator.webdriver) {

trackingEnabled = true;
const debugTracking = localStorage.debugTracking;
Expand All @@ -144,9 +101,8 @@ function activateAnalytics(){
mixpanel.identify(userId);
mixpanel.people.set_once('$first_name', userId);

// google analytics
analytics.initialize(trackingCodes.ga,{ debug:!!debugTracking });
analytics.create(trackingCodes.ga, { name:'newGA', debug:!!debugTracking });
tracking.createTracker(trackingCodes.ga!);
tracking.trackPageView();

$(document).ready(function(){
setCustomTrackingEvents();
Expand All @@ -156,4 +112,5 @@ function activateAnalytics(){

}

activateAnalytics();


0 comments on commit 3cbf4d8

Please sign in to comment.