-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Liz
committed
Mar 13, 2019
1 parent
48af53f
commit 356d600
Showing
9 changed files
with
171 additions
and
67 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# GrowingIOAutoTrack | ||
GrowingIO 批量打点 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,167 @@ | ||
#-*- coding=utf-8 -*- | ||
import emoji | ||
import pandas as pd | ||
import hashlib | ||
import hmac | ||
import time | ||
import requests as req | ||
import json | ||
|
||
project_id = '97fd6815651f25fb' | ||
publicKey = '06b3f5eb364f410eb7435a6940c4f431' | ||
privateKey = '3bde47c09c534a0db10a4b2402d3cd46' | ||
project_uid= 'z98jGyZP' | ||
|
||
# 创建事件级变量,将事件级变量 csv 文件名填入,默认 events.csv | ||
cstmFileName = '' | ||
# 创建事件,将您的自定义事件文件名输入,默认 cstmEvents.csv | ||
cstmEventsFileName = '' | ||
# 创建页面级变量 | ||
pvarFileName = '' | ||
# 创建登录用户变量 | ||
pplFileName = '' | ||
|
||
def authToken(secret, project, ai, tm): | ||
"""计算 auth """ | ||
message = ("POST\n/auth/token\nproject=" + project + "&ai=" + ai + "&tm=" + tm).encode('utf-8') | ||
signature = hmac.new(bytes(secret.encode('utf-8')), bytes(message), digestmod=hashlib.sha256).hexdigest() | ||
return signature | ||
|
||
tmStamp = str(round(time.time() * 1000)) | ||
print ('tm -> '+tmStamp) | ||
|
||
# 私钥、project uid , ai , tm | ||
authStr = authToken('3bde47c09c534a0db10a4b2402d3cd46', 'z98jGyZP', '97fd6815651f25fb',tmStamp) | ||
def getToken(): | ||
tmStamp = str(round(time.time() * 1000)) | ||
print ('使用时间戳 tm -> '+tmStamp) | ||
|
||
print('authToken 计算 -> '+authStr) | ||
# 私钥、project uid , ai , tm | ||
authStr = authToken(privateKey, project_uid, project_id,tmStamp) | ||
print('authToken 计算 -> '+authStr) | ||
|
||
# header 中是 公钥 | ||
header = {'X-Client-Id':'06b3f5eb364f410eb7435a6940c4f431'} | ||
urlToken = 'https://www.growingio.com/auth/token?ai={ai}&project={project}&tm={tm}&auth={auth}'.format( | ||
ai='97fd6815651f25fb', | ||
project='z98jGyZP', | ||
tm=tmStamp, | ||
auth=authStr | ||
) | ||
# | ||
token = req.post(urlToken,headers = header) | ||
# header 中是 公钥 | ||
header = {'X-Client-Id':publicKey} | ||
urlToken = 'https://www.growingio.com/auth/token?ai={ai}&project={project}&tm={tm}&auth={auth}'.format( | ||
ai=project_id, | ||
project=project_uid, | ||
tm=tmStamp, | ||
auth=authStr | ||
) | ||
# | ||
token = req.post(urlToken,headers = header) | ||
print("token 请求返回 -> "+token.text) | ||
tokenReturn = json.loads(token.text) | ||
print('返回 token 啦 -> '+ tokenReturn['code']) | ||
return tokenReturn['code'] | ||
|
||
print("token 请求返回 -> "+token.text) | ||
tokenReturn = json.loads(token.text) | ||
print('返回 token 啦 -> '+ tokenReturn['code']) | ||
headerEvents = {'X-Client-Id':publicKey,'Authorization':getToken()} | ||
print(headerEvents) | ||
|
||
# 公钥、token | ||
headerEvents = {'X-Client-Id':'06b3f5eb364f410eb7435a6940c4f431','Authorization':tokenReturn['code']} | ||
print("header -> "+str(headerEvents)) | ||
def events(): | ||
"""创建事件级变量""" | ||
cstmUrl = 'https://www.growingio.com/v1/api/projects/{project_id}/vars/events'.format(project_id = '97fd6815651f25fb') | ||
with open('events.csv') as file: | ||
cstmUrl = 'https://www.growingio.com/v1/api/projects/{}/vars/events'.format(project_uid) | ||
with open('events.csv' if cstmFileName == '' else cstmFileName) as file: | ||
trackFile = pd.read_csv(file,encoding = "utf_8",index_col=0) | ||
for index,row in trackFile.iterrows(): | ||
if index != 'id1': | ||
break | ||
cstmData={ | ||
'type':row['type'], | ||
'description':row['description'], | ||
'name':row['name'], | ||
'key':row['key'] | ||
} | ||
print('data: ', cstmData) | ||
print('上传事件级变量: ', cstmData) | ||
r = req.post(cstmUrl,headers=headerEvents,json=cstmData) | ||
print(r.text) | ||
print(r.status_code) | ||
if (r.status_code ==200): | ||
print(emoji.emojize(':thumbs_up:'),r.text) | ||
else: | ||
print(emoji.emojize(':broken_heart:'),r.status_code,r.text) | ||
|
||
|
||
|
||
def getCstmEventsVariable(): | ||
"""获取事件级变量,为了拿到服务端分配的 id """ | ||
getCstmEventsUrl= 'https://www.growingio.com/v1/api/projects/{}/vars/events'.format(project_uid) | ||
requests = req.get(getCstmEventsUrl,headers = headerEvents) | ||
if(requests.status_code == 200): | ||
print('---------获取事件级变量-----------') | ||
events = pd.read_json(requests.text) | ||
events.to_csv("getEvents.csv") | ||
print('---------生成表格 getEvents.csv 成功 -----------') | ||
|
||
|
||
def cstmEvents(): | ||
"""创建自定义事件""" | ||
events = 'https://www.growingio.com/v1/api/projects/{project_id}/dim/events'.format(project_id = '97fd6815651f25fb') | ||
"""创建打点事件""" | ||
eventsUrl = 'https://www.growingio.com/v1/api/projects/{}/dim/events'.format(project_uid) | ||
dictEvents = {} | ||
with open('getEvents.csv') as file: | ||
events = pd.read_csv(file,encoding = "utf_8",index_col=0) | ||
for index,row in events.iterrows(): | ||
dictEvents[row['name']] = {"key": row['key'],"id": row['id'], "type": row['type'],"name": row['name']} | ||
|
||
with open('cstmEvents.csv' if cstmEventsFileName == '' else cstmEventsFileName) as file: | ||
trackFile = pd.read_csv(file,encoding = "utf_8",index_col=0) | ||
attrs = [] | ||
cstmData=[] | ||
for index,row in trackFile.iterrows(): | ||
var = row['事件级变量'].split("、") | ||
for key in var: | ||
key = key.strip() | ||
if key != '': | ||
attrs.append(dictEvents[key]) | ||
cstmData.append({ | ||
'attrs':attrs, | ||
'type': 'counter' if row['类型'] == '计数器' else 'number', | ||
'description':row['描述'], | ||
'name':index, | ||
'key':row['标识符'].strip() | ||
}) | ||
print(json.dumps(cstmData)) | ||
r = req.post(eventsUrl,headers=headerEvents,json=cstmData) | ||
if r.status_code != 200 : | ||
print("自定义事件设置失败:",r.status_code,"服务器返回:",r.text) | ||
else: | ||
print(emoji.emojize(':thumbs_up:'),r.text) | ||
|
||
def pvarEvents(): | ||
"""创建页面级变量""" | ||
pvarUrl = 'https://www.growingio.com/v1/api/projects/{}/vars/pages'.format(project_uid) | ||
with open('pvarEvents.csv' if pvarFileName == '' else pvarFileName) as file: | ||
trackFile = pd.read_csv(file,encoding = "utf_8",index_col=0) | ||
for index,row in trackFile.iterrows(): | ||
pvarData = { | ||
'description':row['description'], | ||
'name':row['name'], | ||
'key':row['key'] | ||
} | ||
r = req.post(pvarUrl,headers=headerEvents,json=pvarData) | ||
if r.status_code != 200 : | ||
print("自定义事件设置失败:",r.status_code,"服务器返回:",r.text) | ||
else: | ||
print(emoji.emojize(':thumbs_up:'),r.text) | ||
|
||
|
||
def pplEvents(): | ||
"""创建登录用户变量""" | ||
pplUrl = 'https://www.growingio.com/v1/api/projects/{}/vars/peoples'.format(project_uid) | ||
with open('pplEvents.csv' if pplFileName == '' else pplFileName) as file: | ||
trackFile = pd.read_csv(file,encoding = "utf_8",index_col=0) | ||
for index,row in trackFile.iterrows(): | ||
pplData = [ | ||
{ | ||
'description':row['description'], | ||
'name':index, | ||
'key':row['key'], | ||
'attribution':row['attribution'] | ||
} | ||
] | ||
print(pplData) | ||
r = req.post(pplUrl,headers=headerEvents,json=pplData) | ||
if r.status_code != 200 : | ||
print("创建登录用户变量失败:",r.status_code,"服务器返回:",r.text) | ||
else: | ||
print(emoji.emojize(':thumbs_up:'),r.text) | ||
|
||
|
||
|
||
events() | ||
getCstmEventsVariable() | ||
cstmEvents() | ||
pvarEvents() | ||
pplEvents() | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,51 @@ | ||
name,description,标识符,事件级变量,类型 | ||
name,描述,标识符,事件级变量,类型,type | ||
首页商品曝光,首页商品曝光次数,homePageGoodsImp,"商品ID、 | ||
商品名称、 | ||
流量位",计数器 | ||
流量位",计数器,counter | ||
首页商品点击,首页商品点击,homePageGoodsClick,"商品ID、 | ||
商品名称、 | ||
流量位",计数器 | ||
流量位",计数器,counter | ||
商品分类页面商品点击,商品分类listing页面的商品点击,listingPageGoodsClick,"商品ID、 | ||
商品名称 | ||
",计数器 | ||
",计数器,counter | ||
用户发起搜索,用户在搜索栏发起商品搜索,searchGoods,"搜索词 | ||
",计数器 | ||
搜索有结果次数,用户搜索后返回结果是有搜索结果,searchResultView,搜索词,计数器 | ||
搜索无结果次数,用户搜索后返回结果是无结果,searchNoResultView,搜索词,计数器 | ||
",计数器,counter | ||
搜索有结果次数,用户搜索后返回结果是有搜索结果,searchResultView,搜索词,计数器,counter | ||
搜索无结果次数,用户搜索后返回结果是无结果,searchNoResultView,搜索词,计数器,counter | ||
搜索结果点击,点击搜索结果,searchResultClick,"商品ID、 | ||
商品名称、 | ||
搜索词",计数器 | ||
搜索词",计数器,counter | ||
浏览商品详情页,浏览商品详情页次数,商品详情页打开时触发,goodsDetailPageView,"商品ID、 | ||
商品名称",计数器 | ||
商品名称",计数器,counter | ||
加入购物车,加入购物车次数,addToCart,"商品ID、 | ||
商品名称 | ||
购买数量",计数器 | ||
商品名称、 | ||
购买数量",计数器,counter | ||
订单结算,点击Check Out时触发,checkOut,"商品ID、 | ||
商品名称 | ||
购买数量 | ||
总计金额 | ||
|
||
(是否是每个商品发送一个事件? | ||
那么购买数量永远是 1 啊? )",计数器 | ||
商品名称、 | ||
购买数量、 | ||
支付金额",计数器,counter | ||
订单支付,"支付订单次数。 | ||
用户点击订单支付时触发,一个订单发送一次事件。",payOrder,"订单ID(生成随机数)、 | ||
用户点击订单支付时触发,一个订单发送一次事件。",payOrder,"订单ID、 | ||
购买数量、 | ||
支付方式、 | ||
支付金额、 | ||
",计数器 | ||
",计数器,counter | ||
商品支付,"支付商品次数。 | ||
用户点击支付订单时触发,一个订单中每种商品发送一次事件。例如一个订单中购买了2个A,3个B,4个C,发送3次Pay SPU事件","paySPU | ||
|
||
|
||
|
||
|
||
订单支付和支付订单 | ||
|
||
这不是一个地方么? | ||
","商品ID、 | ||
商品名称 | ||
商品名称、 | ||
购买数量、 | ||
支付金额、 | ||
订单ID、 | ||
支付方式",计数器 | ||
支付方式",计数器,counter | ||
订单支付成功,订单支付成功次数。用户支付成功时触发,一个订单发送一次事件。,payOrderSuccess,"订单ID、 | ||
购买数量、 | ||
支付方式、 | ||
支付金额",计数器 | ||
支付金额",计数器,counter | ||
商品支付成功,商品支付成功次数。用户支付成功时触发,一个订单中每种商品发送一次事件。例如一个订单中购买了2个A,3个B,4个C,发送3次Pay SPU Success事件,paySPUSuccess,"商品ID、 | ||
商品名称 | ||
商品名称、 | ||
购买数量、 | ||
支付金额、 | ||
订单ID、 | ||
支付方式",计数器 | ||
分享成功,分享成功时触发,shareActivity,分享渠道,计数器 | ||
支付方式",计数器,counter | ||
分享成功,分享成功时触发,shareActivity,分享渠道,计数器,counter |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
,associatedAt,createdAt,creator,description,id,key,name,scope,type,updatedAt,updater | ||
0,0,1550822373000,wangying,分享成功渠道(微信朋友圈、微信好友、微博、QQ),woVn2do2,sharechannel,分享渠道,user,String,1550822373000,wangying | ||
1,0,1550822373000,wangying,实际支付金额,QReW6joq,payAmount_var,支付金额,user,Double,1550822373000,wangying | ||
2,0,1550822373000,wangying,支付方式,nRb8pdo3,paymentMethod_var,支付方式,user,String,1550822373000,wangying | ||
3,0,1550822373000,wangying,订单金额,a9BwxORn,orderAmount,订单金额,user,Double,1550822373000,wangying | ||
4,0,1550822373000,wangying,订单ID,4PYngMoM,orderId_var,订单ID,user,String,1550822373000,wangying | ||
5,0,1550822373000,wangying,购买数量,nPNLvD9W,buyQuantity_var,购买数量,user,Int,1550822373000,wangying | ||
6,0,1550822372000,wangying,搜索词:预置搜索词,a9amer9B,searchWord_var,搜索词,user,String,1550822372000,wangying | ||
7,0,1550822372000,wangying,首页所有流量位,包括Banner、限时秒杀、GIO推荐;商品详情页推荐位,noqVWv9k,floor_var,流量位,user,String,1550822372000,wangying | ||
8,0,1550822372000,wangying,即商品的名称:例如:渠道分析手册,xRxNjXo5,productName_var,商品名称,user,String,1550822372000,wangying | ||
9,0,1550822220000,wangying,"即商品的唯一ID编号:001,002,003,004,005",xogn7BPm,productId_var,商品ID,user,String,1550822220000,wangying |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name,description,key,attribution | ||
会员等级,"会员等级",vipLevel,final |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,description,key | ||
1,"商品分类页类型 ",在商品分类页面浏览的是“为您推荐”、“电子产品”、“生活用品”、“服装” ,productListType_pvar |