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

Enable adding analytics to template ad #13114

Merged
merged 6 commits into from Jan 30, 2018

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jan 29, 2018

Insert <amp-analytics> component to template ad.

creativeJson should be defined like

{
  "templateUrl": ...
  "data": {}
  "analytics": {
     "remote": // define remote config url
     "type": // type attribute
     "inline": // inline config valeu
   } // Can also be an array of jsonObject
}

@zhouyx zhouyx force-pushed the template-ad-custom-analytics branch 2 times, most recently from 138f65c to 3d118c0 Compare January 30, 2018 00:38
@@ -75,7 +78,39 @@ export class AmpAdTemplates {
*/
render(templateValues, element) {
return Services.templatesFor(this.win_)
.findAndRenderTemplate(element, templateValues);
.findAndRenderTemplate(element, templateValues)
.then(renderedElement => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is the then clause needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

(isArray(analyticsValue) ? analyticsValue : [analyticsValue]);
for (let i = 0; i < analyticsValue.length; i++) {
const config = analyticsValue[i];
const analyticsEle = document.createElement('amp-analytics');
Copy link
Contributor

Choose a reason for hiding this comment

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

should you use element.owenerDocument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

}
if (config['inline']) {
const scriptElem = createElementWithAttributes(
document,
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -151,6 +151,18 @@ export class AmpAdNetworkAdzerkImpl extends AmpA4A {

/** @override */
getAmpAdMetadata(unusedCreative) {
if (this.ampCreativeJson_.analytics) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should you just load the analytics extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer not to load the extension here. AmpA4A will load extension based on metadata, I think it's better to load all extensions together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked offline. It's not that straightforward to load extension here. Will keep the current approach.

@zhouyx zhouyx force-pushed the template-ad-custom-analytics branch from 49b7db4 to 404d22e Compare January 30, 2018 21:08
@zhouyx zhouyx merged commit 13042d4 into ampproject:master Jan 30, 2018
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* enable adding analytics to template

* fix type check

* rename

* address comment

* linter

* fix test
protonate pushed a commit to protonate/amphtml that referenced this pull request Mar 15, 2018
* enable adding analytics to template

* fix type check

* rename

* address comment

* linter

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

Successfully merging this pull request may close these issues.

None yet

4 participants