Last active
April 7, 2016 20:06
-
-
Save TylerMills/30de2b2ec173758be798468819c7a496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tyler Mills / tmills@localytics.com | |
import requests | |
import json | |
import uuid | |
import time | |
APP_KEY = '575aadd1cd1bceba03fc516-f0d08764-d84c-11e5-3985-00adad38bc8d' # Change Key for the Appropriate Platform | |
headers = {'content-type': 'application/json'} | |
endpoint = 'https://analytics.localytics.com/api/v2/applications/{}/uploads'.format(APP_KEY) | |
blobHeader = json.dumps({ | |
"dt":"h", # Data Type = Header | |
"seq":1, | |
"attrs": { | |
"au":APP_KEY, # App Key | |
"dp":"TV", # Platform Name | |
"dma":"Samsung", # Device Make | |
"dmo":"UHD9500", # Device Model | |
"lv":"Acme 1.1.0" # SDK Library Version | |
"dov":"2.3.2", # Device OS Version | |
"iu":"c31e9516-93e8-4a28-a612-9ee97bb0ed06", # Install ID, represents the install of the app, typically changes between uninstall and reinstall | |
"du":"", # device uuid | |
"adid":"", # (optional) IDFA | |
"tz":-18000, # device timezone | |
"av":"1.0.0", # (optional) app version | |
"dll":"en", #language | |
"dlc":"US" #country | |
} | |
}) | |
sessionOpen = json.dumps({ | |
"dt":"s", # Data Type = Session Open | |
"u":str(uuid.uuid4()), # Random Session UUID | |
"ct":int(time.time()), # Client Time when Session Was Closed in Local Time | |
"cid":"abc123", # Customer ID | |
"utp":"known", # User Type | |
"lat":12.123456 # (optional) float representing latitude | |
"long":12.123456 # (optional) float representing longitude | |
"c0":"Yes" # strings representing custom dimensions (1-20) | |
"mc":"string", #Marketing campaign, possibly utm_campaign | |
"mm":"string", #Marketing medium, possibly utm_medium | |
"ms":"string", #Marketing source, possibly utm_source | |
}) | |
event = json.dumps({ | |
"dt":"e", # Data Type = Event | |
"u":str(uuid.uuid4()), # Random Event UUID | |
"su":"", # Session ID that this event correlates to | |
"ct":int(time.time()), # Client Time in Local Time | |
"n":"Purchase Complete", # Event Name | |
"cid":"abc123", # Customer ID | |
"utp":"known", # User Type | |
"v":100, # (optional) Value in US Cents of this event | |
"lat":12.123456 # (optional) float representing latitude | |
"long":12.123456 # (optional) float representing longitude | |
"attrs": { # (optional) Event Attributes | |
"Button Type":"Round" | |
} | |
"c0":"Yes" # (optional) strings representing custom dimensions (1-20) | |
}) | |
sessionClose = json.dumps({ | |
"dt":"sc", # Data Type = Session Close | |
"u":str(uuid.uuid4()), # Random Session Close UUID | |
"su":"" # ID for session that this close correlates to | |
"ss":90191910 # time when session started | |
"ct":int(time.time()), # Client Time when Session Was Closed in Local Time | |
"ctl":114, # the length of this session (in seconds) | |
"cta":60, # the ‘active’ time of the session (optional) | |
"cid":"abc123", # Customer ID | |
"utp":"known", # User Type | |
"lat":12.123456 # (optional) float representing latitude | |
"long":12.123456 # (optional) float representing longitude | |
"fl":["Home","Video Summary","Video Player", "Home"], # screens flows from the session | |
"c0":"Yes" # strings representing custom dimensions (1-20) | |
}) | |
payload = ('{}\n{}\n{}\n{}'.format(blobHeader,sessionOpen,event,sessionClose) | |
push = requests.post(endpoint, payload, headers=headers) | |
print(push.status_code) | |
print(push.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment