douhe8981 2016-05-10 10:59
浏览 70
已采纳

如何使用谷歌搜索控制台api获得我的网站的平均位置?

My website is connected to google search console API. I would like to make a query that return the average position on my site in google. Is it possible? i would like to get the average including ALL the keywords? does any one know any query for this? The server side is written with php. I can make a query that return me my website position but only by specific keyword that i need to choose. for example:

$query = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
    $query->setSearchType('web');
    $query->setDimensions(array('query', 'country', 'device'));
    $query->setStartDate($StartDate);
    $query->setEndDate($EndDate);

    $filterDevice = new Google_Service_Webmasters_ApiDimensionFilter();
    $filterDevice->setDimension('device');
    $filterDevice->setOperator('equals');
    $filterDevice->setExpression('DESKTOP');

    $filterCountry = new Google_Service_Webmasters_ApiDimensionFilter();
    $filterCountry->setDimension('country');
    $filterCountry->setOperator('equals');
    $filterCountry->setExpression('fr');

    *******THIS IS FOR A SPECIFIC KEY WORD! ********

    $filterQuery = new Google_Service_Webmasters_ApiDimensionFilter();
    $filterQuery->setDimension('query');
    $filterQuery->setOperator('equals');
    $filterQuery->setExpression($keyWord);

    ************************************************

    $filtergroup = new Google_Service_Webmasters_ApiDimensionFilterGroup();
    $filtergroup->setGroupType('and');
    //$filtergroup->setFilters(array($filterDevice,$filterCountry,$filterQuery));
    $filtergroup->setFilters(array($filterDevice,$filterCountry));
    $query->setDimensionFilterGroups(array($filtergroup));

    $response = $webmaster->searchanalytics->query($clientSite,$query);

If i do not send any keyword (query) the respond is a lot of keywords and the position of each one, as shown

{
"0": {
    "clicks": 3164,
    "ctr": 0.373686075351,
    "impressions": 8467,
    "keys": {
        "0": "KEYWORD_EXAMPLE",
        "1": "fr",
        "2": "DESKTOP"
    },
    "position": 1.00035431676
},
"1": {
    "clicks": 267,
    "ctr": 0.765042979943,
    "impressions": 349,
    "keys": {
        "0": "KEYWORD_EXAMPLE",
        "1": "fr",
        "2": "DESKTOP"
    },
    "position": 1.03438395415
},
"2": {
    "clicks": 204,
    "ctr": 0.0491684743312,
    "impressions": 4149,
    "keys": {
        "0": "KEYWORD_EXAMPLE",
        "1": "fr",
        "2": "DESKTOP"
    },
    "position": 6.57869366112
},
"3": {
    "clicks": 135,
    "ctr": 0.308924485126,
    "impressions": 437,
    "keys": {
        "0": "KEYWORD_EXAMPLE",
        "1": "fr",
        "2": "DESKTOP"
    },
    "position": 1
},

TNX!!! :)

  • 写回答

1条回答 默认 最新

  • duandi1919 2016-05-10 11:48
    关注

    I figure it out...some of the $filters did it. if you will send a query without filter it it will work. for example:

    $query = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
        $query->setSearchType('web');
        $query->setStartDate($StartDate);
        $query->setEndDate($EndDate);
    
        $filtergroup = new Google_Service_Webmasters_ApiDimensionFilterGroup();
        $filtergroup->setGroupType('and');
        //***REDUCE THIS LINE! -> $filtergroup->setFilters(array($filterDevice));***//
        $query->setDimensionFilterGroups(array($filtergroup));
    
        $response = $webmaster->searchanalytics->query($clientSite,$query);
    

    The result is:

    "0": {
        "clicks": 14635,
        "ctr": 0.0629018670701,
        "impressions": 232664,
        "keys": null,
        "position": 15.502961352
    }
    

    I know this is my correct position because you can see it on your dashboard in google site. (search console GUI).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Ios抖音直播的时候如何添加自定义图片在直播间!
  • ¥60 riscv-pulpino总线上挂载axi从机
  • ¥15 ssh登录页面的问题
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥15 stm32 串口通讯过程中的问题
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名