Skip to content

kyrozetera/laravel-google-ads

 
 

Repository files navigation

Laravel 5.1 Latest Stable Version Total Downloads Latest Unstable Version License Build Status Code Climate Test Coverage

Google Ads API for Laravel

This project is an integration of googleads/googleads-php-lib in Laravel 5.1.

Setup

  • Run $ composer require nikolajlovenhardt/laravel-google-ads

  • Add provider

'providers' => [
    LaravelGoogleAds\LaravelGoogleAdsProvider::class,
],
  • Run $ php artisan vendor:publish to publish the configuration file config/google-ads.php and insert:
    • developerToken
    • clientId & clientSecret
    • refreshToken

Generate refresh token

This requires that the clientId and clientSecret is from a native application.

Run $ php artisan googleads:token:generate and open the authorization url. Grant access to the app, and input the access token in the console. Copy the refresh token into your configuration config/google-ads.php

Basic usage

The following example is for AdWords, but the general code applies to all products.

use Campaign;
use CampaignService;
use CampaignOperation;
use LaravelGoogleAds\AdWords\AdWordsUser;

class Service
{
    public function foo()
    {
        $user = new AdWordsUser();

        // Optionally, enable logging to capture the content of SOAP requests and responses.
        $user->LogDefaults();

        // Instantiate the desired service class by calling the get***Service method on the AdWordsUser instance.
        /** @var CampaignService $campaignService */
        $campaignService = $user->GetService('CampaignService', 'v201509');

        // Create data objects and invoke methods on the service class instance. The
        // data objects and methods map directly to the data objects and requests for
        // the corresponding web service.


        // Create new campaign structure.
        $campaign = new Campaign();
        $campaign->name = 'Campaign #' . time();
        $campaign->status = 'ACTIVE';
        $campaign->biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        $campaign->biddingStrategyConfiguration->biddingStrategyType = 'MANUAL_CPC';
        $campaign->budget = new Budget('DAILY', new Money(50000000), 'STANDARD');

        $operation = new CampaignOperation();
        $operation->operand = $campaign;
        $operation->operator = 'ADD';
        $operations[] = $operation;

        // Add campaign.
        $campaignReturnValue = $campaignService->mutate($operations);
    }

    public function bar()
    {
        // Create an AdWordsUser instance using the default constructor
        $user = new AdWordsUser();
        $user->SetClientCustomerId('INSERT_CLIENT_CUSTOMER_ID_HERE');
    }
};

Best practices

AdWords API Workshops Fall 2015

Features, requirements, support etc.

See googleads/googleads-php-lib

Dependencies

  • googleads/googleads-php-lib hosts the PHP client library for the various SOAP-based Ads APIs (AdWords, AdExchange Buyer, and DFP) at Google.

About

Google Ads API for Laravel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%