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

WIP Add Tracking #119

Merged
merged 20 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
100 changes: 100 additions & 0 deletions examples/demo-app/src/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// This file sends actions on the demo app to Google analytics

import {ActionTypes} from 'kepler.gl/actions';

This comment was marked as resolved.

This comment was marked as resolved.

import {LOCATION_CHANGE} from 'react-router-redux';

const getPayload = ({payload}) => payload;

const withStoreInformation = getTracking => (payload, store) => {
const trackingFromPayload = getTracking(payload, store);
try {
const {
demo: {
keplerGl: {
map: {
visState: {datasets = {}, filters = [], layers = []}
}
}
}
} = store.getState();
const trackingFromStore = {
datasetsCount: Object.keys(datasets).length,
layersCount: layers.length,
filtersCount: filters.length
};
return {
...trackingFromStore,
...trackingFromPayload
};
} catch (err) {
/* eslint-disable */
console.warn(err);
/* eslint-enable */
return trackingFromPayload;
}
};

const trackingInformation = {
[ActionTypes.LOAD_FILES]: ({files}) =>
files.map(({size, type}) => ({size, type})),
[ActionTypes.LAYER_HOVER]: ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to track LAYER_HOVER, it gets called all the time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All actions are currently tracked - should I specifically exclude this one?

payload: {
info: {lngLat}
}
}) => lngLat,
[ActionTypes.LAYER_CONFIG_CHANGE]: ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LAYER_TYPE_CHANGE

payload: {
oldLayer: {type},
newConfig
}
}) => ({
type,
newConfig
}),
[ActionTypes.MAP_STYLE_CHANGE]: getPayload,
[ActionTypes.TOGGLE_MODAL]: getPayload,
[ActionTypes.TOGGLE_SIDE_PANEL]: getPayload,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to track this

[ActionTypes.UPDATE_MAP]: withStoreInformation(getPayload),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is map viewport change, don't track

[ActionTypes.SET_FILTER]: withStoreInformation(getPayload),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assume this is where we track the type of filter being used. payload would be not wrapped. and it would sed {idx, prop, value}

const {prop} = payload;
if (prop === 'name') {
// get the type of the filter from the next store
const visState = store.demo.keplerGl.map.visState;
const filter  = visState.filters[idx]
const newType = filter.type;

const trackingPayload = {type: newType}
}

[ActionTypes.INTERACTION_CONFIG_CHANGE]: ({config}) => config,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to track whether tooltip or brushing is enabled, we should just track that
({config}) => ({[config.id]:{config.enabled]})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

[LOCATION_CHANGE]: x => x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to track how many layers and filters we can do

[ActionTypes.ADD_LAYER]: (payload, store) => ({
  total: store.demo.keplerGl.map.visState.layers.length
}),
[ActionTypes.ADD_FILTER]: (payload, store) => ({
  total: store.demo.keplerGl.map.visState.filters.length
}),

};

const analyticsMiddleware = store => next => action => {

This comment was marked as resolved.

This comment was marked as resolved.

// eslint-disable-next-line no-undef
if (window && window.ga) {
// eslint-disable-next-line no-undef
window.ga(
'demo_app',
action.type,
trackingInformation[action.type]
? JSON.stringify(
trackingInformation[action.type](action.payload, store)
)
: undefined
);
}
return next(action);
};

export default analyticsMiddleware;
2 changes: 2 additions & 0 deletions examples/demo-app/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import window from 'global/window';
import {taskMiddleware} from 'react-palm';

import demoReducer from './reducers';
import analyticsMiddleware from './analytics';

const reducers = combineReducers({
demo: demoReducer,
routing: routerReducer
});

export const middlewares = [
analyticsMiddleware,
taskMiddleware,
thunk,
routerMiddleware(hashHistory)
Expand Down
14 changes: 13 additions & 1 deletion src/components/side-panel/panel-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
// THE SOFTWARE.

import React, {Component} from 'react';
import {connect} from 'react-redux';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import {Tooltip} from 'components/common/styled-components';
import KeplerGlLogo from 'components/common/logo';
import {CodeAlt, Save, Files, Share, Picture} from 'components/common/icons';
import PanelDropdown from 'components/side-panel/panel-dropdown';
import {ACTION_PREFIX} from 'constants/default-settings.js';

const StyledPanelHeader = styled.div.attrs({
className: 'side-side-panel__header'
Expand Down Expand Up @@ -204,7 +206,7 @@ const defaultActionItems = [
];

function PanelHeaderFactory() {
return class PanelHeader extends Component {
class PanelHeader extends Component {
static propTypes = {
logoComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
actionItems: PropTypes.arrayOf(PropTypes.any)
Expand All @@ -221,10 +223,12 @@ function PanelHeaderFactory() {

showDropdown = id => {
this.setState({dropdown: id});
this.props.trackingActionShowExportDropdown();
};

hideDropdown = () => {
this.setState({dropdown: null});
this.props.trackingActionHideExportDropdown();
};

render() {
Expand Down Expand Up @@ -273,6 +277,14 @@ function PanelHeaderFactory() {
);
}
}
return connect(undefined, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are adding tracking to kepler.gl/src directly here. We don't want to do that. Also, we should now randomly call connect in just this component. connect should only called once in the top level component. If you need, we can add a new ui-state action TOGGLE_SIDE_PANEL_HEADER and showHeaderDropdown prop in ui-state to trigger this behavior

trackingActionShowExportDropdown: () => ({
type: `${ACTION_PREFIX}TRACKING_ACTION_SHOW_EXPORT_DROPDOWN`
}),
trackingActionHideExportDropdown: () => ({
type: `${ACTION_PREFIX}TRACKING_ACTION_HIDE_EXPORT_DROPDOWN`
})
})(PanelHeader);
}

export default PanelHeaderFactory;