11###############################################################################
22# Universal Analytics for Python
33# Copyright (c) 2013, Analytics Pros
4- #
5- # This project is free software, distributed under the BSD license.
6- # Analytics Pros offers consulting and integration services if your firm needs
4+ #
5+ # This project is free software, distributed under the BSD license.
6+ # Analytics Pros offers consulting and integration services if your firm needs
77# assistance in strategy, implementation, or auditing existing work.
88###############################################################################
99
@@ -32,7 +32,7 @@ def generate_uuid(basedata = None):
3232
3333class Time (datetime .datetime ):
3434 """ Wrappers and convenience methods for processing various time representations """
35-
35+
3636 @classmethod
3737 def from_unix (cls , seconds , milliseconds = 0 ):
3838 """ Produce a full |datetime.datetime| object from a Unix timestamp """
@@ -54,7 +54,7 @@ def milliseconds_offset(cls, timestamp, now = None):
5454 if isinstance (timestamp , (int , float )):
5555 base = timestamp
5656 else :
57- base = cls .to_unix (timestamp )
57+ base = cls .to_unix (timestamp )
5858 base = base + (timestamp .microsecond / 1000000 )
5959 if now is None :
6060 now = time .time ()
@@ -72,7 +72,7 @@ class HTTPRequest(object):
7272
7373 endpoint = 'https://www.google-analytics.com/collect'
7474
75-
75+
7676 @staticmethod
7777 def debug ():
7878 """ Activate debugging on urllib2 """
@@ -95,10 +95,10 @@ def fixUTF8(cls, data): # Ensure proper encoding for UA's servers...
9595
9696
9797
98- # Apply stored properties to the given dataset & POST to the configured endpoint
99- def send (self , data ):
98+ # Apply stored properties to the given dataset & POST to the configured endpoint
99+ def send (self , data ):
100100 request = Request (
101- self .endpoint + '?' + urlencode (self .fixUTF8 (data )),
101+ self .endpoint + '?' + urlencode (self .fixUTF8 (data )),
102102 headers = {
103103 'User-Agent' : self .user_agent
104104 }
@@ -124,11 +124,11 @@ def cache_request(self, request):
124124
125125class HTTPPost (HTTPRequest ):
126126
127- # Apply stored properties to the given dataset & POST to the configured endpoint
127+ # Apply stored properties to the given dataset & POST to the configured endpoint
128128 def send (self , data ):
129129 request = Request (
130- self .endpoint ,
131- data = urlencode (self .fixUTF8 (data )),
130+ self .endpoint ,
131+ data = urlencode (self .fixUTF8 (data )),
132132 headers = {
133133 'User-Agent' : self .user_agent
134134 }
@@ -145,7 +145,7 @@ class Tracker(object):
145145 params = None
146146 parameter_alias = {}
147147 valid_hittypes = ('pageview' , 'event' , 'social' , 'screenview' , 'transaction' , 'item' , 'exception' , 'timing' )
148-
148+
149149
150150 @classmethod
151151 def alias (cls , typemap , base , * names ):
@@ -191,7 +191,7 @@ def consume_options(cls, data, hittype, args):
191191 if opt_position < len (args ) and isinstance (args [opt_position ], expected_type ):
192192 data [ optname ] = args [ opt_position ]
193193 opt_position += 1
194-
194+
195195
196196
197197
@@ -205,18 +205,18 @@ def hittime(cls, timestamp = None, age = None, milliseconds = None):
205205 if isinstance (age , (int , float )):
206206 return int (age * 1000 ) + (milliseconds or 0 )
207207
208-
208+
209209
210210 @property
211211 def account (self ):
212212 return self .params .get ('tid' , None )
213213
214214
215215 def __init__ (self , account , name = None , client_id = None , hash_client_id = False , user_id = None , user_agent = None , use_post = True ):
216-
216+
217217 if use_post is False :
218218 self .http = HTTPRequest (user_agent = user_agent )
219- else :
219+ else :
220220 self .http = HTTPPost (user_agent = user_agent )
221221
222222 self .params = { 'v' : 1 , 'tid' : account }
@@ -258,7 +258,7 @@ def send(self, hittype, *args, **data):
258258 if k not in data :
259259 data [ k ] = v
260260
261-
261+
262262 data = dict (self .payload (data ))
263263
264264 if self .hash_client_id :
@@ -278,13 +278,13 @@ def set(self, name, value = None):
278278 param , value = self .coerceParameter (key , value )
279279 self .params [param ] = value
280280 except KeyError :
281- pass
281+ pass
282282 elif isinstance (name , basestring ):
283283 try :
284284 param , value = self .coerceParameter (name , value )
285285 self .params [param ] = value
286286 except KeyError :
287- pass
287+ pass
288288
289289
290290
@@ -387,7 +387,7 @@ def safe_unicode(obj):
387387# User Timing
388388Tracker .alias (safe_unicode , 'utc' , 'timingCategory' , 'timing-category' )
389389Tracker .alias (safe_unicode , 'utv' , 'timingVariable' , 'timing-variable' )
390- Tracker .alias (float , 'utt' , 'time' , 'timingTime' , 'timing-time' )
390+ Tracker .alias (int , 'utt' , 'time' , 'timingTime' , 'timing-time' )
391391Tracker .alias (safe_unicode , 'utl' , 'timingLabel' , 'timing-label' )
392392Tracker .alias (float , 'dns' , 'timingDNS' , 'timing-dns' )
393393Tracker .alias (float , 'pdt' , 'timingPageLoad' , 'timing-page-load' )
@@ -419,7 +419,7 @@ def safe_unicode(obj):
419419 Tracker .alias (int , 'pr{0}qt' .format (product_index )) # Product quantity
420420 Tracker .alias (str , 'pr{0}cc' .format (product_index )) # Product coupon code
421421 Tracker .alias (int , 'pr{0}ps' .format (product_index )) # Product position
422-
422+
423423 for custom_index in range (MAX_CUSTOM_DEFINITIONS ):
424424 Tracker .alias (str , 'pr{0}cd{1}' .format (product_index , custom_index )) # Product custom dimension
425425 Tracker .alias (int , 'pr{0}cm{1}' .format (product_index , custom_index )) # Product custom metric
0 commit comments