|
1 | 1 | import hashlib |
2 | | - |
3 | | -# import smtplib |
4 | 2 | import uuid |
5 | 3 | from collections import UserDict |
6 | | -from email.mime.multipart import MIMEMultipart |
7 | | -from email.mime.text import MIMEText |
8 | 4 | from ipaddress import IPv4Address, IPv6Address, ip_address |
9 | 5 | from pprint import pformat |
10 | 6 | from random import randint |
11 | 7 | from typing import Union |
12 | | -from urllib.parse import urlencode |
13 | 8 |
|
14 | 9 |
|
15 | 10 | class Event(UserDict): |
@@ -77,38 +72,8 @@ def _cid(self, version): |
77 | 72 | elif version == 2: |
78 | 73 | return self._cid_v2() |
79 | 74 |
|
80 | | - # this is a required GA field |
81 | 75 | raise ValueError("CID Version.") |
82 | 76 |
|
83 | | - def to_GA_payload(self, tracking_id, cid_version=1): |
84 | | - # by default implements |
85 | | - # a GA PageView hit-type |
86 | | - |
87 | | - # In the future, consider adding additional |
88 | | - # keys as cutomized dimensions or metrics. |
89 | | - |
90 | | - payload = { |
91 | | - "v": 1, # protocol version |
92 | | - "t": "pageview", |
93 | | - "tid": tracking_id, |
94 | | - "cid": self._cid(cid_version), |
95 | | - "uip": self.user_ip, |
96 | | - "dh": self.host, |
97 | | - "dp": self.path, |
98 | | - } |
99 | | - |
100 | | - # add document referer |
101 | | - if isinstance(self.referer, str): |
102 | | - if len(self.referer) <= 2048: # GA Limit |
103 | | - payload["dr"] = self.referer |
104 | | - |
105 | | - # add user_agent |
106 | | - if self.user_agent: |
107 | | - payload["ua"] = self.user_agent |
108 | | - |
109 | | - # this also escapes payload vals |
110 | | - return [urlencode(payload)] |
111 | | - |
112 | 77 | def to_GA4_payload(self, measurement_id, cid_version=1): |
113 | 78 | # Document about page_view event: https://support.google.com/analytics/answer/9964640#pageviews&zippy=%2Cin-this-article |
114 | 79 | # GA4 does not support [Document path as UA](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dp) |
@@ -154,32 +119,6 @@ class GAEvent(Event): |
154 | 119 | # "value": "60" |
155 | 120 | # } |
156 | 121 |
|
157 | | - def to_GA_payload(self, tracking_id, cid_version=1): |
158 | | - payloads = super().to_GA_payload(tracking_id, cid_version) |
159 | | - if self.get("category") and self.get("action"): |
160 | | - payloads.append( |
161 | | - urlencode( |
162 | | - _clean( |
163 | | - { |
164 | | - "v": 1, # protocol version |
165 | | - "t": "event", |
166 | | - "tid": tracking_id, |
167 | | - "cid": self._cid(cid_version), |
168 | | - "ec": self["category"], |
169 | | - "ea": self["action"], |
170 | | - "el": self.get("label", ""), |
171 | | - "ev": self.get("value", ""), |
172 | | - } |
173 | | - ) |
174 | | - ) |
175 | | - ) |
176 | | - for event in self.get("__secondary__", []): |
177 | | - event["__request__"] = self["__request__"] |
178 | | - payloads.extend(event.to_GA_payload(tracking_id, cid_version)[1:]) |
179 | | - # ignore the first event (pageview) |
180 | | - # which is already generated once |
181 | | - return payloads |
182 | | - |
183 | 122 | def to_GA4_payload(self, measurement_id, cid_version=1): |
184 | 123 | payloads = super().to_GA4_payload(measurement_id, cid_version) |
185 | 124 | if self.get("category") and self.get("action"): |
|
0 commit comments