dsuikgi9199 2017-04-06 10:15
浏览 66
已采纳

如何向Google Analytics api请求添加维度

The examples given by Google are a very simple query request. however, when I try to add more parameters, it will throw errors and I don't exactly know how to structure the syntax.

This simple query request works:

 return $analytics->data_ga->get(
  'ga:' . $viewID,
  $startDate,
  $endDate,
  'ga:sessions'
);

I need more information and I've already used Google's Query Explorer to get the Information but I just don't know how to structure my PHP query. The Information I want to request is also ga:pageviews as another metric, ga:pagePath and ga:pageTitle as dimensions and also a filter. I already fail at adding a second metric.

I have tried this:

return $analytics->data_ga->get(
  'ga:' . $viewID,
  $startDate,
  $endDate,
  'ga:sessions',
  'ga:pageviews'
);

simply adding it doesn't work. Can anyone point me in the correct direction?

  • 写回答

1条回答 默认 最新

  • dongli2000 2017-04-06 10:23
    关注

    Dimensions need to be added as option parms

    //Adding Dimensions 
    $params = array('dimensions' => 'ga:userType'); 
    // requesting the data  
    $data = $service->data_ga->get("ga:89798036", "2014-12-14", "2014-12-14", "ga:users,ga:sessions", $params );    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 spyder运行重复
    • ¥15 有偿做一个PUBG识别枪械配合罗技宏的
    • ¥15 我考考你,这代码是对的还是错的?
    • ¥15 我用C语言easyx图形库绘制了一个3d游戏方框透视,但进入游戏时候鼠标准星对准方框边缘 鼠标光标就会弹出来这是啥情况怎样让光标对准绘制的方框点击鼠标不弹出光标好烦这样
    • ¥20 用Power Query整合的问题
    • ¥20 基于python进行多背包问题的多值编码
    • ¥15 相同型号电脑与配置,发现主板有一台貌似缺少了好多元器件似的,会影响稳定性和使用寿命吗?
    • ¥15 C语言:数据子序列基础版
    • ¥20 powerbulider 导入excel文件,显示不完整
    • ¥15 paddle训练自己的数据loss降不下去