Send form-submit success/error analytics events#5868
Send form-submit success/error analytics events#5868mkhatib merged 6 commits intoampproject:masterfrom
Conversation
|
/cc @avimehta @rudygalfi let me know if this looks good - event naming and if example should be updated - I don't know 100% if I am using the analytics config correct. |
| * @param {?Object<string, string>=} opt_vars A map of vars and their values. | ||
| * @private | ||
| */ | ||
| analyticsEvent_(eventType, opt_vars) { |
There was a problem hiding this comment.
No, amp-form is not a base-element.
avimehta
left a comment
There was a problem hiding this comment.
mostly LGTM. Feel free to merge if others approve before me and you have addressed non-nit comments.
examples/forms.amp.html
Outdated
| <script type="application/json"> | ||
| { | ||
| "requests": { | ||
| "test-ping": "https://my-analytics.com/ping?title=${title}&acct=${account}", |
There was a problem hiding this comment.
nit: This URL will show an errror in network tab. Slight preference for a real URL like: https://www.ampproject.org/static/img/logo-blue.svg.
examples/forms.amp.html
Outdated
| "test-ping": "https://my-analytics.com/ping?title=${title}&acct=${account}", | ||
| "event": "https://my-analytics.com/ping?eid=${eventId}&elab=${eventLabel}" | ||
| }, | ||
| "vars": { |
There was a problem hiding this comment.
nit: Nothing is wrong with this exampe but this is not necessary to showcase analytics abilities in forms. Maybe remove? Also remove ${account} from the request?
examples/forms.amp.html
Outdated
| "account": "12345" | ||
| }, | ||
| "triggers": { | ||
| "page-view": { |
There was a problem hiding this comment.
nit: this can be removed as this isn't specific to forms.
src/analytics.js
Outdated
|
|
||
|
|
||
| /** | ||
| * Helper method to trigger analytics event if analytics is available. |
There was a problem hiding this comment.
if amp-analytics is available?
| requireAmpResponseSourceOrigin: true, | ||
| }).then(response => { | ||
| this.actions_.trigger(this.form_, 'submit-success', null); | ||
| this.analyticsEvent_('amp-form-submit-success'); |
There was a problem hiding this comment.
These need to be documented. Please see how access and slides document this and use the same convention?
There was a problem hiding this comment.
Yeah the plan was to document these once this change is in prod otherwise we'll get lots of issues opened that this isn't working if we update docs right away. I'll send a follow up PR later.
There was a problem hiding this comment.
file a bug and add a todo here.
|
|
||
| /** | ||
| * @param {!AnalyticsEventType|string} type The type of event. | ||
| * @param {!Object<string, string>=} opt_vars A map of vars and their values. |
There was a problem hiding this comment.
Confused. How does ! and = work together? How is it different from ? and = being used together?
There was a problem hiding this comment.
Afaik, the = allows undefined and the ? allows null as values.
There was a problem hiding this comment.
= means the parameter can be omitted:
fn({});
fn();There was a problem hiding this comment.
so we don't really need ? here then?
src/analytics.js
Outdated
| window, 'amp-analytics-instrumentation', 'amp-analytics'))); | ||
| }; | ||
|
|
||
|
|
src/analytics.js
Outdated
| * @returns {!Promise<boolean>} Whether the event was sent or not. | ||
| */ | ||
| export function triggerAnalyticsEvent(window, eventType, opt_vars) { | ||
| return analyticsForOrNull(window).then(analytics => { |
There was a problem hiding this comment.
why do we have to return anything here, seems like it is not being used anywhere?
src/analytics.js
Outdated
| export function triggerAnalyticsEvent(window, eventType, opt_vars) { | ||
| return analyticsForOrNull(window).then(analytics => { | ||
| if (!analytics) { | ||
| return false; |
There was a problem hiding this comment.
i guess we should also be doing some kind of logging here, so that we know if we are triggering before analytics is available.
src/analytics.js
Outdated
| return false; | ||
| } | ||
| analytics.triggerEvent(eventType, opt_vars); | ||
| return true; |
There was a problem hiding this comment.
i don't think this is needed either.
| import {Animation} from '../../../src/animation'; | ||
| import {BaseSlides} from './base-slides'; | ||
| import {analyticsForOrNull} from '../../../src/analytics'; | ||
| import {triggerAnalyticsEvent} from '../../../src/analytics'; |
There was a problem hiding this comment.
you must also make amp-access use this.
camelburrito
left a comment
There was a problem hiding this comment.
Please fix the comments above!
b7b1619 to
acc106f
Compare
|
@camelburrito fixed comments PTAL 👀 |
| requireAmpResponseSourceOrigin: true, | ||
| }).then(response => { | ||
| this.actions_.trigger(this.form_, 'submit-success', null); | ||
| this.analyticsEvent_('amp-form-submit-success'); |
There was a problem hiding this comment.
file a bug and add a todo here.
| * @param {string} eventType | ||
| * @param {!Object<string, string>=} opt_vars A map of vars and their values. | ||
| */ | ||
| export function triggerAnalyticsEvent(window, eventType, opt_vars) { |
|
@camelburrito 👀 PTAL |
Fix #5674