示例#1
0
def post(event_category, event_action, cm_param):
    global client_id
    conn = httplib.HTTPConnection(settings.get_ga_url())
    if cm_param is not None:
        conn.request("POST", "/collect","v=1&tid=%s&cid=%s&t=event&ec=%s&ea=%s&ev=1&%s=1" %(settings.get_tracking_id(), client_id,event_category, event_action, cm_param))
    else:
        conn.request("POST", "/collect","v=1&tid=%s&cid=%s&t=event&ec=%s&ea=%s&ev=1" %(settings.get_tracking_id(), client_id,event_category, event_action))
示例#2
0
import urllib2
from retrying import retry
from threading import Thread
import httplib, urllib
import settings
import uuid

main_ga_url = settings.get_ga_url()
client_id = uuid.uuid4()


def post_ga_event(event_category, event_action,cm_param = None):
    thread = Thread(target = post,args = (event_category, event_action, cm_param))
    thread.start()


@retry(stop_max_attempt_number=3)
def post(event_category, event_action, cm_param):
    global client_id
    conn = httplib.HTTPConnection(settings.get_ga_url())
    if cm_param is not None:
        conn.request("POST", "/collect","v=1&tid=%s&cid=%s&t=event&ec=%s&ea=%s&ev=1&%s=1" %(settings.get_tracking_id(), client_id,event_category, event_action, cm_param))
    else:
        conn.request("POST", "/collect","v=1&tid=%s&cid=%s&t=event&ec=%s&ea=%s&ev=1" %(settings.get_tracking_id(), client_id,event_category, event_action))