Skip to content

Commit

Permalink
馃摉 Document all analytics advanced variable syntax (ampproject#28822)
Browse files Browse the repository at this point in the history
* add doc

* nit
  • Loading branch information
zhouyx committed Jun 12, 2020
1 parent ab06293 commit 28963ab
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions spec/amp-var-substitutions.md
Expand Up @@ -275,6 +275,23 @@ The tables below list the available URL variables grouped by type of usage. Furt
| [Variants](#experiment-variants) | `VARIANTS` | N/A | [`<amp-experiment>`](https://github.com/ampproject/amphtml/blob/master/extensions/amp-experiment/amp-experiment.md) |
| [Geolocation](#geolocation) | `AMP_GEO` | `${ampGeo}` | [`<amp-geo>`](https://github.com/ampproject/amphtml/blob/master/extensions/amp-geo/amp-geo.md) |

### Analytics Advanced Variable Syntax

| Variable Name | Platform Variable | amp-analytics Variable |
| --------------------------- | ----------------- | ---------------------- |
| [Default](#default) | N/A | `$DEFAULT` |
| [SubStr](#string-substr) | N/A | `$SUBSTR` |
| [Trim](#trim) | N/A | `$TRIM` |
| [ToLowerCase](#tolowercase) | N/A | `$TOLOWERCASE` |
| [ToUpperCase](#touppercase) | N/A | `$TOUPPERCASE` |
| [Not](#not) | N/A | `$NOT` |
| [Base64](#base64) | N/A | `$BASE64` |
| [Hash](#hash) | N/A | `$HASH` |
| [If](#if) | N/A | `$IF` |
| [Replace](#replace) | N/A | `$REPLACE` |
| [Match](#match) | N/A | `$MATCH` |
| [Equals](#equals) | N/A | `$EQUALS` |

### Miscellaneous

| Variable Name | Platform Variable | amp-analytics Variable |
Expand Down Expand Up @@ -1292,3 +1309,67 @@ Provides the viewport width in pixels available for the page rendering. In contr
```
- **amp-analytics variable**: `${viewportWidth}`
- Example value: `2560`

#### Analytics Advanced Variable Syntax

The following variables are only supported in `<amp-analytics>`

##### Default

Used to assign fallback value when the variable is resolved to empty string.

- Example: `$DEFAULT(${var}, fallback)`

##### String substr

- Example: `$SUBSTR(${var}, 1, 4)`

##### Trim

- Example: `$TRIM(${var})`

##### ToLowerCase

- Example: `$TOLOWERCASE(${var})`

##### ToUpperCase

- Example: `$TOUPPERCASE(TITLE)`

##### Not

Used to convert truth-y/false-y value to `'false'`/`'true'` string.

- Example `$NOT(hello)` = `'false'` and `$NOT()` = `'true'`

##### Base64

- Example `$BASE64(PAGE_VIEW_ID)`

##### Hash

SHA-384 hash

- Example: `$HASH(PAGE_VIEW_ID)`

##### If

An if statement to choose between values

- Example: `$IF(${var}, value1, value2)` resolves to `value2` if `${var}` resolves to falsey value (`'false'`, `''`, `'0'`, `'null'`, `'Nan'` or `'undefined'`), otherwise will resolve to `value1`.

##### Replace

Find an replace all matched pattern.

- Example: `$REPLACE(${var}, matchPattern, replaceStr)`

##### Match

Find the specified (or first) matched pattern.

- Example: `$MATCH(${var}, matchPatter, 0)`

##### Equals

- Example: `$EQUALS(${val}, value)` resolves to `'true'` or `'false'`

0 comments on commit 28963ab

Please sign in to comment.