Search code examples
amp-html

${documentReferrer} is empty when document.referrer is "https://www.google.com/"


Looking through the AMP documentation (https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#document-referrer) is appears that the documentReferrer variable should reflect the JS document.referrer.

While documentReferrer appears to report the correct value for other domains (like: www.twitter.com, t.co, linkedin.com, etc.) when the page's document.referrer value is "https://www.google.com/" documentReferrer is empty. I couldn't find any documentation indicating that the www.google.com domain carried any additional caveats.


Solution

  • The AMP documentation is accurate. There is no exception made for "https://www.google.com/".

    It is worth mentioning that some AMP tags (like <analytics-tag>) allow you to define custom variables for internal use within the tag. These variables can take precedence over global variables (like documentReferrer) within that tag's scope.

    For more details on one very specific scenario where that can occur see: https://github.com/ampproject/amphtml/issues/10374