PHP example/reporting/GetHotelAdsPerformance of Google Ads API v0_7 not working

208 views
Skip to first unread message

Didier Roy

unread,
Mar 1, 2019, 2:34:43 PM3/1/19
to AdWords API and Google Ads API Forum
Hi All

I am trying to get hotel performance report using below code and get this error : 

PHP Fatal error:  Call to undefined method Google\Ads\GoogleAds\V0\Services\GoogleAdsRow::getHotelCheckInDayOfWeek() in /home/reports/gha/google-ads-php/examples/Reporting/GetHotelAdsPerformance.php on line 132

line 132 is  $googleAdsRow->getHotelCheckInDayOfWeek()

Does anybody has a working example of how to get segment values from the query results?

thanks


    public static function runExample(GoogleAdsClient $googleAdsClient, $customerId)
    {
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
        // Creates a query that retrieves hotel-ads statistics for each campaign and ad group.
        // Returned statistics will be segmented by the check-in day of week and length of stay.
        $query =
            "SELECT campaign.id, "
                . "campaign.advertising_channel_type, "
                . "ad_group.id, "
                . "ad_group.status, "
                . "metrics.impressions, "
                . "metrics.hotel_average_lead_value_micros, "
                . "segments.hotel_check_in_day_of_week, "
                . "segments.hotel_length_of_stay "
            . "FROM hotel_performance_view "
            . "WHERE segments.date DURING LAST_7_DAYS "
                . "AND campaign.advertising_channel_type = 'HOTEL' "
                . "AND ad_group.status = 'ENABLED' "
            . "ORDER BY metrics.impressions DESC "
            . "LIMIT 50";

        // Issues a search request by specifying page size.
        $response =
            $googleAdsServiceClient->search($customerId, $query, ['pageSize' => self::PAGE_SIZE]);

        // Iterates over all rows in all pages and prints the requested field values for each row.
        foreach ($response->iterateAllElements() as $googleAdsRow) {
            /** @var GoogleAdsRow $googleAdsRow */
            // Note: A mapping of enum names to values for days of week can be found at
            // DayOfWeek.php.
            printf(
                "Ad group ID %d in campaign ID %d "
                . "with hotel check-in on %d and %d day(s) of stay "
                . "had %d impression(s) and %d average lead value (in micros) "
                . "during the last 7 days.%s",
                $googleAdsRow->getAdGroup()->getId()->getValue(),
                $googleAdsRow->getCampaign()->getId()->getValue(),
                $googleAdsRow->getHotelCheckInDayOfWeek(),
                $googleAdsRow->getHotelLengthOfStay()->getValue(),
                $googleAdsRow->getMetrics()->getImpressions()->getValue(),
                $googleAdsRow->getMetrics()->getHotelAverageLeadValueMicros()->getValue(),
                PHP_EOL
            );
        }
    }

googleadsapi...@google.com

unread,
Mar 1, 2019, 5:17:10 PM3/1/19
to AdWords API and Google Ads API Forum
Hi Didier,

Could you please try the code as in the sample and see if that fixes your issue? 

$googleAdsRow->getSegments()->getHotelCheckInDayOfWeek(),
$googleAdsRow->getSegments()->getHotelLengthOfStay()->getValue(),


Thanks,
Sreelakshmi, Google Ads API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

Didier Roy

unread,
Mar 4, 2019, 8:12:51 AM3/4/19
to AdWords API and Google Ads API Forum
thank you it works
Reply all
Reply to author
Forward
0 new messages