I am working on a GA-API stuff and I found the tool: http://ga-dev-tools.appspot.com/explorer/ very useful.
But when I copy the Reg Exp into my own code as follows:
function queryCoreReportingApi(profileId) {
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': lastNDays(30),
'end-date': lastNDays(0),
'metrics': 'ga:visitors',
'dimensions': 'ga:pagePath',
'sort': '-ga:visitors',
'filters': 'ga:pagePath=~/q-\d+/.+',
'max-results': 50
}).execute(handleCoreReportingResults);
}
I can't get any result.
I found that
filters: "ga:pagePath=~/q-\d+/.+",
is changed to
filters: "ga:pagePath=~/q-d+/.+"
The \d
becomes d
and I failed to get what I want.
Why the \
is just gone? Any tips?
Thanks!
Aw, looking at the filter reference, I would suggest escaping the backslash. So technically, you would end up with double backslashes:
"ga:pagePath=~/q-\\d+/.+",
See the linked page, section Filter Expressions:
Reserved characters — The semicolon, comma, and backslash must all be backslash escaped when they appear in an expression.
Hope this helps.