forked from snowplow/snowplow-python-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (26 loc) · 976 Bytes
/
app.py
File metadata and controls
38 lines (26 loc) · 976 Bytes
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
from distutils.log import error
from snowplow_tracker import Tracker, Emitter, Subject, SelfDescribingJson
import sys
def get_url_from_args():
if len(sys.argv) != 2:
raise ValueError("Collector Endpoint is required")
return sys.argv[1]
def main():
collector_url = get_url_from_args()
e = Emitter(collector_url)
s = Subject().set_platform("pc")
s.set_lang("en").set_user_id("test_user")
t = Tracker(e, s)
print("Sending events to " + collector_url)
t.track_page_view("https://www.snowplow.io", "Homepage")
t.track_page_ping("https://www.snowplow.io", "Homepage")
t.track_link_click("https://www.snowplow.io")
t.track_self_describing_event(
SelfDescribingJson(
"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",
{"targetUrl": "example.com"},
)
)
t.track_struct_event("shop", "add-to-basket", None, "pcs", 2)
if __name__ == "__main__":
main()