Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a function to create new remarketing audience in R #161

Closed
msheranga opened this issue Mar 7, 2018 · 6 comments
Closed

is there a function to create new remarketing audience in R #161

msheranga opened this issue Mar 7, 2018 · 6 comments

Comments

@msheranga
Copy link

msheranga commented Mar 7, 2018

What goes wrong

ga_remarketing_get() and ga_remarketing_list are exist but there is no function to create a new remarketing audience using R

@MarkEdmondson1234
Copy link
Collaborator

Not at the moment, but there is a general quest to add some more management API features https://github.com/MarkEdmondson1234/googleAnalyticsR/issues/135 - it would involve implementing this guide https://developers.google.com/analytics/devguides/config/mgmt/v3/remarketing#insert

@msheranga
Copy link
Author

msheranga commented Mar 8, 2018

Thanks. Is there way to execute R script in php file. then i am able to create a new remarketing audience. please help

@MarkEdmondson1234
Copy link
Collaborator

I don’t know how to execute R from PHP, sorry.

@msheranga
Copy link
Author

ahh ok. can i know whether function for creating remarketing audience ongoing or not started yet?

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Mar 8, 2018

If you don’t mind doing some coding then the template function is here

https://github.com/MarkEdmondson1234/autoGoogleAPI/blob/f4850822230ef2f5552c9a5f42e397d9ae027a18/googleanalyticsv3.auto/R/analytics_functions.R#L1892-L1925

#' Creates a new remarketing audience.
#' 
#' Autogenerated via \code{\link[googleAuthR]{gar_create_api_skeleton}}
#' 
#' @seealso \href{https://developers.google.com/analytics/}{Google Documentation}
#' 
#' @details 
#' Authentication scopes used by this function are:
#' \itemize{
#'   \item https://www.googleapis.com/auth/analytics.edit
#' }
#' 
#' Set \code{options(googleAuthR.scopes.selected = c(https://www.googleapis.com/auth/analytics.edit)}
#' Then run \code{googleAuthR::gar_auth()} to authenticate.
#' See \code{\link[googleAuthR]{gar_auth}} for details. 
#' 
#' @param RemarketingAudience The \link{RemarketingAudience} object to pass to this method
#' @param accountId The account ID for which to create the remarketing audience
#' @param webPropertyId Web property ID for which to create the remarketing audience
#' @importFrom googleAuthR gar_api_generator
#' @family RemarketingAudience functions
#' @export
management.remarketingAudience.insert <- function(RemarketingAudience, accountId, 
    webPropertyId) {
    url <- sprintf("https://www.googleapis.com/analytics/v3/management/accounts/%s/webproperties/%s/remarketingAudiences", 
        accountId, webPropertyId)
    # analytics.management.remarketingAudience.insert
    f <- googleAuthR::gar_api_generator(url, "POST", data_parse_function = function(x) x)
    stopifnot(inherits(RemarketingAudience, "gar_RemarketingAudience"))
    
    f(the_body = RemarketingAudience)
    
}

which uses this object (and children):

#' RemarketingAudience Object
#' 
#' @details 
#' Autogenerated via \code{\link[googleAuthR]{gar_create_api_objects}}
#' JSON template for an Analytics remarketing audience.
#' 
#' @param RemarketingAudience.audienceDefinition The \link{RemarketingAudience.audienceDefinition} object or list of objects
#' @param RemarketingAudience.stateBasedAudienceDefinition The \link{RemarketingAudience.stateBasedAudienceDefinition} object or list of objects
#' @param RemarketingAudience.stateBasedAudienceDefinition.excludeConditions The \link{RemarketingAudience.stateBasedAudienceDefinition.excludeConditions} object or list of objects
#' @param accountId Account ID to which this remarketing audience belongs
#' @param audienceDefinition The simple audience definition that will cause a user to be added to an audience
#' @param audienceType The type of audience, either SIMPLE or STATE_BASED
#' @param id Remarketing Audience ID
#' @param linkedAdAccounts The linked ad accounts associated with this remarketing audience
#' @param linkedViews The views (profiles) that this remarketing audience is linked to
#' @param name The name of this remarketing audience
#' @param stateBasedAudienceDefinition A state based audience definition that will cause a user to be added or removed from an audience
#' @param webPropertyId Web property ID of the form UA-XXXXX-YY to which this remarketing audience belongs
#' 
#' @return RemarketingAudience object
#' 
#' @family RemarketingAudience functions
#' @export
RemarketingAudience <- function(RemarketingAudience.audienceDefinition = NULL, RemarketingAudience.stateBasedAudienceDefinition = NULL, 
    RemarketingAudience.stateBasedAudienceDefinition.excludeConditions = NULL, accountId = NULL, 
    audienceDefinition = NULL, audienceType = NULL, id = NULL, linkedAdAccounts = NULL, 
    linkedViews = NULL, name = NULL, stateBasedAudienceDefinition = NULL, webPropertyId = NULL) {
    structure(list(RemarketingAudience.audienceDefinition = RemarketingAudience.audienceDefinition, 
        RemarketingAudience.stateBasedAudienceDefinition = RemarketingAudience.stateBasedAudienceDefinition, 
        RemarketingAudience.stateBasedAudienceDefinition.excludeConditions = RemarketingAudience.stateBasedAudienceDefinition.excludeConditions, 
        accountId = accountId, audienceDefinition = audienceDefinition, audienceType = audienceType, 
        id = id, kind = `analytics#remarketingAudience`, linkedAdAccounts = linkedAdAccounts, 
        linkedViews = linkedViews, name = name, stateBasedAudienceDefinition = stateBasedAudienceDefinition, 
        webPropertyId = webPropertyId), class = "gar_RemarketingAudience")
}

It should work under your authentication, but the returned call may need some parsing.

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Mar 30, 2018

How this could look:

adword_list <- ga_adwords_list(123456, "UA-123456-1")

adword_link <- ga_adword(adword_list$id[[1]])

segment_list <- ga_segment_list()$items$definition

my_remarketing1 <- ga_remarketing_build(segment_list[[1]], 
                      state_duration = "TEMPORARY",
                      membershipDurationDays = 90, 
                      daysToLookBack = 14)
my_remarketing2 <- ga_remarketing_build(segment_list[[2]], 
                      state_duration = "PERMANENT",
                      membershipDurationDays = 7, 
                      daysToLookBack = 31)

# state based only can include exclusions
ga_remarketing_create(adwords_link = adword_link,
                     include = my_remarketing1, exclude = my_remarketing2,
                     audienceType = "STATE_BASED", name = "my_remarketing_seg1")

MarkEdmondson1234 added a commit that referenced this issue Nov 7, 2018
building remarketing objects (#161) and add assert_that_ifnn()
MarkEdmondson1234 added a commit that referenced this issue Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants