【问题标题】:Importing data to google analytics with R使用 R 将数据导入谷歌分析
【发布时间】:2016-08-23 17:44:25
【问题描述】:

我想用 R 自动将数据上传到 GoogleAnalytics,但找不到方法。

到目前为止,我已经这样做了:

  1. 根据googleAuthR包获取google auth token:

token <- Authentication$public_fields$token

  1. 生成上传端点的url:

    url.template <- "https://www.googleapis.com/upload/analytics/v3/management/accounts/%1$i/webproperties/%2$s/customDataSources/%3$s/uploads" url <- sprintf(url.template, account.id, web.property.id, data.source)

  2. 使用 httr 包调用 POST:

    httr::content_type("text/csv") httr::POST(url = url, body = list(y = httr::upload_file("ga-product-import.csv")), 配置=令牌, 编码=“多部分” )

到目前为止,我收到了 400 条回复。

我也试过这个:

f <- gar_api_generator(url,
                       "POST",
                       data_parse_function = function(x) x)
f(the_body =  list(y = httr::upload_file("ga-product-import.csv")))

但收到此错误:

错误:没有方法 asJSON S3 类:form_file 错误 the_request$status_code : $ 运算符对原子向量无效

【问题讨论】:

  • 如果您运行来自googleAuthR 的示例之一会发生什么?
  • @Hack-R 我没有看到任何文件上传的例子,你能给一个链接
  • @Hack-R 我试过gar_api_generator,但这似乎也不起作用。
  • googleAnalyticsR现在有成本数据导入github.com/MarkEdmondson1234/googleAnalyticsR/blob/master/R/…

标签: r import google-analytics


【解决方案1】:

googleAnalyticsR 依赖于 googleAuthR,并具有成本数据上传功能,帮助位于 ?ga_custom_upload

【讨论】:

  • 谢谢你。不幸的是,我还没有机会尝试。我会尽快恢复。
  • 回到这里并设法将自定义数据上传到 GA,非常感谢!
猜你喜欢
  • 2017-09-27
  • 2017-05-08
  • 1970-01-01
  • 2023-03-24
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 2019-03-03
  • 1970-01-01
相关资源
最近更新 更多