aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAri Hausman-Cohen <arihc@google.com>2015-10-16 11:21:42 -0700
committerAri Hausman-Cohen <arihc@google.com>2015-10-16 11:21:42 -0700
commit90fb462975a78e0907f2eb6784b56d5d744907e2 (patch)
treec91274710e3428c62786eafa4feef6f346225cf0
parentc6bdfd81e2505ebcf7d6916b5a54cb13686819ea (diff)
downloadbdk-90fb462975a78e0907f2eb6784b56d5d744907e2.tar.gz
Adding app name to support real time metrics.
Change-Id: I6925d981a11aecccd61317128d05324765d74a0a
-rw-r--r--brunch/lib/metrics/data_types/brillo_ga_hits.py2
-rw-r--r--brunch/lib/metrics/data_types/generalized_ga/hit.py9
-rw-r--r--brunch/lib/metrics/data_types/generalized_ga/meta_data.py2
3 files changed, 11 insertions, 2 deletions
diff --git a/brunch/lib/metrics/data_types/brillo_ga_hits.py b/brunch/lib/metrics/data_types/brillo_ga_hits.py
index 80fec8c..c597b74 100644
--- a/brunch/lib/metrics/data_types/brillo_ga_hits.py
+++ b/brunch/lib/metrics/data_types/brillo_ga_hits.py
@@ -35,6 +35,7 @@ from tools import bdk_root
_BDK_VERSION_FILE = bdk_root.FromBDKRoot('tools/bdk/VERSION')
_BRILLO_APP_ID = 'UA-67119306-1'
+_BRILLO_APP_NAME = 'brunch'
_BRILLO_CD_OS = 1
_BRILLO_CD_OS_VERSION = 2
_BRILLO_CD_CPU_CORES = 3
@@ -88,6 +89,7 @@ def _GetRAM():
def _MetaData():
return generalized_ga.MetaData(_BRILLO_PROTOCOL_VERSION,
_BRILLO_APP_ID,
+ _BRILLO_APP_NAME,
_UserID())
diff --git a/brunch/lib/metrics/data_types/generalized_ga/hit.py b/brunch/lib/metrics/data_types/generalized_ga/hit.py
index 6e1628e..1d133aa 100644
--- a/brunch/lib/metrics/data_types/generalized_ga/hit.py
+++ b/brunch/lib/metrics/data_types/generalized_ga/hit.py
@@ -36,6 +36,7 @@ class Hit(object):
Attributes:
version: the Analytics Measurement Protocol version being used.
app_id: the ID of the GA property to send data to.
+ app_name: the name of the application.
user_id: an ID unique to a particular user.
hit_type: the type of interaction this data represents.
cds: (optional) a dictionary of { index : value } for custom dimensions.
@@ -54,6 +55,7 @@ class Hit(object):
popener=None):
self.version = meta_data.version
self.app_id = meta_data.app_id
+ self.app_name = meta_data.app_name
self.user_id = meta_data.user_id
self.hit_type = hit_type
self.cds = custom_dimensions or {}
@@ -62,8 +64,13 @@ class Hit(object):
def _GetFields(self):
"""Returns all fields as a list of (param, value) tuples."""
+ # TODO(arihc): remove this, support for grandfathered saved data
+ if not hasattr(self, 'app_name'):
+ self.app_name = 'brunch'
+
params = {'v' : self.version,
'tid' : self.app_id,
+ 'an' : self.app_name,
'cid' : self.user_id,
't' : self.hit_type}
for i in self.cds:
@@ -80,7 +87,7 @@ class Hit(object):
params = self._GetFields()
data = urllib.urlencode(params)
send_process = self.popener.PopenPiped(['curl',
- '--data=' + data,
+ '--data', data,
self._GA_ENDPOINT])
(out, err) = send_process.communicate()
return send_process.returncode == 0
diff --git a/brunch/lib/metrics/data_types/generalized_ga/meta_data.py b/brunch/lib/metrics/data_types/generalized_ga/meta_data.py
index d4481e2..2d148e5 100644
--- a/brunch/lib/metrics/data_types/generalized_ga/meta_data.py
+++ b/brunch/lib/metrics/data_types/generalized_ga/meta_data.py
@@ -27,4 +27,4 @@ Attributes:
import collections
-MetaData = collections.namedtuple('MetaData', ('version', 'app_id', 'user_id'))
+MetaData = collections.namedtuple('MetaData', ('version', 'app_id', 'app_name', 'user_id'))