1

If I pass a string value containing () to the vars property in the <amp-analytics> component, the string is truncated due to the regex in the getNameArgs_ string method.

Eg:

Passing the user agent from the request headers, renders as so:

"vars": {
     "userAgentHeader": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
}

but will be passed in the analytics requests as Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4)

This is because in encodeVars_ the raw value is passed to getNameArgs_ whose regex (([^(]*)(\([^)]*\))?) matches (Mozilla/5.0 as first match and (Macintosh; Intel Mac OS X 10_10_4) as second)

The data needs to match on AMP and on the main site - so even though I could use the Java URLEncoder (UTF-8), which would encode the brackets, the equivalent JS encodeURIComponent() does not encode brackets therefore I would need to convert back to . So the regex would still match on the equivalent encoding.

Using URLEncoder has this as the query param in the request (double encoding...):

Mozilla%252F5.0%2B%2528Macintosh%253B%2BIntel%2BMac%2BOS%2BX%2B10_10_4%2529%2BAppleWebKit%252F537.36%2B%2528KHTML%252C%2Blike%2BGecko%2529%2BChrome%252F53.0.2785.116%2BSafari%252F537.36

compared to this in a normal GA request:

Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_4)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F53.0.2785.116%20Safari%2F537.36

Even that exact string gets truncated to Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_4) if pasted directly into the object...

Maybe I am doing something completely wrong?

4

2 回答 2

1

这是一个错误,已在此拉取请求中修复,并将在版本中发布1481838084444

于 2016-12-16T14:14:03.007 回答
0

这似乎是一个错误。请在以下位置提交错误报告:https ://github.com/ampproject/amphtml/issues/new

于 2016-12-01T11:38:36.227 回答