Skip to content

Send form-submit success/error analytics events#5868

Merged
mkhatib merged 6 commits intoampproject:masterfrom
mkhatib:submit-analytics
Nov 7, 2016
Merged

Send form-submit success/error analytics events#5868
mkhatib merged 6 commits intoampproject:masterfrom
mkhatib:submit-analytics

Conversation

@mkhatib
Copy link
Copy Markdown
Contributor

@mkhatib mkhatib commented Oct 28, 2016

Fix #5674

@mkhatib
Copy link
Copy Markdown
Contributor Author

mkhatib commented Oct 28, 2016

/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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't it this.win?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, amp-form is not a base-element.

Copy link
Copy Markdown
Contributor

@avimehta avimehta left a comment

Choose a reason for hiding this comment

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

mostly LGTM. Feel free to merge if others approve before me and you have addressed non-nit comments.

<script type="application/json">
{
"requests": {
"test-ping": "https://my-analytics.com/ping?title=${title}&acct=${account}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

"test-ping": "https://my-analytics.com/ping?title=${title}&acct=${account}",
"event": "https://my-analytics.com/ping?eid=${eventId}&elab=${eventLabel}"
},
"vars": {
Copy link
Copy Markdown
Contributor

@avimehta avimehta Oct 28, 2016

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

"account": "12345"
},
"triggers": {
"page-view": {
Copy link
Copy Markdown
Contributor

@avimehta avimehta Oct 28, 2016

Choose a reason for hiding this comment

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

nit: this can be removed as this isn't specific to forms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

src/analytics.js Outdated


/**
* Helper method to trigger analytics event if analytics is available.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if amp-analytics is available?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

requireAmpResponseSourceOrigin: true,
}).then(response => {
this.actions_.trigger(this.form_, 'submit-success', null);
this.analyticsEvent_('amp-form-submit-success');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These need to be documented. Please see how access and slides document this and use the same convention?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

file a bug and add a todo here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done


/**
* @param {!AnalyticsEventType|string} type The type of event.
* @param {!Object<string, string>=} opt_vars A map of vars and their values.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confused. How does ! and = work together? How is it different from ? and = being used together?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Afaik, the = allows undefined and the ? allows null as values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

= means the parameter can be omitted:

fn({});
fn();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so we don't really need ? here then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using ! instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

src/analytics.js Outdated
window, 'amp-analytics-instrumentation', 'amp-analytics')));
};


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: extra empty line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@mkhatib mkhatib assigned camelburrito and unassigned cramforce Nov 1, 2016
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 => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we have to return anything here, seems like it is not being used anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped.

src/analytics.js Outdated
export function triggerAnalyticsEvent(window, eventType, opt_vars) {
return analyticsForOrNull(window).then(analytics => {
if (!analytics) {
return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i guess we should also be doing some kind of logging here, so that we know if we are triggering before analytics is available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped.

src/analytics.js Outdated
return false;
}
analytics.triggerEvent(eventType, opt_vars);
return true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't think this is needed either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped.

import {Animation} from '../../../src/animation';
import {BaseSlides} from './base-slides';
import {analyticsForOrNull} from '../../../src/analytics';
import {triggerAnalyticsEvent} from '../../../src/analytics';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you must also make amp-access use this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

@camelburrito camelburrito left a comment

Choose a reason for hiding this comment

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

Please fix the comments above!

@mkhatib
Copy link
Copy Markdown
Contributor Author

mkhatib commented Nov 2, 2016

@camelburrito fixed comments PTAL 👀

requireAmpResponseSourceOrigin: true,
}).then(response => {
this.actions_.trigger(this.form_, 'submit-success', null);
this.analyticsEvent_('amp-form-submit-success');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tests for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@mkhatib
Copy link
Copy Markdown
Contributor Author

mkhatib commented Nov 5, 2016

@camelburrito 👀 PTAL

@mkhatib mkhatib merged commit 926b444 into ampproject:master Nov 7, 2016
@mkhatib mkhatib deleted the submit-analytics branch November 7, 2016 21:41
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants