0

Datepicker in datasources.

Hi, i am having some trouble getting a variable into the data source URL.

I have made a date-picker, that sets a value to the variables $start_date and $end_date.

As i understand, the way google analytics works with unique users, is that you have to make a data request every time you change the date range. So what i want to do is something like

https://www.googleapis.com/analytics/v3/data/ga?ids=ga%<ID>&start-date=$start_date&end-date=end_date&metrics=ga%3Ausers

I have tried the following

https://www.googleapis.com/analytics/v3/data/ga?ids=ga%<ID>&start-date={date.set($start_date,"yyyy-MM-dd")}&end-date={date.set($end_date,"yyyy-MM-dd")}&metrics=ga%3Ausers

But to no avail, am i on the right track?

Thanks,

Steffen

4 comments

  • 0
    Avatar
    Marketing Creuna

    Update,

    I have made the datepicker such that the raw data is formatted yyyy-MM-dd, so it should be the right format when the url gets it, the error i get when trying to execute

    https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A<ID>&dimensions=ga%3AisMobile&metrics=ga%3Ausers,ga%3Asessions&start-date={probs.start_date}&end-date={probs.end_date}

    is (and the same when i use the date.set function)

    Service responded with exception status (400): {"error":{"errors":[{"domain":"global","reason":"invalidParameter","message":"Invalid value '{probs.end_date}'. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'","locationType":"parameter","location":"end-date"},{"domain":"global","reason":"invalidParameter","message":"Invalid value '{probs.start_date}'. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'","locationType":"parameter","location":"start-date"}],"code":400,"message":"Invalid value '{probs.end_date}'. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'"}}
     
    As far as i can see it does not get the to the variable at all.
  • 0
    Avatar
    Janice Janczyn

    Hi Steffen,

    You are very close!  The variables in you datasource query should be prefixed with "props" instead of "probs". That is (I've replaced all %3A with colons for readability; %3A is the URL-encoded form of the colon symbol):

         https://www.googleapis.com/analytics/v3/data/ga?ids=ga:<ID>&dimensions=ga:isMobile&metrics=ga:users,ga:sessions&start-date={props.start_date}&end-date={props.end_date}

    where <ID> is replaced with your GA profile ID, so the parameter looks something like

         ids=ga:1234567

     

    Thanks,
            Janice

  • 0
    Avatar
    Marketing Creuna

    Hi Janice,

    Thanks, it worked! Now i have another issue,

    I would like to define a compare range. I.e. if i am looking at the

    1. June ($start_date) - 30. June($end_date) (30 days)

    i would like to define

    $start_date_comp = $start_date - ($end_date - $start_date +1 ) = 2. May (The math might be of on this one)
    $end_date_comp = $start_date - 1 = 31. May (Again a 30 day period)

    When i push the update button, to define the range. I have been playing around with the SET function, but i can only get one of them to change at a time.

    Any advice?

    Thanks

    Steffen

     

  • 0
    Avatar
    Janice Janczyn

    Hi Steffen,

    One way to approach this is to 2 create hidden User Input Controls to set your start_date_comp & end_date_comp variables. The formulas would be something like:

       start_date_comp drop-down:  DATE_ADD( $start_date, days, -COUNT_DAYS( $start_date, $end_date) )
       end_date_comp drop-down:   DATE_ADD( $end_date,  days, -COUNT_DAYS( $start_date, $end_date) )

     

    Thank you,
                 Janice

Please sign in to leave a comment.