Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Django modelling and helpers for the Google Adwords API.

Project Description

Django modelling and helpers for the Google Adwords API.

Installation

You can install django-google-adwords either via the Python Package Index (PyPI) or from bitbucket.

To install using pip;

pip install django-google-adwords

From github;

pip install git+https://bitbucket.org/alexhayes/django-google-adwords.git

Settings

Required

You must place the following in your django settings file.

GOOGLEADWORDS_CLIENT_ID = 'your-adwords-client-id'
GOOGLEADWORDS_CLIENT_SECRET = 'your-adwords-client-secret'
GOOGLEADWORDS_REFRESH_TOKEN = 'your-adwords-refresh-token'
GOOGLEADWORDS_DEVELOPER_TOKEN = 'your-adwords-developer-token'
GOOGLEADWORDS_CLIENT_CUSTOMER_ID = 'your-adwords-client-customer-id'

If you don’t know these values already you’ll probably want to read the Google Adwords OAuth 2.0 Authentication documentation.

Other Settings

Other settings can be found in django_google_adwords.settings and can be overridden by putting them in your settings file prepended with GOOGLEADWORDS_.

Celery

Celery installation 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 setting GOOGLEADWORDS_REPORT_RETRIEVAL_CELERY_QUEUE. 2. Downloaded reports are processed using the Celery queue specified in the setting GOOGLEADWORDS_DATA_IMPORT_CELERY_QUEUE.

By default the above two settings, along with GOOGLEADWORDS_HOUSEKEEPING_CELERY_QUEUE are set to celery however 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;

    celery worker --app myapp --queues adwords_retrieval &
celery worker --app myapp --queues adwords_import &
celery worker --app myapp --queues adwords_housekeeping &

Usage

Storing local data

The 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 = [YOUR GOOGLE ADWORDS ACCOUNT ID]
account = Account.objects.create(account_id=account_id)
result = account.sync() # returns a celery AsyncResult

Depending 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 data
GOOGLEADWORDS_SYNC_CAMPAIGN = True   # Sync campaign data
GOOGLEADWORDS_SYNC_ADGROUP = True    # Sync adgroup data
GOOGLEADWORDS_SYNC_AD = False        # Sync ad data - note this can take a LOOOONNNNG time if you have lots of ads...

GOOGLEADWORDS_NEW_ACCOUNT_ACCOUNT_SYNC_DAYS = 61
GOOGLEADWORDS_NEW_ACCOUNT_CAMPAIGN_SYNC_DAYS = 61
GOOGLEADWORDS_NEW_ACCOUNT_AD_GROUP_SYNC_DAYS = 31
GOOGLEADWORDS_NEW_ACCOUNT_AD_SYNC_DAYS = 3
GOOGLEADWORDS_EXISTING_ACCOUNT_SYNC_DAYS = 3

Paged data

To 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) in paged_request('TargetingIdeaService', selector):
    print data

Google Adwords API Versions

The intention is to keep in sync with the latest available Google Adwords API versions.

To do this it’s highly possible we’ll need to break backwards compatibility as the API often does!

Currently we support v201409 however this will sunset on 14 July 2015.

Support for v201502 will be added very soon but note there will be a number of backwards compatibility changes that will most likely break your code.

Backwards Incompatibility Changes

v0.6.0

  • Changed setting GOOGLEADWORDS_START_FINISH_CELERY_QUEUE to GOOGLEADWORDS_HOUSEKEEPING_CELERY_QUEUE.
  • Removed Alert.sync_alerts(), Alert.get_selector() and task sync_alerts as the services that these functions call have been discontinued in the Google API. The Alert model remains in place so that existing alerts can be accessed if required.

v0.4.0

  • Now using Django 1.7 migrations.
  • Switched from money to djmoney (which itself uses py-moneyed).

Contributing

You are encouraged to contribute - please fork and submit pull requests. To get a development environment up you should be able to do the following;

git clone https://bitbucket.org/alexhayes/django-google-adwords.git
cd django-google-adwords
pip instal -r requirements/default.txt
pip instal -r requirements/test.txt
./runtests.py

And to run the full test suite, you can then run;

tox

Note tox tests for Python 2.7, 3.3, 3.4 and PyPy for Django 1.7 and 1.8. You’ll need to consolute the docs for installation of these Python versions on your OS, on Ubuntu you can do the following;

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7 python2.7-dev
sudo apt-get install python3.3 python3.3-dev
sudo apt-get install python3.4 python3.4-dev
sudo apt-get install pypy pypy-dev

Note that django-nose issue #133 and #197 cause issues with some tests thus the reason for alexhayes/django-nose being used in the requirements/test.py and requirements/test3.py.

Thanks

Thank-you to roi.com.au for supporting this project.

Authors

Release History

Release History

This version
History Node

0.6.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-google-adwords-0.6.0.tar.gz (32.9 kB) Copy SHA256 Checksum SHA256 Source Jun 24, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting