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

Analytics: Enable parentPostMessage #17641

Merged
merged 4 commits into from Aug 23, 2018

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Aug 21, 2018

As we agreed, add the parentPostMessage to analytics trigger config, and post the message to parent if is inabox runtime.

Note: I decided that automatically appending ${extraUrlParams} doesn't make much sense in this case. However one can still include extraUrlParams with parentPostMessage: foo ${extraUrlParams} bar

I'll submit doc change in another PR.

if (!trigger['on'] || !trigger['request']) {
const hasRequestOrPostMessage = trigger['request'] ||
(trigger['parentPostMessage'] && this.isInabox_);
if (!trigger['on'] || !hasRequestOrPostMessage) {
this.user().error(TAG, '"on" and "request" ' +
'attributes are required for data to be collected.');
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now a somewhat misleading error message, since request is no longer required. For example, if someone misspelled parentPostMessage they might think this was telling them they also needed to add request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I refined the error message a bit in inabox and non inabox case.


if (!request) {
if (requestName != undefined && !request) {
const TAG = this.getName_();
this.user().error(TAG, 'Ignoring event. Request string ' +
'not found: ', trigger['request']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird to say we're ignoring the event if we might not be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rephrase to ignoring request for event. Request ..... Let me know if that's better.

expect(postMessageSpy).to.have.been.called;
});
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have a test for when there's both a post message and a request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added test
inabox case: w/ request and postMessage, w/o request postMessage, only postMessage
non inabox case: with postMessage and request

* return strings, promises, etc.
* @return {Promise<string>}
*/
export function expandPostMessage(baseInstance, msg,
Copy link
Contributor

Choose a reason for hiding this comment

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

are we able to just reuse the expandTemplate method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure we can also choose to expose the expandTemplate getExtraUrlParams getExtraUrlParamsString and constructExtraUrlParamStrs to amp-analytics.js
But I feel it's cleaner this way. Let me know if you have strong opinion.

@zhouyx zhouyx force-pushed the analytics-postmessage branch 2 times, most recently from 0a3e0c9 to 3a05e06 Compare August 23, 2018 00:50
@zhouyx
Copy link
Contributor Author

zhouyx commented Aug 23, 2018

One thing just crossed my mind. Will the new error message on the same error break publishers error analysis?

@zhouyx zhouyx merged commit c2c4b57 into ampproject:master Aug 23, 2018
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
* init commit

* fix linter

* refine error message

* code style
@jeffkaufman
Copy link
Contributor

I'll submit doc change in another PR.

Did this ever end up happening? Do you need me to do it?

@zhouyx
Copy link
Contributor Author

zhouyx commented Apr 4, 2019

Did this ever end up happening? Do you need me to do it?

I'm sorry but I haven't documented the feature yet. It would be great if you can help! Our analytics documentation is a little bit outdated not only for this feature. @jeffjose let's plan a mini sprint to update our docs after AMP conf. WDYT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants