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

Adding SOURCE_PATH URL variable substitution #2567

Merged
merged 1 commit into from
Mar 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/amp-analytics/0.1/vendors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const ANALYTICS_CONFIG = {
'serverResponseTime': 'SERVER_RESPONSE_TIME',
'sourceUrl': 'SOURCE_URL',
'sourceHost': 'SOURCE_HOST',
'sourcePath': 'SOURCE_PATH',
'tcpConnectTime': 'TCP_CONNECT_TIME',
'timestamp': 'TIMESTAMP',
'timezone': 'TIMEZONE',
Expand Down
12 changes: 12 additions & 0 deletions extensions/amp-analytics/analytics-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ Parses and provides the source URL of the current document to the URL.

The source URL is extracted from the proxy URL if the document is being served from a *known* proxy. Otherwise the original document URL is returned. For instance, if the URL is served via the proxy `https://cdn.ampproject.org` from the URL `https://cdn.ampproject.org/c/s/example.com/page.html`, then `SOURCE_URL` would return `https://example.com/page.html`. If the URL is served directly from `https://example.com/page.html`, `https://example.com/page.html` will be returned.

### sourceHost

Parses and provides the source URL's host. See the description of `sourceUrl` for more details.

Example value: `example.com`

### sourcePath

Parses and provides the source URL's path part. See the description of `sourceUrl` for more details.

Example value: `%2Fpage.html`

### title

Provides the title of the current document.
Expand Down
10 changes: 10 additions & 0 deletions spec/amp-var-substitutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ For instance:
```
may make a request to something like `https://foo.com/pixel?host=pinterest.com`.

### SOURCE_PATH

Use the special string `SOURCE_PATH` to add the source URL's path of the current document to the URL. See the description of `SOURCE_URL` for more details.

For instance:
```html
<amp-pixel src="https://foo.com/pixel?path=SOURCE_PATH"></amp-pixel>
```
may make a request to something like `https://foo.com/pixel?path=%2Fpage2.html`.

### DOCUMENT_CHARSET

Provides the character encoding of the current document.
Expand Down
5 changes: 5 additions & 0 deletions src/url-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class UrlReplacements {
return parseUrl(getSourceUrl(this.win_.location.href)).hostname;
});

// Returns the path of the Source URL for this AMP document.
this.set_('SOURCE_PATH', () => {
return parseUrl(getSourceUrl(this.win_.location.href)).pathname;
});

// Returns a random string that will be the constant for the duration of
// single page view. It should have sufficient entropy to be unique for
// all the page views a single user is making at a time.
Expand Down
6 changes: 6 additions & 0 deletions test/functional/test-url-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ describe('UrlReplacements', () => {
});
});

it('should replace SOURCE_PATH', () => {
return expand('?path=SOURCE_PATH').then(res => {
expect(res).to.not.match(/SOURCE_PATH/);
});
});

it('should replace PAGE_VIEW_ID', () => {
return expand('?pid=PAGE_VIEW_ID').then(res => {
expect(res).to.match(/pid=\d+/);
Expand Down