Package: django-google-adwords
Djangomodelling and helpers for theGoogle Adwords API.UsingCeleryto process tasks in the background the provided models include
methods to retrieve and store data for Accounts, Campaigns, Ad Groups and Ads to
your database for further processing.Currently Google Adwords API versionv201506is supported.InstallationYou can install django-google-adwords either via the Python Package Index (PyPI)
or from github.To install using pip;pipinstalldjango-google-adwordsFrom github;pipinstallgit+https://github.com/alexhayes/django-google-adwords.gitSettingsdjango-google-adwordsusesdjango-appconfto set default settings, of
which there are quite a lot. Out of the box you only need to set the required
settings however you will most likely want to change the Celery queues settings.RequiredYou must place the following in your django settings file.GOOGLEADWORDS_CLIENT_ID='your-adwords-client-id'# ie.. xyz123.apps.googleusercontent.comGOOGLEADWORDS_CLIENT_SECRET='your-adwords-client-secret'# xyz123xyz123xyz123xyz123GOOGLEADWORDS_REFRESH_TOKEN='your-adwords-refresh-token'# 1/xyz123xyz123xyz123xyz123xyz123xyz123xyz123xGOOGLEADWORDS_DEVELOPER_TOKEN='your-adwords-developer-token'# 1234567890GOOGLEADWORDS_CLIENT_CUSTOMER_ID='your-adwords-client-customer-id'# xyz123xyz123xyz123xyz1If you don’t know these values already you’ll probably want to read the Google
AdwordsOAuth 2.0 Authenticationdocumentation.Other SettingsOther settings can be found indjango_google_adwords.settingsand can be
overridden by putting them in your settings file prepended withGOOGLEADWORDS_.CeleryCeleryinstallation and configuration is somewhat out of the scope of this
document but in order to sync Google Adwords data into models you will need a
working Celery.Essentially the syncing of data is a two step process, as follows;1. Reports are downloaded from Adwords using the Celery queue specified in the
settingGOOGLEADWORDS_REPORT_RETRIEVAL_CELERY_QUEUE.
2. Downloaded reports are processed using the Celery queue specified in the
settingGOOGLEADWORDS_DATA_IMPORT_CELERY_QUEUE.By default the above two settings, along withGOOGLEADWORDS_HOUSEKEEPING_CELERY_QUEUEare set toceleryhowever you may want to spilt these up with different
workers, as follows;GOOGLEADWORDS_REPORT_RETRIEVAL_CELERY_QUEUE='adwords_retrieval'GOOGLEADWORDS_DATA_IMPORT_CELERY_QUEUE='adwords_import'GOOGLEADWORDS_HOUSEKEEPING_CELERY_QUEUE='adwords_housekeeping'With the above you could run the following workers;celeryworker--appmyapp--queuesadwords_retrieval&celeryworker--appmyapp--queuesadwords_import&celeryworker--appmyapp--queuesadwords_housekeeping&UsageStoring local dataThe provided models include methods to sync data from the Google Adwords API to
the local models so that it can be queried at a later stage.account_id=[YOURGOOGLEADWORDSACCOUNTID]account=Account.objects.create(account_id=account_id)result=account.sync()# returns a celery AsyncResultDepending on the amount of data contained with your Adwords account the above
could take quite some time to populate! Advice is to monitor the celery task.You can control what data is sync’d with the following settings:GOOGLEADWORDS_SYNC_ACCOUNT=True# Sync account dataGOOGLEADWORDS_SYNC_CAMPAIGN=True# Sync campaign dataGOOGLEADWORDS_SYNC_ADGROUP=True# Sync adgroup dataGOOGLEADWORDS_SYNC_AD=False# Sync ad data - note this can take a LOOOONNNNG time if you have lots of ads...Once you have created an account or have multiple accounts, you can, usingCelery Beathave the accounts sync’d at regular intervals by setting theCELERYBEAT_SCHEDULEsimilar to the following;fromcelery.schedulesimportcrontabCELERYBEAT_SCHEDULE={'sync_google_adwords_data':{'task':'django_google_adwords.tasks.sync_chain','schedule':crontab(minute=5,hour=0),},}Paged dataTo use the API but not store data in the models you can page through yielded data
with the following;selector={'searchParameters':[{'xsi_type':'RelatedToQuerySearchParameter','queries':['seo','adwords','adwords seo']},{'xsi_type':'LanguageSearchParameter','languages':[{'id':'1000'}]},{'xsi_type':'LocationSearchParameter','locations':[{'id':'2036'}]},],'ideaType':'KEYWORD','requestType':'IDEAS','requestedAttributeTypes':['KEYWORD_TEXT','SEARCH_VOLUME'],}for(data,selector)inpaged_request('TargetingIdeaService',selector):printdataGoogle Adwords API VersionsThe intention is to keep in sync with the latest available Google Adwords API
versions - currently this isv201506To do this it’s highly possible we’ll need to break backwards compatibility as
the API can potentially do that.Backwards Incompatibility Changesv0.6.0Changed settingGOOGLEADWORDS_START_FINISH_CELERY_QUEUEtoGOOGLEADWORDS_HOUSEKEEPING_CELERY_QUEUE.RemovedAlert.sync_alerts(),Alert.get_selector()and tasksync_alertsas the services that these functions call have been discontinued in the Google API. TheAlertmodel remains in place so that existing alerts can be accessed if required.v0.4.0Now using Django 1.7 migrations.Switched from money to djmoney (which itself uses py-moneyed).ContributingYou are encouraged to contribute - please fork and submit pull requests. To get
a development environment up you should be able to do the following;gitclonehttps://bitbucket.org/alexhayes/django-google-adwords.gitcddjango-google-adwordspipinstal-rrequirements/default.txtpipinstal-rrequirements/test.txt./runtests.pyAnd to run the full test suite, you can then run;toxNote tox tests for Python 2.7, 3.3, 3.4 and PyPy for Django 1.7 and 1.8.
You’ll need to consult the docs for installation of these Python versions
on your OS, on Ubuntu you can do the following;sudoapt-getinstallpython-software-propertiessudoadd-apt-repositoryppa:fkrull/deadsnakessudoapt-getupdatesudoapt-getinstallpython2.7python2.7-devsudoapt-getinstallpython3.3python3.3-devsudoapt-getinstallpython3.4python3.4-devsudoapt-getinstallpypypypy-devNote thatdjango-noseissue#133and#197cause issues with some
tests thus the reason foralexhayes/django-nosebeing used in therequirements/test.pyandrequirements/test3.py.ThanksThank-you toroi.com.aufor supporting this project.AuthorsJeremy Storer <storerjeremy@gmail.com>Alex Hayes <alex@alution.com>