Yes, you can retrieve Google Ad Manager earnings data and display it directly on your Laravel website. One way to accomplish this is by using the Google Ad Manager API to fetch the earnings information for each website and then displaying it as desired on your Laravel website.
Here is a simplified example of how you can integrate the Google Ad Manager API in a Laravel application to retrieve earnings data per website:
1. Set up Google Ad Manager API Access:
- Enable the Google Ad Manager API in the Google Cloud Platform (GCP) Console.
- Create a service account with appropriate permissions that allows access to the API.
- Generate a JSON key file for the service account.
2. Install Required Packages:
- Include the required Google API client library in your Laravel application by running the following command in your project root directory:
```
composer require google/apiclient
```
3. Configure API Access in Laravel:
- Place the JSON key file in a secure location within your Laravel project.
- Add the following configuration details to your `config/services.php` file:
```php
'google' => [
'application_name' => 'Your Google Ad Manager App Name',
'client_id' => 'Your GCP Console Client ID',
'client_secret' => 'Your GCP Console Client Secret',
'redirect' => '
http://localhost:8000/callback',
'key_file' => storage_path('path/to/your/json-key-file.json'),
'network_code' => 'Your Google Ad Manager Network Code',
],
```
4. Create an API Helper Class:
- Create a new class, for example `GoogleAdManagerHelper`, to handle interactions with the Google Ad Manager API.
- Add methods to authenticate with the API, fetch earnings for each website using the API, and return the earnings data.
```php
<?php
namespace App\Helpers;
use Google\AdsApi\AdManager\AdManagerSessionBuilder;
use Google\AdsApi\AdManager\AdManagerServices;
use Google\AdsApi\AdManager\v202102\ReportQuery;
use Google\AdsApi\AdManager\v202102\ReportService;
use Google\AdsApi\Auth\OAuth2TokenBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;
class GoogleAdManagerHelper
{
public static function getEarningsForWebsites($websites)
{
// Authenticate with Google Ad Manager API
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile(config('services.google.key_file'))
->build();
$session = (new Ad