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

Add analytics events #1036

Merged
merged 15 commits into from
Jun 21, 2017
4 changes: 3 additions & 1 deletion src/__tests__/field/social_buttons_pane.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('SocialButtonsPane', () => {
signUp: false,
disabled: false
};

beforeEach(() => {
jest.resetModules();

Expand All @@ -37,7 +38,8 @@ describe('SocialButtonsPane', () => {
}));

jest.mock('core/index', () => ({
id: () => 1
id: () => 1,
emitEvent: jest.fn()
}));
});

Expand Down
3 changes: 2 additions & 1 deletion src/connection/database/reset_password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { authWithUsername, hasScreen } from './index';
import { cancelResetPassword, resetPassword } from './actions';
import { renderPasswordResetConfirmation } from './password_reset_confirmation';
import * as i18n from '../../i18n';
import * as l from '../../core/index';
Copy link
Member

Choose a reason for hiding this comment

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

do we need this?


const Component = ({ i18n, model }) => {
const headerText = i18n.html('forgotPasswordInstructions') || null;
Expand Down Expand Up @@ -37,7 +38,7 @@ export default class ResetPassword extends Screen {
return i18n.str(m, 'forgotPasswordTitle');
}

submitHandler() {
submitHandler(m) {
return resetPassword;
}

Expand Down
10 changes: 9 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export default class Base extends EventEmitter {
'authorization_error',
'hash_parsed',
'signin ready',
'signup ready'
'signup ready',

'forgot_password ready',
'forgot_password submit',
'signin submit',
'signup submit',
'federated login'
];

this.id = idu.incremental();
Expand Down Expand Up @@ -125,6 +131,8 @@ export default class Base extends EventEmitter {
l.emitEvent(m, 'signin ready');
} else if (screen.name === 'main.signUp') {
l.emitEvent(m, 'signup ready');
} else if (screen.name === 'forgotPassword') {
l.emitEvent(m, 'forgot_password ready');
}
}
this.oldScreenName = screen.name;
Expand Down
3 changes: 2 additions & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ function extractAuthOptions(options) {
sso,
state,
nonce
} = options.auth || {};
} =
options.auth || {};

let { oidcConformant } = options;

Expand Down
12 changes: 11 additions & 1 deletion src/field/social/social_buttons_pane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import { logIn } from '../../quick-auth/actions';
import { displayName, socialConnections, authButtonsTheme } from '../../connection/social/index';

export default class SocialButtonsPane extends React.Component {
handleAuthButtonClick(lock, provider, isSignUp) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this method outside the class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean in the same file, out of the class?

const prov = typeof provider !== 'object' ? provider.toJS() : provider;
Copy link
Member

Choose a reason for hiding this comment

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

Do we need all values of the connection? Can we just send what type of strategy it is?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its technically possible to have multiple strategies of the same type though, right? Thats why we were thinking of getting the name as well as the strategy. We dont need all the properties though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you specify what properties to keep? I'll work on this in a few minutes

Copy link
Member

Choose a reason for hiding this comment

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

You can have multiples connection names per strategy for enterprise (for social it might not be that common) But with connection name and strategy will be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, thanks 👍


l.emitEvent(lock, 'federated login', {
...prov,
action: isSignUp ? 'signup' : 'signin'
});
return logIn(l.id(lock), provider);
}

render() {
// TODO: i don't like that it receives the instructions tanslated
// but it also takes the t fn
Expand All @@ -31,7 +41,7 @@ export default class SocialButtonsPane extends React.Component {
signUp ? 'signUpWithLabel' : 'loginWithLabel',
connectionName || displayName(x)
)}
onClick={() => logIn(l.id(lock), x)}
onClick={() => this.handleAuthButtonClick(lock, x, signUp)}
strategy={x.get('strategy')}
primaryColor={primaryColor}
foregroundColor={foregroundColor}
Expand Down
27 changes: 26 additions & 1 deletion src/ui/box/chrome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
import ReactCSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
import MultisizeSlide from './multisize_slide';
import GlobalMessage from './global_message';
import * as l from '../../core/index';
import Header from './header';

const submitSvg =
Expand All @@ -12,6 +13,23 @@ const submitText =
'<svg focusable="false" class="icon-text" width="8px" height="12px" viewBox="0 0 8 12" version="1.1" xmlns="http://www.w3.org/2000/svg"><g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Web/Submit/Active" transform="translate(-148.000000, -32.000000)" fill="#FFFFFF"><polygon id="Shape" points="148 33.4 149.4 32 155.4 38 149.4 44 148 42.6 152.6 38"></polygon></g></g></svg>';

class SubmitButton extends React.Component {
handleSubmit() {
const { label, screenName, contentProps } = this.props;
const { model } = contentProps;

if (screenName === 'main.signUp') {
l.emitEvent(model, 'signup submit');
} else if (screenName === 'main.login') {
l.emitEvent(model, 'signin submit');
} else if (screenName === 'forgotPassword') {
l.emitEvent(model, 'forgot_password submit');
}

if (this.props.onSubmit) {
this.props.onSubmit(label, screenName);
}
}

focus() {
ReactDOM.findDOMNode(this).focus();
}
Expand All @@ -30,6 +48,7 @@ class SubmitButton extends React.Component {
className="auth0-lock-submit"
disabled={disabled}
style={{ backgroundColor: color }}
onClick={::this.handleSubmit}
type="submit"
>
<div className="auth0-loading-container">
Expand All @@ -44,7 +63,10 @@ class SubmitButton extends React.Component {
SubmitButton.propTypes = {
color: PropTypes.string.isRequired,
disabled: PropTypes.bool,
label: PropTypes.string
label: PropTypes.string,
screenName: PropTypes.string,
onSubmit: PropTypes.func,
contentProps: PropTypes.object
};

const MESSAGE_ANIMATION_DURATION = 250;
Expand Down Expand Up @@ -193,6 +215,8 @@ export default class Chrome extends React.Component {
<SubmitButton
color={primaryColor}
disabled={disableSubmitButton}
screenName={screenName}
contentProps={contentProps}
key="submit"
label={submitButtonLabel}
ref="submit"
Expand Down Expand Up @@ -306,6 +330,7 @@ Chrome.propTypes = {
isSubmitting: PropTypes.bool.isRequired,
logo: PropTypes.string.isRequired,
primaryColor: PropTypes.string.isRequired,
screenName: PropTypes.string.isRequired,
showSubmitButton: PropTypes.bool.isRequired,
submitButtonLabel: PropTypes.string,
success: PropTypes.node,
Expand Down