From 7edb11fa72e18c6287dba2dc5b61717c48778e8d Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 01:12:05 -0200 Subject: [PATCH 01/12] Describe form events to trigger --- app/modules/widgets/utils/analytics-events.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/modules/widgets/utils/analytics-events.js diff --git a/app/modules/widgets/utils/analytics-events.js b/app/modules/widgets/utils/analytics-events.js new file mode 100644 index 0000000000..da44b6372b --- /dev/null +++ b/app/modules/widgets/utils/analytics-events.js @@ -0,0 +1,25 @@ +import ReactGA from 'react-ga' + +const formIsFilled = () => { + ReactGA.event({ + category: 'Formulário', + action: 'Preenchimento Iniciado' + }) +} + +const formSavedData = () => { + ReactGA.event({ + category: 'Formulário', + action: 'Dados Salvos com Sucesso' + }) +} + +const formSocialShare = (source) => { + ReactGA.event({ + category: 'Formulário', + action: 'Social', + label: source + }) +} + +export default { formIsFilled, formSavedData, formSocialShare } From 326f0f0085b324e78c038c6b4bffce4c8342817b Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 01:30:39 -0200 Subject: [PATCH 02/12] describe donation events --- app/modules/widgets/utils/analytics-events.js | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/app/modules/widgets/utils/analytics-events.js b/app/modules/widgets/utils/analytics-events.js index da44b6372b..de230558a0 100644 --- a/app/modules/widgets/utils/analytics-events.js +++ b/app/modules/widgets/utils/analytics-events.js @@ -1,25 +1,37 @@ import ReactGA from 'react-ga' -const formIsFilled = () => { - ReactGA.event({ - category: 'Formulário', - action: 'Preenchimento Iniciado' - }) -} +const FORM_FILLED = { category: 'Formulário', action: 'Preenchimento Iniciado' } +const FORM_SAVED = { category: 'Formulário', action: 'Dados Salvos com Sucesso' } +const FORM_SHARED = { category: 'Formulário', action: 'Social' } + +const DONATION_STARTED = { category: 'Doação', action: '' } +const DONATION_FINISHED = { category: 'Doação', action: '' } +const DONATION_SHARED = { category: 'Doação', action: '' } -const formSavedData = () => { - ReactGA.event({ - category: 'Formulário', - action: 'Dados Salvos com Sucesso' - }) +const sendEvent = (event) => { + ReactGA.event(event) } +const formIsFilled = () => { sendEvent(FORM_FILLED) } +const formSavedData = () => { sendEvent(FORM_SAVED) } const formSocialShare = (source) => { - ReactGA.event({ - category: 'Formulário', - action: 'Social', - label: source - }) + sendEvent({...FORM_SHARED, label: source}) +} + +const donationSetValue = () => { sendEvent(DONATION_STARTED) } +const donationFinishRequest = (value) => { + sendEvent({...DONATION_FINISHED, label: value}) } -export default { formIsFilled, formSavedData, formSocialShare } +const donationSocialShare = (source) => { + sendEvent({...DONATION_SHARED, label: source}) +} + +export default { + formIsFilled, + formSavedData, + formSocialShare, + donationSetValue, + donationFinishRequest, + donationSocialShare +} From 48263538dc106f43930d4945719fef06868d7884 Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 01:43:01 -0200 Subject: [PATCH 03/12] Describe pressure events --- app/modules/widgets/utils/analytics-events.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/modules/widgets/utils/analytics-events.js b/app/modules/widgets/utils/analytics-events.js index de230558a0..46ef9727b7 100644 --- a/app/modules/widgets/utils/analytics-events.js +++ b/app/modules/widgets/utils/analytics-events.js @@ -4,9 +4,13 @@ const FORM_FILLED = { category: 'Formulário', action: 'Preenchimento Iniciado' const FORM_SAVED = { category: 'Formulário', action: 'Dados Salvos com Sucesso' } const FORM_SHARED = { category: 'Formulário', action: 'Social' } -const DONATION_STARTED = { category: 'Doação', action: '' } -const DONATION_FINISHED = { category: 'Doação', action: '' } -const DONATION_SHARED = { category: 'Doação', action: '' } +const DONATION_STARTED = { category: 'Doação', action: 'Escolheu Valor' } +const DONATION_FINISHED = { category: 'Doação', action: 'Servidor Recebeu Dados' } +const DONATION_SHARED = { category: 'Doação', action: 'Social' } + +const PRESSURE_FILLED = { category: 'Pressão', action: 'Preenchimento Iniciado' } +const PRESSURE_SAVED = { category: 'Pressão', action: 'Dados Salvos com Sucesso' } +const PRESSURE_SHARED = { category: 'Pressão', action: 'Social' } const sendEvent = (event) => { ReactGA.event(event) @@ -27,11 +31,20 @@ const donationSocialShare = (source) => { sendEvent({...DONATION_SHARED, label: source}) } +const pressureIsFilled = () => { sendEvent(PRESSURE_FILLED) } +const pressureSavedData = () => { sendEvent(PRESSURE_SAVED) } +const pressureSocialShare = (source) => { + sendEvent({...PRESSURE_SHARED, label: source}) +} + export default { formIsFilled, formSavedData, formSocialShare, donationSetValue, donationFinishRequest, - donationSocialShare + donationSocialShare, + pressureIsFilled, + pressureSavedData, + pressureSocialShare } From fea88c18ce205102a5f14043e1f9fc5d2b98c0c3 Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 02:18:01 -0200 Subject: [PATCH 04/12] add test to send event to google analytics --- app/modules/widgets/utils/analytics-events.js | 68 +++++++++++-------- .../widgets/utils/analytics-events.spec.js | 31 +++++++++ 2 files changed, 69 insertions(+), 30 deletions(-) create mode 100644 app/modules/widgets/utils/analytics-events.spec.js diff --git a/app/modules/widgets/utils/analytics-events.js b/app/modules/widgets/utils/analytics-events.js index 46ef9727b7..8263709014 100644 --- a/app/modules/widgets/utils/analytics-events.js +++ b/app/modules/widgets/utils/analytics-events.js @@ -12,39 +12,47 @@ const PRESSURE_FILLED = { category: 'Pressão', action: 'Preenchimento Iniciado' const PRESSURE_SAVED = { category: 'Pressão', action: 'Dados Salvos com Sucesso' } const PRESSURE_SHARED = { category: 'Pressão', action: 'Social' } -const sendEvent = (event) => { - ReactGA.event(event) -} +class AnalyticsEvents { -const formIsFilled = () => { sendEvent(FORM_FILLED) } -const formSavedData = () => { sendEvent(FORM_SAVED) } -const formSocialShare = (source) => { - sendEvent({...FORM_SHARED, label: source}) -} + static sendEvent (event) { + return ReactGA.event(event) + } -const donationSetValue = () => { sendEvent(DONATION_STARTED) } -const donationFinishRequest = (value) => { - sendEvent({...DONATION_FINISHED, label: value}) -} + static formIsFilled () { + return this.sendEvent(FORM_FILLED) + } -const donationSocialShare = (source) => { - sendEvent({...DONATION_SHARED, label: source}) -} + static formSavedData () { + return this.sendEvent(FORM_SAVED) + } -const pressureIsFilled = () => { sendEvent(PRESSURE_FILLED) } -const pressureSavedData = () => { sendEvent(PRESSURE_SAVED) } -const pressureSocialShare = (source) => { - sendEvent({...PRESSURE_SHARED, label: source}) -} + static formSocialShare (source) { + return this.sendEvent({...FORM_SHARED, label: source}) + } + + static donationSetValue () { + return this.sendEvent(DONATION_STARTED) + } -export default { - formIsFilled, - formSavedData, - formSocialShare, - donationSetValue, - donationFinishRequest, - donationSocialShare, - pressureIsFilled, - pressureSavedData, - pressureSocialShare + static donationFinishRequest (value) { + return this.sendEvent({...DONATION_FINISHED, label: value}) + } + + static donationSocialShare (source) { + return this.sendEvent({...DONATION_SHARED, label: source}) + } + + static pressureIsFilled () { + return this.sendEvent(PRESSURE_FILLED) + } + + static pressureSavedData () { + return this.sendEvent(PRESSURE_SAVED) + } + + static pressureSocialShare (source) { + return this.sendEvent({...PRESSURE_SHARED, label: source}) + } } + +export default AnalyticsEvents diff --git a/app/modules/widgets/utils/analytics-events.spec.js b/app/modules/widgets/utils/analytics-events.spec.js new file mode 100644 index 0000000000..0d1206a967 --- /dev/null +++ b/app/modules/widgets/utils/analytics-events.spec.js @@ -0,0 +1,31 @@ +import sinon from 'sinon' +import { expect } from 'chai' + +import AnalyticsEvents from '../../../modules/widgets/utils/analytics-events' + +describe.skip('app/modules/widgets/utils/analytics-events', () => { + let sandbox + + before(() => { + sandbox = sinon.sandbox.create() + sandbox.spy(AnalyticsEvents, 'sendEvent') + }) + + context('#formIsFilled', () => { + console.log(AnalyticsEvents) + it('should return true when form is filled', () => { + expect(AnalyticsEvents.formIsFilled()).to.be.true + }) + + expect(AnalyticsEvents.sendEvent).to.be.called + }) + + // formSavedData, + // formSocialShare, + // donationSetValue, + // donationFinishRequest, + // donationSocialShare, + // pressureIsFilled, + // pressureSavedData, + // pressureSocialShare +}) From dab4eb7f16542deb796432e093d25e3154b1867a Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 03:19:28 -0200 Subject: [PATCH 05/12] Move Social Media to external category --- app/modules/widgets/utils/analytics-events.js | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/app/modules/widgets/utils/analytics-events.js b/app/modules/widgets/utils/analytics-events.js index 8263709014..81a97eff86 100644 --- a/app/modules/widgets/utils/analytics-events.js +++ b/app/modules/widgets/utils/analytics-events.js @@ -1,57 +1,51 @@ import ReactGA from 'react-ga' -const FORM_FILLED = { category: 'Formulário', action: 'Preenchimento Iniciado' } -const FORM_SAVED = { category: 'Formulário', action: 'Dados Salvos com Sucesso' } -const FORM_SHARED = { category: 'Formulário', action: 'Social' } - -const DONATION_STARTED = { category: 'Doação', action: 'Escolheu Valor' } -const DONATION_FINISHED = { category: 'Doação', action: 'Servidor Recebeu Dados' } -const DONATION_SHARED = { category: 'Doação', action: 'Social' } +class AnalyticsEvents { + constructor () { + this.FORM_FILLED = { category: 'Formulário', action: 'Preenchimento Iniciado' } + this.FORM_SAVED = { category: 'Formulário', action: 'Dados Salvos com Sucesso' } -const PRESSURE_FILLED = { category: 'Pressão', action: 'Preenchimento Iniciado' } -const PRESSURE_SAVED = { category: 'Pressão', action: 'Dados Salvos com Sucesso' } -const PRESSURE_SHARED = { category: 'Pressão', action: 'Social' } + this.DONATION_STARTED = { category: 'Doação', action: 'Escolheu Valor' } + this.DONATION_FINISHED = { category: 'Doação', action: 'Servidor Recebeu Dados' } -class AnalyticsEvents { + this.PRESSURE_FILLED = { category: 'Pressão', action: 'Preenchimento Iniciado' } + this.PRESSURE_SAVED = { category: 'Pressão', action: 'Dados Salvos com Sucesso' } + this.SOCIAL_SHARED = { category: 'Redes Sociais', action: 'Compartilhou no ' } + } static sendEvent (event) { return ReactGA.event(event) } static formIsFilled () { - return this.sendEvent(FORM_FILLED) + return this.sendEvent(this.FORM_FILLED) } static formSavedData () { - return this.sendEvent(FORM_SAVED) - } - - static formSocialShare (source) { - return this.sendEvent({...FORM_SHARED, label: source}) + return this.sendEvent(this.FORM_SAVED) } static donationSetValue () { - return this.sendEvent(DONATION_STARTED) + return this.sendEvent(this.DONATION_STARTED) } static donationFinishRequest (value) { - return this.sendEvent({...DONATION_FINISHED, label: value}) - } - - static donationSocialShare (source) { - return this.sendEvent({...DONATION_SHARED, label: source}) + return this.sendEvent({...this.DONATION_FINISHED, label: value}) } static pressureIsFilled () { - return this.sendEvent(PRESSURE_FILLED) + return this.sendEvent(this.PRESSURE_FILLED) } static pressureSavedData () { - return this.sendEvent(PRESSURE_SAVED) + return this.sendEvent(this.PRESSURE_SAVED) } - static pressureSocialShare (source) { - return this.sendEvent({...PRESSURE_SHARED, label: source}) + static socialShared (source, text) { + let evt = { ...this.SOCIAL_SHARED } + evt.action = evt.action + source + evt.label = text + return this.sendEvent(evt) } } From 83f662ceb0be304a05417d45c88cee17454f3dce Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 03:21:43 -0200 Subject: [PATCH 06/12] Add events to Facebook and Twttter share button --- app/scripts/components/FacebookShareButton.jsx | 8 ++++++-- app/scripts/components/TwitterShareButton.jsx | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/scripts/components/FacebookShareButton.jsx b/app/scripts/components/FacebookShareButton.jsx index 465b9d12d8..66a11a606b 100644 --- a/app/scripts/components/FacebookShareButton.jsx +++ b/app/scripts/components/FacebookShareButton.jsx @@ -1,12 +1,16 @@ import React, { PropTypes } from 'react' +import AnalyticsEvents from '../../app/modules/widgets/utils/analytics-events' export default class FacebookShareButton extends React.Component { static propTypes = { - href: PropTypes.string.isRequired + href: PropTypes.string.isRequired, + text: PropTypes.string.isRequired } handleClick() { - const { href } = this.props + const { text, href } = this.props + + AnalyticsEvents.socialShared('Facebook', text) window.open( `http://www.facebook.com/sharer.php?u=${href}`, diff --git a/app/scripts/components/TwitterShareButton.jsx b/app/scripts/components/TwitterShareButton.jsx index b1ab8f9fab..f260f54bfc 100644 --- a/app/scripts/components/TwitterShareButton.jsx +++ b/app/scripts/components/TwitterShareButton.jsx @@ -1,4 +1,5 @@ import React, { PropTypes } from 'react' +import AnalyticsEvents from '../../app/modules/widgets/utils/analytics-events' export default class TwitterShareButton extends React.Component { static propTypes = { @@ -13,6 +14,9 @@ export default class TwitterShareButton extends React.Component { // hashtags: comma-separated list without # const { href, text } = this.props + + AnalyticsEvents.socialShared('Twitter', text) + window.open( `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${href}`, 'Compartilhar no Twitter', From 252cd7e8866bfdc3c63c3d59c7b0bca82df856fe Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 03:22:17 -0200 Subject: [PATCH 07/12] Add events to donation widget --- .../action-creators/async-donation-transaction-create.js | 4 ++++ .../widgets/__plugins__/donation/components/__donation__.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js b/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js index 97125ac0c1..95f1b6bee3 100644 --- a/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js +++ b/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js @@ -1,5 +1,6 @@ import { createAction } from './create-action' import * as t from '../action-types' +import { AnalyticsEvents } from '../../../../../modules/widgets/utils/analytics-events' const asyncDonationTransactionCreate = params => (dispatch, getState, axios) => { const endpoint = `/mobilizations/${params.mobilization_id}/donations` @@ -9,6 +10,9 @@ const asyncDonationTransactionCreate = params => (dispatch, getState, axios) => return axios.post(endpoint, body) .then(response => { dispatch({ type: t.ASYNC_DONATION_TRANSACTION_CREATE_SUCCESS }) + + AnalyticsEvents.donationFinishRequest() + return Promise.resolve() }) .catch(failure => { diff --git a/app/modules/widgets/__plugins__/donation/components/__donation__.js b/app/modules/widgets/__plugins__/donation/components/__donation__.js index c53701b86a..b475281e69 100644 --- a/app/modules/widgets/__plugins__/donation/components/__donation__.js +++ b/app/modules/widgets/__plugins__/donation/components/__donation__.js @@ -9,6 +9,8 @@ import * as Paths from '../../../../../scripts/Paths' // Parent module dependencies import { WidgetOverlay, FinishMessageCustom } from '../../../../../modules/widgets/components' +import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' + // Current module dependencies import { DonationTellAFriend } from '../components' import './__donation__.scss' @@ -93,6 +95,9 @@ class Donation extends React.Component { uiColor: main_color, paymentButtonText: widget.settings.button_text } + + AnalyticsEvents.donationSetValue() + checkout.open(params) } From 7e94716531400bb0bdf1f101afa1c580d28ac898 Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 03:22:41 -0200 Subject: [PATCH 08/12] Add events to form entries widget --- .../form/action-creators/async-form-entry-create.js | 4 ++++ .../widgets/__plugins__/form/components/__form__.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js b/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js index 5bfe33bb5d..acd8b13ab6 100644 --- a/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js +++ b/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js @@ -1,6 +1,7 @@ // Parent module dependencies import * as WidgetSelectors from '../../../../../modules/widgets/selectors' import { actions as WidgetActions } from '../../../../../modules/widgets' +import { AnalyticsEvents } from '../../../../../modules/widgets/utils/analytics-events' // Current module dependencies import * as t from '../action-types' @@ -19,6 +20,9 @@ const asyncFormEntryCreate = ({ mobilization, formEntry }) => (dispatch, getStat dispatch(WidgetActions.setWidgetList( updateWidgetList(state, response.data) )) + + AnalyticsEvents.formSavedData() + return Promise.resolve() }) .catch(failure => { diff --git a/app/modules/widgets/__plugins__/form/components/__form__.js b/app/modules/widgets/__plugins__/form/components/__form__.js index 49df65333b..72a746640c 100644 --- a/app/modules/widgets/__plugins__/form/components/__form__.js +++ b/app/modules/widgets/__plugins__/form/components/__form__.js @@ -12,6 +12,7 @@ import { isValidEmail } from '../../../../../util/validation-helper' // Parent module dependencies import { WidgetOverlay, FinishMessageCustom } from '../../../../../modules/widgets/components' +import { AnalyticsEvents } from '../../../../../modules/widgets/utils/analytics-events' // Current module dependencies import { Button, Input, FormTellAFriend } from '../components' @@ -99,6 +100,8 @@ class Form extends React.Component { ) } + + renderFields() { const fields = this.fields() return fields.map((field, index) => { @@ -229,6 +232,7 @@ class Form extends React.Component { onClick={::this.handleOverlayOnClick} text="Clique para configurar o formulário de inscrição" > +
e.stopPropagation()} />
{success ? this.renderShareButtons() : this.renderForm()} {this.renderCount()} @@ -238,6 +242,10 @@ class Form extends React.Component { } } +document.addEventListener('keydown', () => { + AnalyticsEvents.formIsFilled() +}) + Form.propTypes = { mobilization: PropTypes.object.isRequired, widget: PropTypes.shape({ From d94809079fc6455e6bb48af30a566f19b7ec9759 Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 03:23:02 -0200 Subject: [PATCH 09/12] Add events to pressure widget --- .../pressure/action-creators/async-fill-widget.js | 4 ++++ .../widgets/__plugins__/pressure/components/__pressure__.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/app/modules/widgets/__plugins__/pressure/action-creators/async-fill-widget.js b/app/modules/widgets/__plugins__/pressure/action-creators/async-fill-widget.js index 27f625c3c0..f7cfa97562 100644 --- a/app/modules/widgets/__plugins__/pressure/action-creators/async-fill-widget.js +++ b/app/modules/widgets/__plugins__/pressure/action-creators/async-fill-widget.js @@ -2,6 +2,7 @@ import * as t from '../action-types' import { createAction } from './create-action' import * as WidgetSelectors from '../../../../../modules/widgets/selectors' import { actions as WidgetsActions } from '../../../../../modules/widgets' +import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' // // The name of this action needs to be refactored to make more sense. @@ -22,6 +23,9 @@ const asyncFillWidget = ({ payload: fill, widget }) => (dispatch, getState, axio dispatch(WidgetsActions.setWidgetList( updateWidgetList(state, response.data) )) + + AnalyticsEvents.pressureSavedData() + return Promise.resolve() }) .catch(failure => { diff --git a/app/modules/widgets/__plugins__/pressure/components/__pressure__.js b/app/modules/widgets/__plugins__/pressure/components/__pressure__.js index cb345aa6d2..b4b8dcae04 100644 --- a/app/modules/widgets/__plugins__/pressure/components/__pressure__.js +++ b/app/modules/widgets/__plugins__/pressure/components/__pressure__.js @@ -8,6 +8,7 @@ import Editor from '../../../../../scripts/RebooEditor' // Parent module dependencies import { WidgetOverlay, FinishMessageCustom } from '../../../../../modules/widgets/components' +import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' // Current module dependencies import { @@ -111,6 +112,7 @@ export class Pressure extends Component { ) ) : (
+
e.stopPropagation()} />

{ + AnalyticsEvents.pressureIsFilled() +}) + Pressure.propTypes = { editable: PropTypes.bool, mobilization: PropTypes.object.isRequired, From 24b83c6bfe384a2e6007d940805a77bf03637620 Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 04:11:56 -0200 Subject: [PATCH 10/12] fix wrong imports --- .../action-creators/async-donation-transaction-create.js | 2 +- .../widgets/__plugins__/pressure/components/__pressure__.js | 5 ----- app/scripts/components/FacebookShareButton.jsx | 2 +- app/scripts/components/TwitterShareButton.jsx | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js b/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js index 95f1b6bee3..5114b13a53 100644 --- a/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js +++ b/app/modules/widgets/__plugins__/donation/action-creators/async-donation-transaction-create.js @@ -1,6 +1,6 @@ import { createAction } from './create-action' import * as t from '../action-types' -import { AnalyticsEvents } from '../../../../../modules/widgets/utils/analytics-events' +import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' const asyncDonationTransactionCreate = params => (dispatch, getState, axios) => { const endpoint = `/mobilizations/${params.mobilization_id}/donations` diff --git a/app/modules/widgets/__plugins__/pressure/components/__pressure__.js b/app/modules/widgets/__plugins__/pressure/components/__pressure__.js index b4b8dcae04..b8507afbef 100644 --- a/app/modules/widgets/__plugins__/pressure/components/__pressure__.js +++ b/app/modules/widgets/__plugins__/pressure/components/__pressure__.js @@ -8,7 +8,6 @@ import Editor from '../../../../../scripts/RebooEditor' // Parent module dependencies import { WidgetOverlay, FinishMessageCustom } from '../../../../../modules/widgets/components' -import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' // Current module dependencies import { @@ -143,10 +142,6 @@ export class Pressure extends Component { } } -document.addEventListener('keydown', () => { - AnalyticsEvents.pressureIsFilled() -}) - Pressure.propTypes = { editable: PropTypes.bool, mobilization: PropTypes.object.isRequired, diff --git a/app/scripts/components/FacebookShareButton.jsx b/app/scripts/components/FacebookShareButton.jsx index 66a11a606b..f6d0a1381d 100644 --- a/app/scripts/components/FacebookShareButton.jsx +++ b/app/scripts/components/FacebookShareButton.jsx @@ -1,5 +1,5 @@ import React, { PropTypes } from 'react' -import AnalyticsEvents from '../../app/modules/widgets/utils/analytics-events' +import AnalyticsEvents from '../../modules/widgets/utils/analytics-events' export default class FacebookShareButton extends React.Component { static propTypes = { diff --git a/app/scripts/components/TwitterShareButton.jsx b/app/scripts/components/TwitterShareButton.jsx index f260f54bfc..16b10d8e04 100644 --- a/app/scripts/components/TwitterShareButton.jsx +++ b/app/scripts/components/TwitterShareButton.jsx @@ -1,5 +1,5 @@ import React, { PropTypes } from 'react' -import AnalyticsEvents from '../../app/modules/widgets/utils/analytics-events' +import AnalyticsEvents from '../../modules/widgets/utils/analytics-events' export default class TwitterShareButton extends React.Component { static propTypes = { From 94302467545601223e9a51da6e74d11b1c931667 Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 04:12:36 -0200 Subject: [PATCH 11/12] Remove static from class --- app/modules/widgets/utils/analytics-events.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/modules/widgets/utils/analytics-events.js b/app/modules/widgets/utils/analytics-events.js index 81a97eff86..f3dcdc2163 100644 --- a/app/modules/widgets/utils/analytics-events.js +++ b/app/modules/widgets/utils/analytics-events.js @@ -1,6 +1,6 @@ import ReactGA from 'react-ga' -class AnalyticsEvents { +export default class AnalyticsEvents { constructor () { this.FORM_FILLED = { category: 'Formulário', action: 'Preenchimento Iniciado' } this.FORM_SAVED = { category: 'Formulário', action: 'Dados Salvos com Sucesso' } @@ -13,40 +13,38 @@ class AnalyticsEvents { this.SOCIAL_SHARED = { category: 'Redes Sociais', action: 'Compartilhou no ' } } - static sendEvent (event) { + sendEvent (event) { return ReactGA.event(event) } - static formIsFilled () { + formIsFilled () { return this.sendEvent(this.FORM_FILLED) } - static formSavedData () { + formSavedData () { return this.sendEvent(this.FORM_SAVED) } - static donationSetValue () { + donationSetValue () { return this.sendEvent(this.DONATION_STARTED) } - static donationFinishRequest (value) { + donationFinishRequest (value) { return this.sendEvent({...this.DONATION_FINISHED, label: value}) } - static pressureIsFilled () { + pressureIsFilled () { return this.sendEvent(this.PRESSURE_FILLED) } - static pressureSavedData () { + pressureSavedData () { return this.sendEvent(this.PRESSURE_SAVED) } - static socialShared (source, text) { + socialShared (source, text) { let evt = { ...this.SOCIAL_SHARED } evt.action = evt.action + source evt.label = text return this.sendEvent(evt) } } - -export default AnalyticsEvents From 4f70cb70d4ef3206456c0e4343e1e4e84d3d3a9f Mon Sep 17 00:00:00 2001 From: Lucas Pirola Date: Mon, 30 Jan 2017 04:13:39 -0200 Subject: [PATCH 12/12] Improve trigger to send event to GA when start fill form --- .../form/action-creators/async-form-entry-create.js | 2 +- .../widgets/__plugins__/form/components/__form__.js | 9 ++------- app/modules/widgets/__plugins__/form/components/input.js | 3 ++- .../__plugins__/pressure/components/pressure-form.js | 3 +++ app/modules/widgets/utils/analytics-events.js | 4 +++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js b/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js index acd8b13ab6..0ba179ee93 100644 --- a/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js +++ b/app/modules/widgets/__plugins__/form/action-creators/async-form-entry-create.js @@ -1,7 +1,7 @@ // Parent module dependencies import * as WidgetSelectors from '../../../../../modules/widgets/selectors' import { actions as WidgetActions } from '../../../../../modules/widgets' -import { AnalyticsEvents } from '../../../../../modules/widgets/utils/analytics-events' +import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' // Current module dependencies import * as t from '../action-types' diff --git a/app/modules/widgets/__plugins__/form/components/__form__.js b/app/modules/widgets/__plugins__/form/components/__form__.js index 72a746640c..a7284792ee 100644 --- a/app/modules/widgets/__plugins__/form/components/__form__.js +++ b/app/modules/widgets/__plugins__/form/components/__form__.js @@ -12,7 +12,7 @@ import { isValidEmail } from '../../../../../util/validation-helper' // Parent module dependencies import { WidgetOverlay, FinishMessageCustom } from '../../../../../modules/widgets/components' -import { AnalyticsEvents } from '../../../../../modules/widgets/utils/analytics-events' +import AnalyticsEvents from '../../../../../modules/widgets/utils/analytics-events' // Current module dependencies import { Button, Input, FormTellAFriend } from '../components' @@ -100,8 +100,6 @@ class Form extends React.Component { ) } - - renderFields() { const fields = this.fields() return fields.map((field, index) => { @@ -110,6 +108,7 @@ class Form extends React.Component { {...this.props} key={field.uid} uid={field.uid} + onBlur={(Number(index) === 0 ? AnalyticsEvents.formIsFilled.bind(AnalyticsEvents) : ()=>{})} canMoveUp={index !== 0} canMoveDown={index !== fields.length - 1} initializeEditing={this.props.hasNewField && index === fields.length - 1} @@ -242,10 +241,6 @@ class Form extends React.Component { } } -document.addEventListener('keydown', () => { - AnalyticsEvents.formIsFilled() -}) - Form.propTypes = { mobilization: PropTypes.object.isRequired, widget: PropTypes.shape({ diff --git a/app/modules/widgets/__plugins__/form/components/input.js b/app/modules/widgets/__plugins__/form/components/input.js index 15078a7be0..72147470f2 100644 --- a/app/modules/widgets/__plugins__/form/components/input.js +++ b/app/modules/widgets/__plugins__/form/components/input.js @@ -54,7 +54,7 @@ class Input extends Component { } renderFieldKind() { - const { field, uid, editable, configurable } = this.props + const { field, uid, editable, configurable, onBlur } = this.props if (field.kind === 'dropdown') { return (