Skip to content

Add amp-story URL replacement support#11528

Merged
alanorozco merged 2 commits intoampproject:masterfrom
alanorozco:story-analytics-vars
Oct 2, 2017
Merged

Add amp-story URL replacement support#11528
alanorozco merged 2 commits intoampproject:masterfrom
alanorozco:story-analytics-vars

Conversation

@alanorozco
Copy link
Copy Markdown
Member

This adds support for the rewriting the STORY_PAGE_INDEX and STORY_PAGE_ID variables for analytics.

/cc @newmuis

@alanorozco alanorozco force-pushed the story-analytics-vars branch from c969bc0 to 0d059eb Compare October 2, 2017 18:53
@alanorozco alanorozco changed the title (ON HOLD) Add amp-story URL replacement support Add amp-story URL replacement support Oct 2, 2017
Copy link
Copy Markdown

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Ah, looks like a lot of other extension-specific code is here too. 😝

}

/**
* @param {!Window} win
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ditto.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same response :)

/** @private {?Promise<?ShareTrackingFragmentsDef>} */
this.shareTrackingFragments_ = null;

/** @private {?Promise<?{pageIndex: number, pageId: string}>} */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should return AmpStoryVariableService right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That would be ideal, but I'd rather not add the whole amp-story tree to the general source file set (otherwise the module can't be resolved).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We're not really retrieving an element "service" here though. How are we registering that data as a service with the runtime? registerService?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ohh I see. 😃 I think adding the extension to the Closure file path is fine. Erwin's working on making Closure compile runtime + extensions in a single pass anyways. Replacing a class with a record-type of its getter property interface confused me a lot.

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.

This is super confusing. Why is it a record? Don't these change? There are a lot of services here that function exactly same way, e.g. getAccessService_.

This definitely needs to change. Please send a PR.

getStoryValue_(getter, expr) {
if (!this.storyVariables_) {
this.storyVariables_ =
Services.storyVariableServiceForOrNull(this.ampdoc.win);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This could return null again (if the AMP page doesn't have the story extension installed), which means calling .then() on it will cause an error. In that case, let's throw a user error asking them to install amp-story.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. Re: error. I think the convention in this case is just to assert the error on promise resolution.
  2. Re: null-value, I don't think that's the case. storyVariableServiceForOrNull will return a promise that resolves to null, not null itself.

See getVairiantsValue_ (sic), getShareTrackingValue_ for prior art on the same use-case (i.e. reading extension-specific values).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh, my mistake. Can we change this.storyVariables_ to this.storyVariablesPromise_?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, done.

getStoryValue_(getter, expr) {
if (!this.storyVariables_) {
this.storyVariables_ =
Services.storyVariableServiceForOrNull(this.ampdoc.win);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh, my mistake. Can we change this.storyVariables_ to this.storyVariablesPromise_?

@alanorozco alanorozco merged commit 2fc55d6 into ampproject:master Oct 2, 2017
@alanorozco alanorozco deleted the story-analytics-vars branch October 2, 2017 20:44
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.

5 participants