diff --git a/src/config/common.config.js b/src/config/common.config.js index c00eb7430..27bbb8338 100644 --- a/src/config/common.config.js +++ b/src/config/common.config.js @@ -49,37 +49,7 @@ define([], function () { 'polyfill', 'js/dark-mode-switch', ], function (config) { - // rca: not sure why the ganalytics is loaded here instead of inside analytics.js - // perhaps it is because it is much/little sooner this way? - - // make sure that google analytics never blocks app load - setTimeout(function () { - require(['google-analytics', 'analytics'], function (_, analytics) { - // set ganalytics debugging - //window.ga_debug = {trace: true}; - analytics( - 'create', - config.googleTrackingCode || '', - config.googleTrackingOptions, - ); - - // if we ever want to modify what experiment/variant the user - // is going to receive, it has to happen here - by modifying the - // _gaexp cookie -- but at this stage we haven't yet downloaded - // optimize AND we haven't setup any of our api calls - - // example that sets the variant 2 of the experiment - // document.cookie = '_gaexp=GAX1.1.WFD4u8V3QkaI5EcZ969yeQ.18459.2;'; - - if (config.googleOptimizeCode) { - analytics('require', config.googleOptimizeCode); - if (!config.debugExportBBB) - console.warn( - 'AB testing will be loaded, but bbb object is not exposed. Change debugExportBBB if needed.', - ); - } - }); - }, 0); + // stub here to make sure these load before the main app }); // set up handlebars helpers diff --git a/src/js/components/analytics.js b/src/js/components/analytics.js index 7489d970d..7b8629b91 100644 --- a/src/js/components/analytics.js +++ b/src/js/components/analytics.js @@ -1,4 +1,4 @@ -define(['underscore', 'jquery'], function(_, $) { +define(['underscore', 'jquery'], function (_, $) { /* * Set of targets * each has a set of hooks which coorespond to the event label passed @@ -34,8 +34,8 @@ define(['underscore', 'jquery'], function(_, $) { * @param {string} url * @param {object} data */ - var sendEvent = function(url) { - $.ajax({ url: url, type: 'GET' }); + var sendEvent = function (url) { + $.ajax({url: url, type: 'GET'}); }; /** @@ -46,12 +46,12 @@ define(['underscore', 'jquery'], function(_, $) { * @param {string} label - the event label * @param {object} data - the event data */ - var adsLogger = function(label, data) { + var adsLogger = function (label, data) { // if label or data is not present, do nothing if (_.isString(label) && _.isPlainObject(data) && _.has(data, 'target')) { - _.forEach(TARGETS, function(val) { + _.forEach(TARGETS, function (val) { var target = null; - _.forEach(val.types, function(type) { + _.forEach(val.types, function (type) { if (_.isArray(type)) { if (type[0] === data.target && _.has(type[1], 'redirectTo')) { target = type[1].redirectTo; @@ -63,7 +63,7 @@ define(['underscore', 'jquery'], function(_, $) { // send event if we find a hook and the target is in the list of types if (_.contains(val.hooks, label) && target) { - var params = _.assign({}, data, { target: target }); + var params = _.assign({}, data, {target: target}); sendEvent(data.url ? data.url : val.url(params)); } }); @@ -73,31 +73,31 @@ define(['underscore', 'jquery'], function(_, $) { var buffer = []; var gaName = window.GoogleAnalyticsObject || 'ga'; - var cleanBuffer = function() { + var cleanBuffer = function () { if (window[gaName]) { - for (var i=0; i 0) - cleanBuffer() - window[gaName].apply(this, arguments); - return true; - } - else { - console.log('Buffering GA signal', arguments); - buffer.push(arguments); - setTimeout(cleanBuffer, 1000); - return false; + + // if the action is send and the event is event, then we want to send the event to the dataLayer + if (action === 'send' && event === 'event') { + + // some events are 'interaction' or 'error', so add that to the event name + window.dataLayer.push({ + event: `${type}_${description}`, + + // if the next argument is an object, we'll use that as the data, ignore an extra arguments + value1: args[0], + value2: args[1], + value3: args[2], + }); } - }; return Analytics; diff --git a/src/js/react/Recommender/components/App.jsx.js b/src/js/react/Recommender/components/App.jsx.js index 97f10f91a..ce78a6d31 100644 --- a/src/js/react/Recommender/components/App.jsx.js +++ b/src/js/react/Recommender/components/App.jsx.js @@ -6,14 +6,14 @@ define([ '../actions', 'es6!./RecommendedList.jsx', 'es6!./SearchExamples.jsx', -], function( +], function ( React, - { Nav, NavItem }, + {Nav, NavItem}, PropTypes, - { useDispatch, useSelector }, - { setTab, emitAnalytics }, + {useDispatch, useSelector}, + {setTab, emitAnalytics}, RecommendedList, - SearchExamples + SearchExamples, ) { const selector = (state) => ({ tab: state.tab, @@ -21,16 +21,16 @@ define([ const App = () => { const dispatch = useDispatch(); - const { tab } = useSelector(selector); + const {tab} = useSelector(selector); const onSelected = (key) => { dispatch(setTab(key)); dispatch( emitAnalytics([ 'send', 'event', - 'interaction.main-page', + 'interaction', 'main-page', key === 1 ? 'recommender' : 'help', - ]) + ]), ); }; @@ -63,8 +63,8 @@ define([ Search examples -
- {tab === 1 ? : } +
+ {tab === 1 ? : }
); diff --git a/src/js/react/Recommender/components/RecommendedList.jsx.js b/src/js/react/Recommender/components/RecommendedList.jsx.js index f7af41121..2a4caf2b7 100644 --- a/src/js/react/Recommender/components/RecommendedList.jsx.js +++ b/src/js/react/Recommender/components/RecommendedList.jsx.js @@ -1,10 +1,10 @@ -define(['react', 'prop-types', 'react-redux', '../actions'], function( +define(['react', 'prop-types', 'react-redux', '../actions'], function ( React, PropTypes, - { useSelector, useDispatch }, - { getRecommendations, emitAnalytics } + {useSelector, useDispatch}, + {getRecommendations, emitAnalytics}, ) { - const Paper = ({ title, bibcode, author, totalAuthors, onClick }) => { + const Paper = ({title, bibcode, author, totalAuthors, onClick}) => { const el = React.useRef(null); React.useEffect(() => { if (el.current) { @@ -18,7 +18,7 @@ define(['react', 'prop-types', 'react-redux', '../actions'], function( }, []); return ( -
  • +
  • {title} @@ -36,7 +36,8 @@ define(['react', 'prop-types', 'react-redux', '../actions'], function( bibcode: '', author: [], totalAuthors: 0, - onClick: () => {}, + onClick: () => { + }, }; Paper.propTypes = { @@ -47,7 +48,7 @@ define(['react', 'prop-types', 'react-redux', '../actions'], function( onClick: PropTypes.func, }; - const Message = ({ children }) => ( + const Message = ({children}) => (
    { @@ -113,26 +114,26 @@ define(['react', 'prop-types', 'react-redux', '../actions'], function( emitAnalytics([ 'send', 'event', - 'interaction.no-recommendation', // category + 'interaction', 'no-recommendation', // category 'no-useful-recommendations', // action '', // label, 0, // value - ]) + ]), ); reported = true; } }); - const onPaperSelect = ({ bibcode }, index) => { + const onPaperSelect = ({bibcode}, index) => { dispatch( emitAnalytics([ 'send', 'event', - 'interaction.recommendation', // category + 'interaction', 'recommendation', // category queryParams.function, // action bibcode, // label, index, // value - ]) + ]), ); }; @@ -143,7 +144,7 @@ define(['react', 'prop-types', 'react-redux', '../actions'], function( return ( -