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
Conversation
3c17378
to
7808661
Compare
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.'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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']); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
0a3e0c9
to
3a05e06
Compare
One thing just crossed my mind. Will the new error message on the same error break publishers error analysis? |
3a05e06
to
8b07771
Compare
* init commit * fix linter * refine error message * code style
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 |
As we agreed, add the
parentPostMessage
to analyticstrigger
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 includeextraUrlParams
withparentPostMessage: foo ${extraUrlParams} bar
I'll submit doc change in another PR.