Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added appDomain configuration variable allowing GA to track on altern…

…ate domain
  • Loading branch information...
commit 61fdb9a79c28c682d1f41f6543d68e6e46ab5e2a 1 parent a0428c8
Brett webflint authored
Showing with 60 additions and 54 deletions.
  1. +18 −17 AppConfig.py
  2. +42 −37 GAHelper.py
35 AppConfig.py
View
@@ -3,23 +3,24 @@
# Hacker News API Config
#
#main server
-hackerNewsRSSFeed = 'http://tinyurl.com/6y37ehb'#http://news.ycombinator.com/rss
-hackerNewsURL = 'http://tinyurl.com/3nkabdb'#http://news.ycombinator.com
-hackerNewsPage2URL = 'http://tinyurl.com/69cgmyd'#http://news.ycombinator.com/news2
-hackerNewsNewestURL = 'http://tinyurl.com/3ouh6ml'#http://news.ycombinator.org/newest
-hackerNewsBestURL = 'http://tinyurl.com/68y3nzx'#http://news.ycombinator.org/best
-hackerNewsAskURL = 'http://tinyurl.com/3lduuz8'#http://news.ycombinator.org/ask
+hackerNewsRSSFeed = 'http://tinyurl.com/6y37ehb' # http://news.ycombinator.com/rss
+hackerNewsURL = 'http://tinyurl.com/3nkabdb' # http://news.ycombinator.com
+hackerNewsPage2URL = 'http://tinyurl.com/69cgmyd' # http://news.ycombinator.com/news2
+hackerNewsNewestURL = 'http://tinyurl.com/3ouh6ml' # http://news.ycombinator.org/newest
+hackerNewsBestURL = 'http://tinyurl.com/68y3nzx' # http://news.ycombinator.org/best
+hackerNewsAskURL = 'http://tinyurl.com/3lduuz8' # http://news.ycombinator.org/ask
#backup
-hackerNewsRSSFeedBackup = 'http://tinyurl.com/6y37ehb'#http://news.ycombinator.com/rss
-hackerNewsURLBackup = 'http://tinyurl.com/3nkabdb'#http://news.ycombinator.com
-hackerNewsPage2URLBackup = 'http://tinyurl.com/69cgmyd'#http://news.ycombinator.com/news2
-hackerNewsNewestURLBackup = 'http://tinyurl.com/3ouh6ml'#http://news.ycombinator.org/newest
-hackerNewsBestURLBackup = 'http://tinyurl.com/68y3nzx'#http://news.ycombinator.org/best
-hackerNewsAskURLBackup = 'http://tinyurl.com/3lduuz8'#http://news.ycombinator.org/ask
+hackerNewsRSSFeedBackup = 'http://tinyurl.com/6y37ehb' # http://news.ycombinator.com/rss
+hackerNewsURLBackup = 'http://tinyurl.com/3nkabdb' # http://news.ycombinator.com
+hackerNewsPage2URLBackup = 'http://tinyurl.com/69cgmyd' # http://news.ycombinator.com/news2
+hackerNewsNewestURLBackup = 'http://tinyurl.com/3ouh6ml' # http://news.ycombinator.org/newest
+hackerNewsBestURLBackup = 'http://tinyurl.com/68y3nzx' # http://news.ycombinator.org/best
+hackerNewsAskURLBackup = 'http://tinyurl.com/3lduuz8' # http://news.ycombinator.org/ask
#other settings
-hackerNewsRSSFeed = 'http://tinyurl.com/6y37ehb'#http://news.ycombinator.com/rss
-hackerNewsBgroundBrightness = 0xf6 # HN pages' background color "R" value
- # (out of "RGB")
-googleAnalyticsKey = 'UA-24252811-3'
-dataExpirationPolicy = '180'#in seconds
+hackerNewsRSSFeed = 'http://tinyurl.com/6y37ehb' # http://news.ycombinator.com/rss
+hackerNewsBgroundBrightness = 0xf6 # HN pages' background color "R" value (out of "RGB")
+
+googleAnalyticsKey = 'UA-24252811-3' # UA-24252811-3
+dataExpirationPolicy = '180' # in seconds
+appDomain = 'hndroidapi.appspot.com' # hndroidapi.appspot.com
79 GAHelper.py
View
@@ -1,44 +1,49 @@
-import os
-import re
import logging
import time
from UserString import MutableString
-from google.appengine.ext.webapp import util
from google.appengine.api import urlfetch
import AppConfig
-from UserString import MutableString
-from xml.sax.saxutils import escape
import random
-def trackGARequests(path,remoteAddr, referer = ''):
- logging.debug('trackRSSRequests: calling GA GIF service')
-
- var_utmac = AppConfig.googleAnalyticsKey #enter the new urchin code
- var_utmhn = 'hndroidapi.appspot.com' #enter your domain
- var_utmn = str(random.randint(1000000000, 9999999999))#random request number
- var_cookie = str(random.randint(10000000, 99999999))#random cookie number
- var_random = str(random.randint(1000000000, 2147483647)) #number under 2147483647
- var_today = str(int(time.time())) #today
- var_referer = referer #referer url
- var_uservar = '-' #enter your own user defined variable
- var_utmp = '%s/%s' % (path, remoteAddr) #this example adds a fake page request to the (fake) rss directory (the viewer IP to check for absolute unique RSS readers)
- #build URL
- urchinUrl = MutableString()
- urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=' + var_utmn + '&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' + var_utmhn + '&utmr=' + var_referer + '&utmp=' + var_utmp + '&utmac=' + var_utmac + '&utmcc=__utma%3D' + var_cookie + '.' + var_random + '.' + var_today + '.' + var_today + '.' + var_today + '.2%3B%2B__utmb%3D' + var_cookie + '%3B%2B__utmc%3D' + var_cookie + '%3B%2B__utmz%3D' + var_cookie + '.' + var_today + '.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D' + var_cookie + '.' + var_uservar + '%3B';
-
- #async request to GA's GIF service
- rpcGA = None
- try:
- rpcGA = urlfetch.create_rpc()
- urlfetch.make_fetch_call(rpcGA, urchinUrl)
- except Exception,exT:
- logging.error('trackRSSRequests: Errors calling GA GIF service : %s' % exT)
-
- #validate request
- if (rpcGA):
- try:
- result = rpcGA.get_result()
- if (result and result.status_code == 200):
- logging.debug('trackRSSRequests: GA logged successfully')
- except Exception,ex:
- logging.error('trackRSSRequests: Errors : %s' % ex)
+
+def trackGARequests(path, remoteAddr, referer=''):
+ logging.debug('trackRSSRequests: calling GA GIF service')
+
+ var_utmac = AppConfig.googleAnalyticsKey # enter the new urchin code
+ var_utmhn = AppConfig.appDomain # enter your domain
+ var_utmn = str(random.randint(1000000000, 9999999999)) # random request number
+ var_cookie = str(random.randint(10000000, 99999999)) # random cookie number
+ var_random = str(random.randint(1000000000, 2147483647)) # number under 2147483647
+ var_today = str(int(time.time())) # today
+ var_referer = referer # referer url
+ var_uservar = '-' # enter your own user defined variable
+ var_utmp = '%s/%s' % (path, remoteAddr) # this example adds a fake page request to the (fake) rss directory (the viewer IP to check for absolute unique RSS readers)
+ #build URL
+ urchinUrl = MutableString()
+ urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=' + var_utmn
+ urchinUrl += '&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn='
+ urchinUrl += var_utmhn + '&utmr=' + var_referer + '&utmp=' + var_utmp
+ urchinUrl += '&utmac=' + var_utmac + '&utmcc=__utma%3D' + var_cookie
+ urchinUrl += '.' + var_random + '.' + var_today + '.' + var_today + '.'
+ urchinUrl += var_today + '.2%3B%2B__utmb%3D' + var_cookie
+ urchinUrl += '%3B%2B__utmc%3D' + var_cookie + '%3B%2B__utmz%3D' + var_cookie
+ urchinUrl += '.' + var_today
+ urchinUrl += '.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D'
+ urchinUrl += var_cookie + '.' + var_uservar + '%3B'
+
+ #async request to GA's GIF service
+ rpcGA = None
+ try:
+ rpcGA = urlfetch.create_rpc()
+ urlfetch.make_fetch_call(rpcGA, urchinUrl)
+ except Exception, exT:
+ logging.error('trackRSSRequests: Errors calling GA GIF service : %s' % exT)
+
+ #validate request
+ if (rpcGA):
+ try:
+ result = rpcGA.get_result()
+ if (result and result.status_code == 200):
+ logging.debug('trackRSSRequests: GA logged successfully')
+ except Exception, ex:
+ logging.error('trackRSSRequests: Errors : %s' % ex)
Please sign in to comment.
Something went wrong with that request. Please try again.