kra3/py-ga-mob

Are custom dimensions supported?

reece opened this issue · 1 comments

reece commented

UA (and perhaps GA) provides "Custom Dimensions". Are these possible to use with pyga?

https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

kra3 commented

Hello @reece, this library is written against GA.js, while I have plans to create a version for UA, time is not in favour so far.

That said, pyga has supports for custom variables, events & campaigns from ga.js. Most likely, one of those will work for you.

For example, ga.js variables can be thought of us less capable version of analytics.js dimensions.

py-ga-mob/pyga/entities.py

Lines 130 to 171 in 93fb657

class CustomVariable(object):
'''
Represent a Custom Variable
Properties:
index -- Is the slot, you have 5 slots
name -- Name given to custom variable
value -- Value for the variable
scope -- Scope can be any one of 1, 2 or 3.
WATCH OUT: It's a known issue that GA will not decode URL-encoded
characters in custom variable names and values properly, so spaces
will show up as "%20" in the interface etc. (applicable to name & value)
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=2cdb3ec0be32e078
'''
SCOPE_VISITOR = 1
SCOPE_SESSION = 2
SCOPE_PAGE = 3
def __init__(self, index=None, name=None, value=None, scope=3):
self.index = index
self.name = name
self.value = value
self.scope = CustomVariable.SCOPE_PAGE
if scope:
self.scope = scope
def __setattr__(self, name, value):
if name == 'scope':
if value and value not in range(1, 4):
raise ValueError('Custom Variable scope has to be one of the 1,2 or 3')
if name == 'index':
# Custom Variables are limited to five slots officially, but there seems to be a
# trick to allow for more of them which we could investigate at a later time (see
# http://analyticsimpact.com/2010/05/24/get-more-than-5-custom-variables-in-google-analytics/
if value and (value < 0 or value > 5):
raise ValueError('Custom Variable index has to be between 1 and 5.')
object.__setattr__(self, name, value)