{"id":14974442,"url":"https://github.com/edujugon/laravel-google-ads","last_synced_at":"2025-04-09T08:09:28.067Z","repository":{"id":17483356,"uuid":"81458331","full_name":"Edujugon/laravel-google-ads","owner":"Edujugon","description":"Google Adwords API for Laravel","archived":false,"fork":false,"pushed_at":"2022-08-12T13:59:35.000Z","size":437,"stargazers_count":68,"open_issues_count":24,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-30T07:29:49.610Z","etag":null,"topics":["adwords","adwords-api","google","laravel","laravel-5-package","laravel-6-package","laravel5"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Edujugon.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-09T14:26:43.000Z","updated_at":"2024-06-18T18:25:35.000Z","dependencies_parsed_at":"2022-07-26T18:02:31.991Z","dependency_job_id":null,"html_url":"https://github.com/Edujugon/laravel-google-ads","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2Flaravel-google-ads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2Flaravel-google-ads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2Flaravel-google-ads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2Flaravel-google-ads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Edujugon","download_url":"https://codeload.github.com/Edujugon/laravel-google-ads/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999861,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adwords","adwords-api","google","laravel","laravel-5-package","laravel-6-package","laravel5"],"created_at":"2024-09-24T13:50:34.240Z","updated_at":"2025-04-09T08:09:28.048Z","avatar_url":"https://github.com/Edujugon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google Adwords API for Laravel\n\nSimple and easy to use API for your Google Adwords.\n\n##  Installation\n\n##### Type in console:\n\n```\ncomposer require edujugon/laravel-google-ads\n```\n\n##### Laravel 5.5 or higher?\n\nThen you don't have to either register or add the alias, this package uses Package Auto-Discovery's feature, and should be available as soon as you install it via Composer.\n\n##### (Only for Laravel 5.4 or minor) Register the GoogleAds service by adding it to the providers array.\n\n```\n'providers' =\u003e array(\n        ...\n        Edujugon\\GoogleAds\\Providers\\GoogleAdsServiceProvider::class\n    )\n```\n\n##### (Only for Laravel 5.4 or minor) Let's add the Alias facade, add it to the aliases array.\n\n```\n'aliases' =\u003e array(\n        ...\n        'GoogleAds' =\u003e Edujugon\\GoogleAds\\Facades\\GoogleAds::class,\n    )\n```\n\n##### Publish the package's configuration file to the application's own config directory.\n\n```\nphp artisan vendor:publish --provider=\"Edujugon\\GoogleAds\\Providers\\GoogleAdsServiceProvider\" --tag=\"config\"\n```\n\nThe above command will generate a new file under your laravel app config folder called `google-ads.php`\n\n##  Configuration\n\nUpdate the `google-ads.php` file with your data.\n\n```\n'env' =\u003e 'test',\n'production' =\u003e [\n    'developerToken' =\u003e \"YOUR-DEV-TOKEN\",\n    'clientCustomerId' =\u003e \"CLIENT-CUSTOMER-ID\",\n    'userAgent' =\u003e \"YOUR-NAME\",\n    'clientId' =\u003e \"CLIENT-ID\",\n    'clientSecret' =\u003e \"CLIENT-SECRET\",\n    'refreshToken' =\u003e \"REFRESH-TOKEN\"\n],\n'test' =\u003e [\n    'developerToken' =\u003e \"YOUR-DEV-TOKEN\",\n    'clientCustomerId' =\u003e \"CLIENT-CUSTOMER-ID\",\n    'userAgent' =\u003e \"YOUR-NAME\",\n    'clientId' =\u003e \"CLIENT-ID\",\n    'clientSecret' =\u003e \"CLIENT-SECRET\",\n    'refreshToken' =\u003e \"REFRESH-TOKEN\"\n],\n```\n\u003e   'env' key accepts one of the following values: test / production\n\n##  Generate refresh token\n\n\u003e   Notice that it will take the `clientID` and `clientSecret` from `google-ads.php` config file based on the `env` value.\n\nType in console:\n\n```\nphp artisan googleads:token:generate\n```\n\n*   Visit the URL it shows, grant access to your app and input the access token in console.\n*   Then copy the fresh token in `google-ads.php` config file.\n\n\u003e   Remember to copy that token in the correct section (test/production).Depends on your `env` value.\n\n##  Usage samples\n\nInstance the main wrapper class:\n\n```\n$ads = new GoogleAds();\n```\n\u003e   Do not forget to put at the top of the file the use statement:\n```\nuse Edujugon\\GoogleAds\\GoogleAds;\n```\n\nAll needed configuration data is took from `google-ads.php` config file. But you always may pass new values on the fly if required.\n\nYou may override the default environment value calling the env method:\n\n```\n$ads-\u003eenv('test');\n```\n\nAlso, you may get the env value by getEnv method:\n\n```\n$ads-\u003egetEnv();\n```\n\nIf need to override the oAuth details, just call the oAuth method like so:\n\n```\n$ads-\u003eoAuth([\n            'clientId' =\u003e 'test',\n            'clientSecret' =\u003e 'test',\n            'refreshToken' =\u003e 'TEST'\n\n        ]);\n```\n\nSame with session. If need to override the default values on the fly, just do it by calling session method:\n\n```\n$ads-\u003esession([\n    'developerToken' =\u003e 'token',\n    'clientCustomerId' =\u003e 'id'\n]);\n```\n\nAll the above methods can be chained as follows:\n\n```\n$ads-\u003eenv('test')\n    -\u003eoAuth([\n        'clientId' =\u003e 'test',\n        'clientSecret' =\u003e 'test',\n        'refreshToken' =\u003e 'TEST'\n\n    ])\n    -\u003esession([\n        'developerToken' =\u003e 'token',\n        'clientCustomerId' =\u003e 'id'\n    ]);\n```\n\n### Google Services\n\nFor Google Ads Services you only have to call the service method:\n\n```\n$ads-\u003eservice(CampaignService::class);\n```\n\nor\n\n```\n$ads-\u003eservice(AdGroupService::class);\n```\n\nor\n\n```\n$ads-\u003eservice(AdGroupAdService::class);\n```\n\nor Any google ads services available under `Google\\AdsApi\\AdWords\\v201809\\cm` folder.\n\nAlso you can use the global helper in order the get an instance of Service.\n\n```\n$service = google_service(CampaignService::class)\n```\n\nTo retrieve a list of campaigns, do like follows:\n\n```\n$ads-\u003eservice(CampaignService::class)\n    -\u003eselect(['Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate'])\n    -\u003eget();\n```\n\n\u003e Notice the method `select` is required and you have to use it in order to set the fields you wanna get from the campaign.\n\nIf need to add a condition to your search you can use the `where` method like follows:\n\n```\n$ads-\u003eservice(CampaignService::class)\n    -\u003eselect(['Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate'])\n    -\u003ewhere('Id IN [752331963,795625088]')\n    -\u003eget();\nor\n\n$ads-\u003eservice(CampaignService::class)\n    -\u003eselect(['Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate'])\n    -\u003ewhere('Id = 752331963')\n    -\u003eget();\n```\n\u003e Notice! You may also set more than one condition. Do so calling `where` method as many times as you need.\n\nAvailable Operators: \n\n```\n= | != | \u003e | \u003e= | \u003c | \u003c= | IN | NOT_IN | STARTS_WITH | STARTS_WITH_IGNORE_CASE |\nCONTAINS | CONTAINS_IGNORE_CASE | DOES_NOT_CONTAIN | DOES_NOT_CONTAIN_IGNORE_CASE |\nCONTAINS_ANY | CONTAINS_NONE | CONTAINS_ALL\n```\n\nIf need to limit your search you may use `limit` method:\n\n```\n$ads-\u003eservice(CampaignService::class)\n    -\u003eselect(['Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate'])\n    -\u003elimit(5)\n    -\u003eget();\n    \n```\n\nAlso you can order by a field:\n\n```\n$ads-\u003eservice(CampaignService::class)\n    -\u003eselect(['Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate'])\n    -\u003eorderBy('Name')\n    -\u003elimit(5)\n    -\u003eget();\n\n```\n\nNotice that the `get` method returns an instance of ServiceCollection. \nThat custom collection has its own methods.\n\nOnce you have the collection, you can again filter with the where method\n\n```\n$campaignService = $ads-\u003eservice(CampaignService::class);\n\n$results = $campaignService-\u003eselect('CampaignId','CampaignName')-\u003eget();\n\n//You can also add any where condition on the list.\n$campaign = $results-\u003ewhere('id',1341312);\n\n```\n\nAlso you can call the `set` method to change any value\n\n```\n$campaign = $results-\u003ewhere('id',$this-\u003etestedCampaignId)-\u003eset('name','hello !!');\n\n```\n\nFinally you can persist those changes with the `save` method:\n\n```\n$campaign = $campaign-\u003esave();\n```\n\nSave method returns an array of updated elements or false if nothing updated.\n\n\u003e Important!! notice that it will persist all elements that are in the collection.\n\nYou can get the list as illuminate collection simply calling `items` method.\n\n### Google Reports\n\nTo start with google reporting just call `report` method from the main wrapper:\n\n```\n$report = $ads-\u003ereport();\n```\n\nor use the global helper like follows:\n\n```\n$report = google_report();\n```\n\nIt will return an instance of `Edujugon\\GoogleAds\\Reports\\Report`\n\nNow, you have a set of method to prepare the google ads report:\n\n```\n$obj = $ads-\u003ereport()\n            -\u003efrom('CRITERIA_PERFORMANCE_REPORT')\n            -\u003eduring('20170101','20170210')\n            -\u003ewhere('CampaignId = 752331963')\n            -\u003eselect('CampaignId','AdGroupId','AdGroupName','Id', 'Criteria', 'CriteriaType','Impressions', 'Clicks', 'Cost', 'UrlCustomParameters')\n            -\u003egetAsObj();\n```\n\nIn the above methods, the mandatory ones are `from` and `select`\n\n\u003e   Notice that in `during` method you have to pass the dates as a string like YearMonthDay\n\nYou may also want to set more than one condition. Use Where clause as many times as you need like follows:\n\n```\n$obj = $ads-\u003ereport()\n            -\u003efrom('CRITERIA_PERFORMANCE_REPORT')\n            -\u003ewhere('Clicks \u003e 10')\n            -\u003ewhere('Cost \u003e 10')\n            -\u003ewhere('Impressions \u003e 1')\n            -\u003eselect('CampaignId','AdGroupId','AdGroupName','Id', 'Criteria', 'CriteriaType','Impressions', 'Clicks', 'Cost', 'UrlCustomParameters')\n            -\u003egetAsObj();\n```\nAvailable Operators: \n\n```\n= | != | \u003e | \u003e= | \u003c | \u003c= | IN | NOT_IN | STARTS_WITH | STARTS_WITH_IGNORE_CASE |\nCONTAINS | CONTAINS_IGNORE_CASE | DOES_NOT_CONTAIN | DOES_NOT_CONTAIN_IGNORE_CASE |\nCONTAINS_ANY | CONTAINS_NONE | CONTAINS_ALL\n```\n\nWant to exclude any field? Just do it like follows:\n\n```\n$obj = $ads-\u003ereport()\n           -\u003efrom('SHOPPING_PERFORMANCE_REPORT')\n           -\u003eselect(\\Edujugon\\GoogleAds\\Facades\\GoogleAds::fields()-\u003eof('SHOPPING_PERFORMANCE_REPORT')-\u003easList())\n           -\u003eexcept('SearchImpressionShare','ExternalConversionSource','Ctr','Cost','Date','Week','Year','AverageCpc','Clicks','ClickType','ConversionCategoryName','ConversionTrackerId','ConversionTypeName')\n            -\u003egetAsObj();\n```\n\n\nIf want to see the retrieve items, just get so by `result` property of the object returned:\n\n```\n$items = $obj-\u003eresult;\n```\n\n\u003e Notice that it is a Collection. So you have all collection methods available.\n \nIf need the report in another format, just call `format` method before getting the report:\n\n```\n$string = $ads-\u003ereport()\n            -\u003eformat('CSVFOREXCEL')\n            -\u003eselect('CampaignId','AdGroupId','AdGroupName','Id', 'Criteria', 'CriteriaType','Impressions', 'Clicks', 'Cost', 'UrlCustomParameters')\n            -\u003efrom('CRITERIA_PERFORMANCE_REPORT')\n            -\u003egetAsString();\n```\n\nTo see the available report formats:\n\n```\n$ads-\u003ereport()-\u003egetFormats()\n```\n\nTo see what fields are available for a specific report type you can do like follows:\n\n```\n$fields = $ads-\u003ereport()-\u003efrom('CRITERIA_PERFORMANCE_REPORT')-\u003egetFields();\n```\n\n\nIf want to know what report types are available, just do like follow:\n\n```\n$ads-\u003ereport()-\u003egetTypes();\n```\n\nThere are 3 output formats for the report. It can be as object, as stream, as string.\n\n```\ngetAsString();\ngetStream();\ngetAsObj();\n```\n\nAlso you can save the report in a file:\n\n```\n$saved = $ads-\u003ereport()\n             -\u003eselect('CampaignId','AdGroupId','AdGroupName','Id', 'Criteria', 'CriteriaType','Impressions', 'Clicks', 'Cost', 'UrlCustomParameters')\n             -\u003efrom('CRITERIA_PERFORMANCE_REPORT')\n             -\u003esaveToFile($filePath)\n```\n\n\u003e The above code will create a file in the passed path returning true if everything was fine. \n\n##  API Documentation\n\n[Full API List](https://edujugon.github.io/laravel-google-ads/build/master/Edujugon/GoogleAds/GoogleAds.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedujugon%2Flaravel-google-ads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedujugon%2Flaravel-google-ads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedujugon%2Flaravel-google-ads/lists"}