Reputation: 53
Is there a way to retrieve query string values from an AMP-HTML Site and store them in a cookie or use them in a link?
Example:
www.example.com/amp?foo=bar
www.example.com/checkout?foo=bar
Upvotes: 3
Views: 6042
Reputation: 36
You can use QUERY_PARAM
https://expample.amp.com?slug=1234abc
<a
href="https://example.com?abc=QUERY_PARAM(slug)"
data-amp-replace="QUERY_PARAM"
>Go to my site</a
>
<amp-list id="time"
layout="fixed-height"
height="18"
src="https://api.exemple.com/posts?slug=QUERY_PARAM(slug)"
binding="refresh"
data-amp-replace="QUERY_PARAM"
single-item
items=".">
<template type="amp-mustache">
...
</template>
</amp-list>
Upvotes: 2
Reputation: 934
Just extending Avi's answer. You can also use it in forms and anchor tags () like this:
<form method="post" id="form1" role="search" action-xhr="https://example.com/path/to/something" target="_top" on="submit-success:msg-thanks-sticky;submit-error:msg-sorry-sticky">
[...]
<input type="hidden" class="inputHidden" name="param1" value="QUERY_PARAM(param1)" data-amp-replace="QUERY_PARAM">
<input type="hidden" class="inputHidden" name="param2" value="QUERY_PARAM(param2)" data-amp-replace="QUERY_PARAM">
[...]
</form>
Pay attention to the "data-amp-replace" attribute, needed for this specific tags.
For detailed information: - https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#substitution-timing - https://github.com/ampproject/amphtml/blob/master/extensions/amp-form/amp-form.md#variable-substitutions
Upvotes: 3
Reputation: 217
On your non-AMP checkout page, you could use JavaScript to read document.referrer
and extract the query string that was passed to the AMP landing page.
For example:
document.referrer
and see that it contains "https://www.ampproject.org/?foo=bar"
.Note that document.referrer
may be empty when an HTTPS page links to an HTTP URL.
Upvotes: 1
Reputation: 2383
You should be able to use QUERY_PARAM()
variable to get the variables in amp-pixel or amp-analytics.
https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#query_param
Upvotes: 3