Bug 1601878 - Report click metrics for EOYSnippets r=nanj

Differential Revision: https://phabricator.services.mozilla.com/D64393

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrei Oprea 2020-02-26 16:12:27 +00:00
Родитель 4f620e31e9
Коммит ffa3d955d3
3 изменённых файлов: 25 добавлений и 2 удалений

Просмотреть файл

@ -24,11 +24,12 @@ class EOYSnippetBase extends React.PureComponent {
handleSubmit(event) { handleSubmit(event) {
event.preventDefault(); event.preventDefault();
this.props.sendClick(event);
this.setFrequencyValue(); this.setFrequencyValue();
this.refs.form.submit();
if (!this.props.content.do_not_autoblock) { if (!this.props.content.do_not_autoblock) {
this.props.onBlock(); this.props.onBlock();
} }
this.refs.form.submit();
} }
renderDonations() { renderDonations() {
@ -61,6 +62,7 @@ class EOYSnippetBase extends React.PureComponent {
action={this.props.content.donation_form_url} action={this.props.content.donation_form_url}
method={this.props.form_method} method={this.props.form_method}
onSubmit={this.handleSubmit} onSubmit={this.handleSubmit}
data-metric="EOYSnippetForm"
ref="form" ref="form"
> >
{donationURLParams.map(([key, value], idx) => ( {donationURLParams.map(([key, value], idx) => (

Просмотреть файл

@ -12067,12 +12067,14 @@ class EOYSnippet_EOYSnippetBase extends external_React_default.a.PureComponent {
handleSubmit(event) { handleSubmit(event) {
event.preventDefault(); event.preventDefault();
this.props.sendClick(event);
this.setFrequencyValue(); this.setFrequencyValue();
this.refs.form.submit();
if (!this.props.content.do_not_autoblock) { if (!this.props.content.do_not_autoblock) {
this.props.onBlock(); this.props.onBlock();
} }
this.refs.form.submit();
} }
renderDonations() { renderDonations() {
@ -12102,6 +12104,7 @@ class EOYSnippet_EOYSnippetBase extends external_React_default.a.PureComponent {
action: this.props.content.donation_form_url, action: this.props.content.donation_form_url,
method: this.props.form_method, method: this.props.form_method,
onSubmit: this.handleSubmit, onSubmit: this.handleSubmit,
"data-metric": "EOYSnippetForm",
ref: "form" ref: "form"
}, donationURLParams.map(([key, value], idx) => external_React_default.a.createElement("input", { }, donationURLParams.map(([key, value], idx) => external_React_default.a.createElement("input", {
type: "hidden", type: "hidden",

Просмотреть файл

@ -30,6 +30,7 @@ describe("EOYSnippet", () => {
provider, provider,
onAction: sandbox.stub(), onAction: sandbox.stub(),
onBlock: sandbox.stub(), onBlock: sandbox.stub(),
sendClick: sandbox.stub(),
}; };
const comp = mount(<EOYSnippet {...props} />); const comp = mount(<EOYSnippet {...props} />);
// Check schema with the final props the component receives (including defaults) // Check schema with the final props the component receives (including defaults)
@ -64,6 +65,10 @@ describe("EOYSnippet", () => {
assert.lengthOf(wrapper.find("input[type='radio']"), 4); assert.lengthOf(wrapper.find("input[type='radio']"), 4);
}); });
it("should have a data-metric field", () => {
assert.ok(wrapper.find("form[data-metric='EOYSnippetForm']"));
});
it("should select the second donation option", () => { it("should select the second donation option", () => {
wrapper = mountAndCheckProps({ selected_button: "donation_amount_second" }); wrapper = mountAndCheckProps({ selected_button: "donation_amount_second" });
@ -103,6 +108,19 @@ describe("EOYSnippet", () => {
assert.notCalled(onBlockStub); assert.notCalled(onBlockStub);
}); });
it("should report form submissions", () => {
wrapper = mountAndCheckProps();
const { sendClick } = wrapper.props();
wrapper.find("form").simulate("submit");
assert.calledOnce(sendClick);
assert.equal(
sendClick.firstCall.args[0].target.dataset.metric,
"EOYSnippetForm"
);
});
it("it should preserve URL GET params as hidden inputs", () => { it("it should preserve URL GET params as hidden inputs", () => {
wrapper = mountAndCheckProps({ wrapper = mountAndCheckProps({
donation_form_url: donation_form_url: