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

AFE: move submit logging to server #35723

Merged
merged 6 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ const SIGN_UP_URL = studio(
const SIGN_IN_URL = studio(`/users/sign_in?${RETURN_TO}`);

export default class AmazonFutureEngineerAccountConfirmation extends React.Component {
logSignUpButtonPress = () => {
firehoseClient.putRecord({
study: 'amazon-future-engineer-eligibility',
event: 'sign_up_button_press'
});
signUpButtonPress = () => {
firehoseClient.putRecord(
{
study: 'amazon-future-engineer-eligibility',
event: 'sign_up_button_press'
},
{callback: () => (window.location = SIGN_UP_URL)}
);
};

signInButtonPress = event => {
event.preventDefault();

firehoseClient.putRecord(
{
study: 'amazon-future-engineer-eligibility',
event: 'sign_in_button_press'
},
{callback: () => (window.location = SIGN_IN_URL)}
);
};

render() {
Expand All @@ -43,13 +58,13 @@ export default class AmazonFutureEngineerAccountConfirmation extends React.Compo
if you already have one.
</div>
<div style={styles.body}>
Already have a Code.org account? <a href={SIGN_IN_URL}>Sign in.</a>
Already have a Code.org account?{' '}
<a onClick={this.signInButtonPress}>Sign in.</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing the href may have changed the style of this link. I think, in this case, you could avoid that with href="#" or something - I don't feel bad about changing the hash since we're about to navigate.

Copy link
Contributor Author

@bencodeorg bencodeorg Jul 9, 2020

Choose a reason for hiding this comment

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

Nice, good to know will update! Main difference I see is that when you hover it gives you the clicky finger with an href, and the text cursor without it.

Copy link
Member

Choose a reason for hiding this comment

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

fwiw, you can use cursor: pointer to show the clicky finger again.

</div>
<Button
id="sign_up"
href={SIGN_UP_URL}
style={styles.button}
onClick={this.logSignUpButtonPress}
onClick={this.signUpButtonPress}
>
Sign up
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ export default class AmazonFutureEngineerEligibility extends React.Component {
this.saveToSessionStorage();

if (!isEligible) {
firehoseClient.putRecord({
study: 'amazon-future-engineer-eligibility',
event: 'ineligible'
});

window.location = pegasus('/afe/start-codeorg');
firehoseClient.putRecord(
{
study: 'amazon-future-engineer-eligibility',
event: 'ineligible'
},
{callback: () => (window.location = pegasus('/afe/start-codeorg'))}
);
}
}

Expand All @@ -198,18 +199,6 @@ export default class AmazonFutureEngineerEligibility extends React.Component {
};

submitToAFE = () => {
firehoseClient.putRecord({
study: 'amazon-future-engineer-eligibility',
event: 'submit_to_afe',
data_json: JSON.stringify({
accountEmail: this.props.accountEmail,
accountSchoolId: this.props.schoolId,
formEmail: this.state.formData.email,
formSchoolId: this.state.formData.schoolId
})
});

// returns a promise
return fetch('/dashboardapi/v1/amazon_future_engineer_submit', {
method: 'POST',
headers: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'honeybadger/ruby'
require 'cdo/firehose'

#
# Handles submissions to our AFE form at code.org/afe, and in turn submits on
Expand All @@ -12,7 +13,7 @@ def submit
return head :forbidden unless current_user&.teacher?

afe_params = submit_params
Services::AFEEnrollment.submit(
submission_body = Services::AFEEnrollment.submit(
first_name: afe_params['firstName'],
last_name: afe_params['lastName'],
email: afe_params['email'],
Expand All @@ -29,6 +30,20 @@ def submit
new_code_account: current_user.created_at > 5.minutes.ago
)

FirehoseClient.instance.put_record(
{
study: 'amazon-future-engineer-eligibility',
event: 'submit_to_afe',
data_json: {
accountEmail: current_user.email,
accountSchoolId: current_user&.school_info&.school&.id,
formEmail: afe_params['email'],
formSchoolId: afe_params['schoolId'],
formData: submission_body
}.to_json
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now we're tracking this event if we successfully submit to AFE or if submitting to AFE is disabled for that environment. (But not if we skip submission or submission fails for some other reason.) That seems okay - is it the desired behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it was sort of for testing purposes, so I could see what would be sent to Firehose in development (since it sends Firehose requests to your logfile). Seems maybe useful in the future as well, to have the entire payload returned to the controller in development (instead of just immediately returning)?


# If the teacher requested it, submit to CSTA as well
if to_bool(afe_params['csta'])
school = School.find_by(id: afe_params['schoolId'])
Expand Down
42 changes: 22 additions & 20 deletions dashboard/lib/services/afe_enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,37 @@ class Error < StandardError; end
def self.submit(first_name:, last_name:, email:, nces_id:, street_1:, street_2:,
city:, state:, zip:, marketing_kit:, csta_plus:, aws_educate:,
amazon_terms:, new_code_account:)
return unless CDO.afe_pardot_form_handler_url
submission_body = {
'traffic-source' => 'AFE-code.org-2020',
'first-name' => first_name,
'last-name' => last_name,
'email' => email,
'nces-id' => nces_id,
'school-address-1' => street_1,
'school-address-2' => street_2,
'school-city' => city,
'school-state' => state,
'school-zip' => zip,
'inspirational-marketing-kit' => booleanize(marketing_kit),
'csta-plus' => booleanize(csta_plus),
'aws-educate' => booleanize(aws_educate),
'amazon-terms' => booleanize(amazon_terms),
'new-code-account' => booleanize(new_code_account),
'registration-date-time' => Time.now.iso8601
}

return submission_body unless CDO.afe_pardot_form_handler_url

raise Error.new('AFE submission skipped: Terms and conditions were not accepted') unless amazon_terms

response = Net::HTTP.post_form(
URI(CDO.afe_pardot_form_handler_url),
{
'traffic-source' => 'AFE-code.org-2020',
'first-name' => first_name,
'last-name' => last_name,
'email' => email,
'nces-id' => nces_id,
'school-address-1' => street_1,
'school-address-2' => street_2,
'school-city' => city,
'school-state' => state,
'school-zip' => zip,
'inspirational-marketing-kit' => booleanize(marketing_kit),
'csta-plus' => booleanize(csta_plus),
'aws-educate' => booleanize(aws_educate),
'amazon-terms' => booleanize(amazon_terms),
'new-code-account' => booleanize(new_code_account),
'registration-date-time' => Time.now.iso8601
}
submission_body
)

raise Error.new("AFE submission failed with HTTP #{response.code}") unless response.code == '200'
raise Error.new("AFE submission failed with a validation error") if response.body =~ /Cannot find error page/
nil
submission_body
end

private_class_method def self.booleanize(val)
Expand Down