doAuthMacro: Quick setup of shinyGA authentication

Description Usage Arguments Value See Also Examples

Description

This function calls all the other authentication functions so you can quick start. Sacrifices customisation for speed.

Usage

1
2
doAuthMacro(input, output, session, securityCode, client.id, client.secret,
  type = "analytics", customScopes = NULL)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

securityCode

A unique session code, such as from createCode()

client.id

The client ID taken from the Google API Console.

client.secret

The client secret taken from the Google API Console.

type

Type of Google Authentication. c("analytics").

customScopes

If not NULL, then a chacter vector of Google scopes to authenticate.

Value

For Analytics:

A named list. See example for uses in shinyServer().

token

Google Authentication Token needed for API calls.

table

Table of Google Analytics Profiles needed for rollupGA.

It also outputs the link users need to click on to authenticate as output$AuthGAURL. Put this in your ui.r somewhere by using uiOutput("AuthGAURL")

For Analytics, the function will also create the outputs for an authentication menu. The user needs to choose their Account, Web Property and View for the GA API to work. The menu outputs are per the defaults of renderAuthDropdownRow

Also outputs a DataTable called 'output$GAProfile' for use in ui.r as renderDataTable('GAProfile')

See Also

Authentication macros renderAuthDropdownRow and authDropdownRow

Other authentication functions: authReturnCode; createCode; shinygaGetTokenURL; shinygaGetToken

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 

securityCode <- createCode()

shinyServer(function(input, output, session)){

  ## returns list of token and profile.table
  ## client info taken from Google API console.
  auth <- doAuthMacro(input, output, session,
                      securityCode,
                      client.id     = "xxxxx.apps.googleusercontent.com",
                      client.secret = "xxxxxxxxxxxx",
                      type          = "analytics"
                      )

  ga.token         <- auth$token
  profile.table    <- auth$table

  ## call the token for API calls

  gadata <- reactive({

    rollupGA(GAProfileTable = profile.table(),
             dimensions     = 'ga:date',
             start_date     = '2014-03-13',
             end_date       = '2015-03-13'
             metrics        = 'ga:sessions',
             ga             = ga.token())
                 })

  }

## End(Not run)

MarkEdmondson1234/shinyga documentation built on May 7, 2019, 3:34 p.m.