Google Analytics driven TwitterBot using AppEngine

15
TwitterBot via AppEngine Driven by Google Analytics Nirvana Tikku / @ntikku

description

An Automated Marketing Solution for my Android app ASOTUnofficial. Presented at Google Developer Group (15 Jan '13)

Transcript of Google Analytics driven TwitterBot using AppEngine

Page 1: Google Analytics driven TwitterBot using AppEngine

TwitterBot via AppEngineDriven by Google Analytics

Nirvana Tikku / @ntikku

Page 2: Google Analytics driven TwitterBot using AppEngine

Context

• Android App – ASOT Unofficial–Weekly Trance/Progressive Radio Show– Track listings, Play YouTube videos– Google Analytics to track usage– Parse, AppEngine, YouTube, SoundCloud– 15 months, 23K active users–>5K plays a day

• Indie developer, free app

Page 3: Google Analytics driven TwitterBot using AppEngine

Why?

• Automated social marketing• Unleash GA data• SEO powered by Twitter• Link to interesting content as deemed by

visitors

• Compelling media content music charts

Page 4: Google Analytics driven TwitterBot using AppEngine

How?

Service. Two Cron jobs, Twitter, Google Analytics and the AE datastore.

• Seed Tweets – Daily – Query GA via Core Reporting API– Store necessary elements in datastore

• Publish Tweets – Hourly– Tweepy library for auth and publishing– ‘Update Status’ with Pending Tweets in datastore

Page 5: Google Analytics driven TwitterBot using AppEngine

Technical Details

• AppEngine Python Runtime (2.7)• Libraries used– Tweepy– PyCryptoSignedJWT – OAuth2Client– HTTPLib2– APIClient & URITemplate

• Additional– Google Account with OAuth credentials– Twitter API key and OAuth credentials

Page 6: Google Analytics driven TwitterBot using AppEngine

Caveats

• PyCrypto doesn’t play well with PKCS12 certs – need to use PyCryptoSignedJWT library to sign PEM key

• Trying to dereference names to handles (i.e. Armin van Buuren -- @arminvanbuuren), will most likely get your bot banned

Page 7: Google Analytics driven TwitterBot using AppEngine

Code

1. The authentication process– Google Analytics API– Twitter API

2. Seed tweets via Google Analytics3. Publish update to Twitter via Tweepy

Page 8: Google Analytics driven TwitterBot using AppEngine

Google Analytics Authentication

• Google Analytics API– Download key (p12)– Convert to .pem– Add gserviceaccount

user to GA profile– Use PyCryptoJWT

Page 9: Google Analytics driven TwitterBot using AppEngine

Twitter Authentication• Twitter API– Create App– Create OAuth key– Copy params

• consumer_key• consumer_secret• access_token• access_token_secret

Page 10: Google Analytics driven TwitterBot using AppEngine

2. Seed tweets via trends in GA

Query Details

Page 11: Google Analytics driven TwitterBot using AppEngine

3. Publishing tweets via Tweepy

Merge the context with the template

Publish the status update

Page 12: Google Analytics driven TwitterBot using AppEngine

@ASOTbot

• 1 month, 70 followers organically

• Utilizes unicode character for chart position (1 char)

• Associated with community hash tag #ASOT for discoverability

• Attaches YouTube video youtube.com/watch?v=[videoId]

Page 13: Google Analytics driven TwitterBot using AppEngine

Recap & DIY

• Clone the ga_twitterbot repo on GitHub• Go to the Google API Console

– Register for Google Analytics– Create a Service Account– Setup the client_id, service_account params– Convert the .p12 key to .pem

• Go to the Twitter API Apps Console– Create your app– Setup the tw_consumer_key, tw_consumer_secret,

tw_access_token and tw_access_token_secret params

• Build your GA query via the Google Analytics Query Explorer and replace SeedTweetsUtil values

• Set your schedule in cron.yaml

Page 15: Google Analytics driven TwitterBot using AppEngine

Thanks