How to pass specific URL parameters in Google Data Studio?

8.7k views Asked by At

We need help understanding how to generate a specific URL with parameters to direct users to our report. We've been through the Google data studio documentation about direct links here.

We're still struggling to understand how to make it work, and we believe the potential answer would benefit all people who are looking for a similar solution.

A brief explanation - we have a bunch of categories (towns) within our website, with the potential to have even more in a short period. Instead of creating a report for each category, we would like to save time and resources by creating only one report that should display results based on the passed parameters via URL. The parameter would be only one - a category. Furthermore, our script will generate the report URL with the required parameter that we can then display to our editors.

We know this is somewhat covered within the documentation, but we would appreciate it if someone can come up with more specific instructions on how to make it work.

2

There are 2 answers

1
Yeisson Graciano On

I know I'm writing very late, but I hope it helps some other people who are looking for the same thing, it has helped me, especially passing the parameters to the connection to the database, to which the variable is assigned in the where and filter the information that is needed. all from the url:

https://developers.google.com/datastudio/connector/data-source-parameters#set_url_parameters

0
mindeh On

Expanding on Yeisson's answer.

Report parameters are passed via query parameter params.

Value is URL-encoded JSON object with all report parameters that you want to set. So parameter values such as

{
  "ds0.includeToday": true,
  "ds0.units": "Metric",
  "ds1.countries": ["Canada", "Mexico"],
  "ds1.labelName": "Population"
}

would be encoded this way (JavaScript):

const json = JSON.stringify({
  "ds0.includeToday": true,
  "ds0.units": "Metric",
  "ds1.countries": ["Canada", "Mexico"],
  "ds1.labelName": "Population"
})
// "{\"ds0.includeToday\":true,\"ds0.units\":\"Metric\",\"ds1.countries\":[\"Canada\",\"Mexico\"],\"ds1.labelName\":\"Population\"}" 

const encodedParams = encodeURIComponent("{\"ds0.includeToday\":true,\"ds0.units\":\"Metric\",\"ds1.countries\":[\"Canada\",\"Mexico\"],\"ds1.labelName\":\"Population\"}")
// "%7B%22ds0.includeToday%22%3Atrue%2C%22ds0.units%22%3A%22Metric%22%2C%22ds1.countries%22%3A%5B%22Canada%22%2C%22Mexico%22%5D%2C%22ds1.labelName%22%3A%22Population%22%7D"

and then passed to the report like this:

https://datastudio.google.com/reporting/REPORT_ID/page/PAGE_ID?params=%7B%22ds0.includeToday%22%3Atrue%2C%22ds0.units%22%3A%22Metric%22%2C%22ds1.countries%22%3A%5B%22Canada%22%2C%22Mexico%22%5D%2C%22ds1.labelName%22%3A%22Population%22%7D