Skip to content

Commit

Permalink
feat(Signup): set up mat. experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Oct 9, 2019
1 parent 4486096 commit f19a71c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const CUSTOM_VARIABLES = {
//
export const AB_TESTS = {
PIT_SIDE_NAV_TEST3: 'PitSidenavTest3',
MIN_MAX_EXCHANGE: 'MinMaxExchange'
WALLET_PIT_SIGNUP: 'WalletPitSignup'
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { AB_TESTS } from './model'

const INITIAL_STATE = {
ab_tests: {
[AB_TESTS.PIT_SIDE_NAV_TEST3]: Remote.NotAsked
[AB_TESTS.PIT_SIDE_NAV_TEST3]: Remote.NotAsked,
[AB_TESTS.WALLET_PIT_SIGNUP]: Remote.NotAsked
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { call, delay, put, select, take } from 'redux-saga/effects'
import { add, equals, map, not, propOr, reduce, toLower } from 'ramda'
import { add, equals, map, not, propOr, reduce } from 'ramda'
import Bitcoin from 'bitcoinjs-lib'
import BIP39 from 'bip39'

Expand Down Expand Up @@ -141,7 +141,7 @@ export default ({ api }) => {
const { event } = action.payload
yield call(postMessage, {
method: 'trackEvent',
messageData: map(toLower, event)
messageData: event
})
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'logEvent', e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const TYPE_WHITELIST = [
'SHOW_MODAL'
]

const _paq = window._paq || []

const matomoMiddleware = () => store => next => action => {
const eventCategory = prop('type', action)
const nextAction =
Expand All @@ -39,7 +37,14 @@ const matomoMiddleware = () => store => next => action => {
const logEvent = contains(action.type, TYPE_WHITELIST)

if (logEvent) {
_paq.push(['trackEvent', eventCategory, eventAction, eventName])
const frame = document.getElementById('matomo-iframe')
frame.contentWindow.postMessage(
{
method: 'trackEvent',
messageData: [eventCategory, eventAction, eventName]
},
'*'
)
}

return next(action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import styled from 'styled-components'

import { actions, selectors } from 'data'
import { actions, model, selectors } from 'data'

const { AB_TESTS } = model.analytics

const Iframe = styled.iframe`
position: absolute;
Expand All @@ -15,11 +17,16 @@ const Iframe = styled.iframe`
`

class AnalyticsTracker extends React.PureComponent {
handleOnLoad = () => {
this.props.analyticsActions.createABTest(AB_TESTS.WALLET_PIT_SIGNUP)
}

render () {
const { domains, siteId } = this.props
return (
<Iframe
id='matomo-iframe'
onLoad={this.handleOnLoad}
src={domains.walletHelper + '/wallet-helper/matomo/#/?siteId=' + siteId}
/>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import styled, { keyframes, css } from 'styled-components'
import { prop } from 'ramda'
import { Icon, Image, Link, Text } from 'blockchain-info-components'
import { Wrapper } from 'components/Public'

Expand Down Expand Up @@ -70,8 +71,14 @@ const GoLink = styled.div`
}
`

const PitCallout = () => {
return (
const PitCallout = ({ abTestR, domainsR }) => {
const domain = prop(
'thePit',
domainsR.getOrElse({ thePit: 'https://pit.blockchain.com' })
)
const campaign = abTestR.getOrElse('original')

return campaign === 'original' ? null : (
<PitCalloutWrapper>
<InnerWrapper>
<CopyWrapper>
Expand All @@ -97,7 +104,7 @@ const PitCallout = () => {
}}
/>
<FooterLink
href='google.com'
href={`${domain}/?utm_source=web_wallet&utm_medium=wallet_signup&utm_campaign=${campaign}`}
className='footer'
target='_blank'
rel='noopener noreferrer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,45 @@ import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { formValueSelector } from 'redux-form'
import { pathOr } from 'ramda'
import { Remote } from 'blockchain-wallet-v4'

import Register from './template'
import { actions, selectors } from 'data'
import { actions, model, selectors } from 'data'

const { AB_TESTS } = model.analytics

class RegisterContainer extends React.PureComponent {
componentDidMount () {
if (Remote.Success.is(this.props.abTestR)) return

// This line is done in AnalyticsTracker because we need to wait for
// the matomo iframe to mount. See ../../providers/AnalyticsTracker/index
// this.props.analyticsActions.createABTest(AB_TESTS.WALLET_PIT_SIGNUP)

window.addEventListener('message', this.receiveMatomoMessage, false)

// Fallback if a/b test can not be created
setTimeout(() => {
if (!Remote.Success.is(this.props.abTestR)) {
this.props.analyticsActions.createABTestSuccess(
AB_TESTS.WALLET_PIT_SIGNUP,
'original'
)
}
}, 2000)
}

receiveMatomoMessage = res => {
if (res.data.from === 'matomo') {
const result = pathOr('original', ['data', 'command'], res)
this.props.analyticsActions.createABTestSuccess(
AB_TESTS.WALLET_PIT_SIGNUP,
result
)
}
}

onSubmit = () => {
const { email, password, language } = this.props
this.props.authActions.register(email, password, language)
Expand All @@ -20,12 +54,13 @@ class RegisterContainer extends React.PureComponent {
Loading: () => true,
NotAsked: () => false
})

const passwordLength = (password && password.length) || 0

return (
<Register
onSubmit={this.onSubmit}
busy={busy}
onSubmit={this.onSubmit}
password={password}
passwordLength={passwordLength}
{...this.props}
Expand All @@ -36,13 +71,16 @@ class RegisterContainer extends React.PureComponent {

const mapStateToProps = state => ({
data: selectors.auth.getRegistering(state),
domainsR: selectors.core.walletOptions.getDomains(state),
language: selectors.preferences.getLanguage(state),
email: formValueSelector('register')(state, 'email'),
goals: selectors.goals.getGoals(state),
password: formValueSelector('register')(state, 'password') || ''
password: formValueSelector('register')(state, 'password') || '',
abTestR: selectors.analytics.selectAbTest(AB_TESTS.WALLET_PIT_SIGNUP)(state)
})

const mapDispatchToProps = dispatch => ({
analyticsActions: bindActionCreators(actions.analytics, dispatch),
alertActions: bindActionCreators(actions.alerts, dispatch),
authActions: bindActionCreators(actions.auth, dispatch)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const validStrongPassword = value =>
)

const Register = props => {
const { handleSubmit, busy, invalid, password, passwordLength, goals } = props
const { busy, goals, handleSubmit, invalid, password, passwordLength } = props
let passwordScore = has('zxcvbn', window) ? window.zxcvbn(password).score : 0
const isLinkAccountGoal = find(propEq('name', 'linkAccount'), goals)

Expand Down Expand Up @@ -233,7 +233,7 @@ const Register = props => {
</FormGroup>
</RegisterForm>
</PublicWrapper>
<PitCallout />
<PitCallout {...props} />
</SignupWrapper>
)
}
Expand Down

0 comments on commit f19a71c

Please sign in to comment.