forked from adswerve/universal-analytics-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
60 lines (45 loc) · 1.98 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
###############################################################################
# Test and example kit for Universal Analytics for Python
# Copyright (c) 2013, Analytics Pros
#
# This project is free software, distributed under the BSD license.
# Analytics Pros offers consulting and integration services if your firm needs
# assistance in strategy, implementation, or auditing existing work.
###############################################################################
from UniversalAnalytics import Tracker
DEBUG = True
if DEBUG: # these are optional...
from UniversalAnalytics import HTTPLog
HTTPLog.consume() # Filters urllib2's standard debugging for readability
Tracker.HTTPPost.debug() # Enables debugging in urllib2
# Create the tracker
tracker = Tracker.create('UA-XXXXX-Y', name = 'mytracker')
# Apply campaign settings
tracker.set('campaignName', 'testing')
tracker.set('campaignMedium', 'testing')
# Send a pageview
tracker.send('pageview', '/test')
# Send an event
tracker.send('event', 'mycat', 'myact', 'mylbl', { 'noninteraction': 1, 'page': '/1' })
# Send a social hit
tracker.send('social', 'facebook', 'test', '/test#social')
# A few more hits for good measure, testing real-time support for time offset
tracker.send('pageview', '/test', { 'campaignName': 'testing2' }, hitage = 60 * 5) # 5 minutes ago
tracker.send('pageview', '/test', { 'campaignName': 'testing3' }, hitage = 60 * 20) # 20 minutes ago
tracker.send('item', {
'transactionId': '12345abc',
'itemName': 'pizza',
'itemCode': 'abc',
'itemCategory': 'hawaiian',
'itemQuantity': 1
}, hitage = 7200)
tracker.send('transaction', {
'transactionId': '12345abc',
'transactionAffiliation': 'phone order',
'transactionRevenue': 28.00,
'transactionTax': 3.00,
'transactionShipping': 0.45,
'transactionCurrency': 'USD'
}, hitage = 7200)
# vim: set nowrap tabstop=4 shiftwidth=4 softtabstop=0 expandtab textwidth=0 filetype=python foldmethod=indent foldcolumn=4