traqio 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ # No trailing slash on purpose: `node_modules/` matches directories only, so a
2
+ # node_modules *symlink* (a worktree pointed at another checkout's install) slips
3
+ # past it and gets swept into a commit — an absolute path that breaks resolution
4
+ # everywhere else. Match the name, directory or not.
5
+ node_modules
6
+ dist/
7
+ # TypeScript incremental build cache. Rewritten by every `tsc`/`next build`, so a
8
+ # tracked copy makes the worktree dirty after each build (and has already triggered
9
+ # a pointless prod deploy).
10
+ *.tsbuildinfo
11
+ # pnpm-only workspace: a stray npm lockfile (e.g. left by a codemod that shells
12
+ # out to `npm install`) desyncs the tree from pnpm-lock.yaml.
13
+ package-lock.json
14
+ .next/
15
+ .turbo/
16
+ *.log
17
+
18
+ # env / secrets
19
+ .env
20
+ .env.*
21
+ !.env.example
22
+
23
+ # prisma
24
+ packages/db/generated/
25
+
26
+ # IP → country ranges, fetched by `pnpm --filter @traqio/api geo:fetch` (~30 MB,
27
+ # refreshed upstream daily — see apps/api/scripts/fetch-geo.ts)
28
+ apps/api/geo-data/
29
+
30
+ # gradle / native SDK build outputs (keep the wrapper: gradle/wrapper/, gradlew)
31
+ .gradle/
32
+ .build/
33
+ packages/sdk-*/build/
34
+ packages/sdk/android-tests/build/
35
+ packages/sdk-android/jvm-tests/build/
36
+ # e2e/ tells you to copy a gradle wrapper in — don't let that dirty the tree.
37
+ packages/sdk/e2e/fake-play-store/build/
38
+ packages/sdk/e2e/fake-play-store/app/build/
39
+ packages/sdk/e2e/fake-play-store/gradle/
40
+ packages/sdk/e2e/fake-play-store/gradlew
41
+ packages/sdk/e2e/fake-play-store/gradlew.bat
42
+ # @traqio/core + @traqio/react-native publishable JS output (tsc -p tsconfig.build.json)
43
+ packages/sdk/build/
44
+ **/build/outputs/
45
+ **/local.properties
46
+ # xcode / derived data
47
+ DerivedData/
48
+ *.xcresult
49
+
50
+ # os / editor
51
+ .DS_Store
52
+ .idea/
53
+ .vscode/
54
+
55
+ # ── khufu HQ · env convention (docs/hq/project-env.md) ──
56
+ !**/.env.enc
57
+ !.env.enc
58
+ # .NET build outputs (MAUI SDK, the Unity Editor patch tests)
59
+ packages/sdk-maui/bin/
60
+ packages/sdk-maui/obj/
61
+ packages/sdk-unity/Tests~/bin/
62
+ packages/sdk-maui/tests/bin/
63
+ packages/sdk-maui/tests/obj/
64
+ packages/sdk-unity/Tests~/obj/
65
+
66
+ # Indexing manifest (apps/web/scripts/indexing.ts) — lives in the Actions cache, never in git
67
+ .indexing/
68
+ # Sitemap lastmod manifest (apps/web/scripts/sitemapLastmod.ts) — written by each build
69
+ apps/web/generated/
traqio-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Khufu FZCO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
traqio-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,277 @@
1
+ Metadata-Version: 2.5
2
+ Name: traqio
3
+ Version: 0.1.0
4
+ Summary: Traqio server SDK for Python — report sign-ups and conversions from your backend and tie them to the ad click (trackID) the visitor came from. Django, Flask, FastAPI.
5
+ Project-URL: Homepage, https://traqio.app/docs/sdks/python
6
+ Project-URL: Documentation, https://traqio.app/docs/sdks/python
7
+ Author-email: "khufu.io" <hello@khufu.io>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: attribution,conversion-tracking,django,fastapi,roas,server-side-tracking,web-attribution
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: Django
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Framework :: Flask
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+
24
+ # traqio
25
+
26
+ The Python server SDK of [Traqio](https://traqio.app). It reports the conversions that
27
+ happen on your **backend** — a sign-up, a subscription, a purchase — and ties each one
28
+ to the ad click the visitor came from, **deterministically**.
29
+
30
+ It is the server half of Traqio's web SDK. The browser half, `@traqio/web`, keeps the
31
+ ad click id — the **trackID** — in first-party storage from the landing page to the
32
+ sign-up form. Your backend hands that trackID to this package with your own user id,
33
+ and Traqio credits the campaign that brought the user. No fingerprinting, no
34
+ guesswork, no dependency: the standard library only. Django, Flask, FastAPI or any
35
+ other framework.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install traqio
41
+ ```
42
+
43
+ Python 3.9 or later. Typed (`py.typed`).
44
+
45
+ ## Initialize
46
+
47
+ ```python
48
+ import os
49
+ from traqio import Traqio
50
+
51
+ traqio = Traqio(os.environ["TRAQIO_SECRET_KEY"])
52
+ ```
53
+
54
+ One client per process is enough. **Use a server key** (`tq_sk_…`), created in the
55
+ Traqio console under **Integrations → SDK**. It is a secret: keep it in your server's
56
+ environment, never in a page or a mobile app. It is what allows a conversion to be tied
57
+ to a click, which a public key can never do. A web key (`tq_web_…`) is refused.
58
+
59
+ ## Report the sign-up, with its trackID
60
+
61
+ Call `signup()` once, where you create the account. `@traqio/web` writes the trackID in
62
+ a `traq_click` cookie on your own domain, so it arrives with the sign-up request:
63
+
64
+ ```python
65
+ from traqio import track_id_from_request
66
+
67
+ # Django
68
+ def signup(request):
69
+ user = User.objects.create_user(...)
70
+ result = traqio.signup(str(user.pk), track_id_from_request(request))
71
+ # result.track_id: "matched" | "unknown" | "expired" | "claimed" | "refused" | None
72
+ # result.attribution.campaign_id, .network, .type
73
+ ...
74
+ ```
75
+
76
+ `track_id_from_request` reads Django, Flask and Starlette / FastAPI requests, and
77
+ returns `None` when the visitor did not come from an ad.
78
+
79
+ The sign-up is the moment the user is **acquired**. Traqio credits the **last click**
80
+ before it, inside your attribution window. If your backend is on another domain than
81
+ your site, send `Traqio.getTrackId()` from the browser with the form instead.
82
+
83
+ ### Visitors without a Traqio link: their source
84
+
85
+ A visitor from an Instagram bio, a newsletter or a Google ad with plain
86
+ `?utm_source=…&utm_campaign=…` has no trackID. `@traqio/web` keeps their origin — the
87
+ `utm_*`, `gclid` / `fbclid` / `ttclid`, the referring site — in a `traq_src` cookie.
88
+ Send it with the sign-up and Traqio reports the user under that source and campaign
89
+ (`result.source`, and the **Source / Medium / Campaign (web)** report dimensions). It
90
+ is not an ad attribution: the credit stays organic, so no ROAS moves. A trackID, when
91
+ there is one, wins.
92
+
93
+ ```python
94
+ from traqio import source_from_request, track_id_from_request
95
+
96
+ result = traqio.signup(
97
+ str(user.pk),
98
+ track_id_from_request(request),
99
+ source=source_from_request(request), # None when the visit carried nothing
100
+ )
101
+ # result.source: {"source": "instagram", "medium": "social", "campaign": "launch"}
102
+ ```
103
+
104
+ The first source sent for a user is kept. An `fbclid` / `ttclid` in it also matches the
105
+ sign-up forwarded to Meta / TikTok when no trackID click carries one. Like the trackID,
106
+ it is read from the raw `Cookie` header (the cookie value is URI-encoded).
107
+
108
+ ## Track conversions
109
+
110
+ ```python
111
+ traqio.track(
112
+ str(user.pk),
113
+ "purchase",
114
+ value=49,
115
+ currency="EUR",
116
+ transaction_id=payment_intent.id, # one payment, one row
117
+ store="stripe",
118
+ )
119
+ ```
120
+
121
+ Every event has an id (a UUID is minted when you pass no `event_id`), and a payment is
122
+ also keyed on its `transaction_id`, so a retry or a duplicate report is stored once.
123
+ Conversions follow the user: they are credited to the campaign that acquired them.
124
+
125
+ The client is synchronous. In FastAPI, keep it off the event loop with a background
126
+ task — `background_tasks.add_task(traqio.signup, str(user.id), track_id)` runs it in a
127
+ thread after the response.
128
+
129
+ ## Product analytics
130
+
131
+ `capture()` records a product-analytics event from your backend — what the console's
132
+ Analytics section reads (events, funnels, property splits), next to the events your
133
+ site and apps send. It is **not** a conversion: it goes to `/ingest/analytics/server`,
134
+ is never billed and never reaches an ad network. A purchase or a sign-up stays
135
+ `track()` / `signup()`.
136
+
137
+ ```python
138
+ traqio.capture("export_finished", user_id=str(user.pk), props={"rows": 1200})
139
+
140
+ # A subject that is not a signed-in user: an account, a visitor id @traqio/web gave you.
141
+ traqio.capture("subscription_churned", distinct_id=account.slug)
142
+
143
+ # A user's properties — a breakdown and a cohort condition in the console.
144
+ traqio.identify(str(user.pk), {"plan": "pro", "seats": 12}, {"signup_source": "sales"})
145
+ ```
146
+
147
+ One request per call, retried like the others (keep it off an event loop, as above).
148
+ Names are 1-128 characters and never start with `$` (reserved); `props` must survive
149
+ JSON and stay under 4 KB, else they are dropped and the event kept; trait values are
150
+ text, numbers or booleans — never an email or a name. There is no `screen()` on a
151
+ server: the route takes custom events only. In debug mode the events go to
152
+ Analytics › Realtime › Debug and count nowhere.
153
+
154
+ ## Groups (B2B accounts)
155
+
156
+ In B2B, your customer is an account — a company, a workspace — as much as a person.
157
+ `group()` creates or updates that account with its properties; `capture()` then names,
158
+ through `groups=`, the account each event happened in. The console's Analytics can then
159
+ count accounts instead of people: funnels and retention by account, unique accounts,
160
+ and the list of your accounts with their properties.
161
+
162
+ ```python
163
+ # After sign-in, or when the account changes (a plan change in a billing webhook):
164
+ # create or update the account. Traits may be empty — the account is created anyway.
165
+ traqio.group("company", str(org.pk), {"plan": "pro", "seats": 12})
166
+
167
+ # Every event that happens in that account names it.
168
+ traqio.capture("export_finished", user_id=str(user.pk), groups={"company": str(org.pk)})
169
+ ```
170
+
171
+ The group type is lowercase (`company`, `workspace`, `team`: a letter, then letters,
172
+ digits or `_`, 30 characters at most); the key is your own account id, 1-256
173
+ characters — never an email. A bad type or key raises `TraqioError` before any request; in
174
+ `capture()`, invalid pairs are dropped and at most 5 types are kept. Traits follow the
175
+ identify rules — never an email or a person's name. A server keeps nothing between
176
+ calls, so pass the groups on each event that belongs to an account; `resetGroups()` on
177
+ sign-out (or `reset()`) belongs to the web and app SDKs, which remember the account.
178
+
179
+ ## Alias and experiments
180
+
181
+ `alias()` says that the user known so far as `previous_id` — a guest id, a pre-sign-up
182
+ id, an id from an older system — is `user_id`. With your secret key the server merges
183
+ ALL of `previous_id`'s analytics history and properties into `user_id` (`user_id`'s own
184
+ properties win). `exposure()` records that a user saw a variant of an experiment: a
185
+ `$exposure` event the console's experiment analysis reads.
186
+
187
+ ```python
188
+ # At sign-up, when the guest becomes a user.
189
+ traqio.alias(str(user.pk), guest_id)
190
+
191
+ # Where the variant is decided — same subject arguments as capture().
192
+ traqio.exposure("checkout_v2", "treatment", {"surface": "web"}, user_id=str(user.pk))
193
+ ```
194
+
195
+ Both ids are 1-256 characters and must differ; the experiment and variant are 1-200
196
+ characters and win over a prop of the same name. Anything else raises `TraqioError`
197
+ before any request. There is no `reset()` on a server — it keeps no user between
198
+ calls; call `reset()` at sign-out in the web and app SDKs.
199
+
200
+ ## What it does today
201
+
202
+ - Ties a sign-up to its click and answers with the credited campaign — **yes**.
203
+ - Records conversions with value, currency and payment id, deduplicated — **yes**.
204
+ - Leaves your mobile apps' installs, revenue and ROAS untouched: a conversion sent
205
+ here is never attached to an app install — **yes**.
206
+ - Shows web conversions in the console's reports — **not yet**; the API response is
207
+ where you read the attribution today.
208
+ - Sends web conversions to Meta (Conversions API) and TikTok (Events API), with the ad
209
+ click's `fbclid` / `ttclid` — **yes**, to the product's destinations set in the console.
210
+
211
+ ### Meta and TikTok: consent, context and the pixel's event id
212
+
213
+ ```python
214
+ from traqio import web_context_from_request
215
+
216
+ traqio.track(
217
+ order.user_id,
218
+ "purchase",
219
+ value=order.total,
220
+ currency="EUR",
221
+ event_id=order.id, # the same id your pixel fires with, so each network keeps one
222
+ consent="granted", # your banner's answer; "denied" keeps it away from the networks
223
+ context=web_context_from_request(request), # IP, user agent, page, _fbp/_fbc/_ttp/ttclid
224
+ )
225
+ ```
226
+
227
+ `context` is never stored by Traqio; `web_context_from_request(request)` reads it off the request.
228
+
229
+ ## Errors and retries
230
+
231
+ A network error, a timeout, a `429` or a `5xx` is retried (twice by default) with the
232
+ same body, so nothing is counted twice. A `4xx` — a wrong key, an invalid payload — is
233
+ not retried. Both end as a `TraqioError` with `.status` and `.body`:
234
+
235
+ ```python
236
+ from traqio import TraqioError
237
+
238
+ try:
239
+ traqio.signup(str(user.pk), track_id)
240
+ except TraqioError as error:
241
+ logger.warning("traqio: %s (status %s)", error, error.status) # never fail the sign-up
242
+ ```
243
+
244
+ ## Options
245
+
246
+ | Option | Default | |
247
+ | --- | --- | --- |
248
+ | `secret_key` | — | Your server key, `tq_sk_…` (first argument, required) |
249
+ | `endpoint` | `https://api.traqio.app` | Origin of the Traqio API |
250
+ | `timeout` | `10.0` | Seconds per attempt |
251
+ | `max_retries` | `2` | Retries after a network error, a 429 or a 5xx |
252
+ | `transport` | `urllib` | A custom transport (proxies, tests) |
253
+ | `debug` | auto | `True` / `False` forces debug mode on or off — see below |
254
+
255
+ ## Debug mode
256
+
257
+ Calls from a development machine are flagged as debug traffic. The client turns it on
258
+ by itself when `TRAQIO_DEBUG` is `1` or `true`, or when Python runs in development
259
+ mode (`python -X dev`); anything else is production. `Traqio(key, debug=True)` or
260
+ `debug=False` overrides the detection, and `traqio.is_debug` tells which mode is on.
261
+
262
+ Debug traffic shows in the console's **Debug** view, but it is never counted,
263
+ attributed, forwarded to ad networks or billed.
264
+
265
+ ## Requirements
266
+
267
+ Python 3.9+, no dependency. A Traqio product with a server key, and `@traqio/web`
268
+ on the site so the trackID is kept until sign-up.
269
+
270
+ ## Documentation
271
+
272
+ Full guide, the trackID and how web attribution works:
273
+ https://traqio.app/docs/sdks/python
274
+
275
+ ## License
276
+
277
+ MIT
traqio-0.1.0/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # traqio
2
+
3
+ The Python server SDK of [Traqio](https://traqio.app). It reports the conversions that
4
+ happen on your **backend** — a sign-up, a subscription, a purchase — and ties each one
5
+ to the ad click the visitor came from, **deterministically**.
6
+
7
+ It is the server half of Traqio's web SDK. The browser half, `@traqio/web`, keeps the
8
+ ad click id — the **trackID** — in first-party storage from the landing page to the
9
+ sign-up form. Your backend hands that trackID to this package with your own user id,
10
+ and Traqio credits the campaign that brought the user. No fingerprinting, no
11
+ guesswork, no dependency: the standard library only. Django, Flask, FastAPI or any
12
+ other framework.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pip install traqio
18
+ ```
19
+
20
+ Python 3.9 or later. Typed (`py.typed`).
21
+
22
+ ## Initialize
23
+
24
+ ```python
25
+ import os
26
+ from traqio import Traqio
27
+
28
+ traqio = Traqio(os.environ["TRAQIO_SECRET_KEY"])
29
+ ```
30
+
31
+ One client per process is enough. **Use a server key** (`tq_sk_…`), created in the
32
+ Traqio console under **Integrations → SDK**. It is a secret: keep it in your server's
33
+ environment, never in a page or a mobile app. It is what allows a conversion to be tied
34
+ to a click, which a public key can never do. A web key (`tq_web_…`) is refused.
35
+
36
+ ## Report the sign-up, with its trackID
37
+
38
+ Call `signup()` once, where you create the account. `@traqio/web` writes the trackID in
39
+ a `traq_click` cookie on your own domain, so it arrives with the sign-up request:
40
+
41
+ ```python
42
+ from traqio import track_id_from_request
43
+
44
+ # Django
45
+ def signup(request):
46
+ user = User.objects.create_user(...)
47
+ result = traqio.signup(str(user.pk), track_id_from_request(request))
48
+ # result.track_id: "matched" | "unknown" | "expired" | "claimed" | "refused" | None
49
+ # result.attribution.campaign_id, .network, .type
50
+ ...
51
+ ```
52
+
53
+ `track_id_from_request` reads Django, Flask and Starlette / FastAPI requests, and
54
+ returns `None` when the visitor did not come from an ad.
55
+
56
+ The sign-up is the moment the user is **acquired**. Traqio credits the **last click**
57
+ before it, inside your attribution window. If your backend is on another domain than
58
+ your site, send `Traqio.getTrackId()` from the browser with the form instead.
59
+
60
+ ### Visitors without a Traqio link: their source
61
+
62
+ A visitor from an Instagram bio, a newsletter or a Google ad with plain
63
+ `?utm_source=…&utm_campaign=…` has no trackID. `@traqio/web` keeps their origin — the
64
+ `utm_*`, `gclid` / `fbclid` / `ttclid`, the referring site — in a `traq_src` cookie.
65
+ Send it with the sign-up and Traqio reports the user under that source and campaign
66
+ (`result.source`, and the **Source / Medium / Campaign (web)** report dimensions). It
67
+ is not an ad attribution: the credit stays organic, so no ROAS moves. A trackID, when
68
+ there is one, wins.
69
+
70
+ ```python
71
+ from traqio import source_from_request, track_id_from_request
72
+
73
+ result = traqio.signup(
74
+ str(user.pk),
75
+ track_id_from_request(request),
76
+ source=source_from_request(request), # None when the visit carried nothing
77
+ )
78
+ # result.source: {"source": "instagram", "medium": "social", "campaign": "launch"}
79
+ ```
80
+
81
+ The first source sent for a user is kept. An `fbclid` / `ttclid` in it also matches the
82
+ sign-up forwarded to Meta / TikTok when no trackID click carries one. Like the trackID,
83
+ it is read from the raw `Cookie` header (the cookie value is URI-encoded).
84
+
85
+ ## Track conversions
86
+
87
+ ```python
88
+ traqio.track(
89
+ str(user.pk),
90
+ "purchase",
91
+ value=49,
92
+ currency="EUR",
93
+ transaction_id=payment_intent.id, # one payment, one row
94
+ store="stripe",
95
+ )
96
+ ```
97
+
98
+ Every event has an id (a UUID is minted when you pass no `event_id`), and a payment is
99
+ also keyed on its `transaction_id`, so a retry or a duplicate report is stored once.
100
+ Conversions follow the user: they are credited to the campaign that acquired them.
101
+
102
+ The client is synchronous. In FastAPI, keep it off the event loop with a background
103
+ task — `background_tasks.add_task(traqio.signup, str(user.id), track_id)` runs it in a
104
+ thread after the response.
105
+
106
+ ## Product analytics
107
+
108
+ `capture()` records a product-analytics event from your backend — what the console's
109
+ Analytics section reads (events, funnels, property splits), next to the events your
110
+ site and apps send. It is **not** a conversion: it goes to `/ingest/analytics/server`,
111
+ is never billed and never reaches an ad network. A purchase or a sign-up stays
112
+ `track()` / `signup()`.
113
+
114
+ ```python
115
+ traqio.capture("export_finished", user_id=str(user.pk), props={"rows": 1200})
116
+
117
+ # A subject that is not a signed-in user: an account, a visitor id @traqio/web gave you.
118
+ traqio.capture("subscription_churned", distinct_id=account.slug)
119
+
120
+ # A user's properties — a breakdown and a cohort condition in the console.
121
+ traqio.identify(str(user.pk), {"plan": "pro", "seats": 12}, {"signup_source": "sales"})
122
+ ```
123
+
124
+ One request per call, retried like the others (keep it off an event loop, as above).
125
+ Names are 1-128 characters and never start with `$` (reserved); `props` must survive
126
+ JSON and stay under 4 KB, else they are dropped and the event kept; trait values are
127
+ text, numbers or booleans — never an email or a name. There is no `screen()` on a
128
+ server: the route takes custom events only. In debug mode the events go to
129
+ Analytics › Realtime › Debug and count nowhere.
130
+
131
+ ## Groups (B2B accounts)
132
+
133
+ In B2B, your customer is an account — a company, a workspace — as much as a person.
134
+ `group()` creates or updates that account with its properties; `capture()` then names,
135
+ through `groups=`, the account each event happened in. The console's Analytics can then
136
+ count accounts instead of people: funnels and retention by account, unique accounts,
137
+ and the list of your accounts with their properties.
138
+
139
+ ```python
140
+ # After sign-in, or when the account changes (a plan change in a billing webhook):
141
+ # create or update the account. Traits may be empty — the account is created anyway.
142
+ traqio.group("company", str(org.pk), {"plan": "pro", "seats": 12})
143
+
144
+ # Every event that happens in that account names it.
145
+ traqio.capture("export_finished", user_id=str(user.pk), groups={"company": str(org.pk)})
146
+ ```
147
+
148
+ The group type is lowercase (`company`, `workspace`, `team`: a letter, then letters,
149
+ digits or `_`, 30 characters at most); the key is your own account id, 1-256
150
+ characters — never an email. A bad type or key raises `TraqioError` before any request; in
151
+ `capture()`, invalid pairs are dropped and at most 5 types are kept. Traits follow the
152
+ identify rules — never an email or a person's name. A server keeps nothing between
153
+ calls, so pass the groups on each event that belongs to an account; `resetGroups()` on
154
+ sign-out (or `reset()`) belongs to the web and app SDKs, which remember the account.
155
+
156
+ ## Alias and experiments
157
+
158
+ `alias()` says that the user known so far as `previous_id` — a guest id, a pre-sign-up
159
+ id, an id from an older system — is `user_id`. With your secret key the server merges
160
+ ALL of `previous_id`'s analytics history and properties into `user_id` (`user_id`'s own
161
+ properties win). `exposure()` records that a user saw a variant of an experiment: a
162
+ `$exposure` event the console's experiment analysis reads.
163
+
164
+ ```python
165
+ # At sign-up, when the guest becomes a user.
166
+ traqio.alias(str(user.pk), guest_id)
167
+
168
+ # Where the variant is decided — same subject arguments as capture().
169
+ traqio.exposure("checkout_v2", "treatment", {"surface": "web"}, user_id=str(user.pk))
170
+ ```
171
+
172
+ Both ids are 1-256 characters and must differ; the experiment and variant are 1-200
173
+ characters and win over a prop of the same name. Anything else raises `TraqioError`
174
+ before any request. There is no `reset()` on a server — it keeps no user between
175
+ calls; call `reset()` at sign-out in the web and app SDKs.
176
+
177
+ ## What it does today
178
+
179
+ - Ties a sign-up to its click and answers with the credited campaign — **yes**.
180
+ - Records conversions with value, currency and payment id, deduplicated — **yes**.
181
+ - Leaves your mobile apps' installs, revenue and ROAS untouched: a conversion sent
182
+ here is never attached to an app install — **yes**.
183
+ - Shows web conversions in the console's reports — **not yet**; the API response is
184
+ where you read the attribution today.
185
+ - Sends web conversions to Meta (Conversions API) and TikTok (Events API), with the ad
186
+ click's `fbclid` / `ttclid` — **yes**, to the product's destinations set in the console.
187
+
188
+ ### Meta and TikTok: consent, context and the pixel's event id
189
+
190
+ ```python
191
+ from traqio import web_context_from_request
192
+
193
+ traqio.track(
194
+ order.user_id,
195
+ "purchase",
196
+ value=order.total,
197
+ currency="EUR",
198
+ event_id=order.id, # the same id your pixel fires with, so each network keeps one
199
+ consent="granted", # your banner's answer; "denied" keeps it away from the networks
200
+ context=web_context_from_request(request), # IP, user agent, page, _fbp/_fbc/_ttp/ttclid
201
+ )
202
+ ```
203
+
204
+ `context` is never stored by Traqio; `web_context_from_request(request)` reads it off the request.
205
+
206
+ ## Errors and retries
207
+
208
+ A network error, a timeout, a `429` or a `5xx` is retried (twice by default) with the
209
+ same body, so nothing is counted twice. A `4xx` — a wrong key, an invalid payload — is
210
+ not retried. Both end as a `TraqioError` with `.status` and `.body`:
211
+
212
+ ```python
213
+ from traqio import TraqioError
214
+
215
+ try:
216
+ traqio.signup(str(user.pk), track_id)
217
+ except TraqioError as error:
218
+ logger.warning("traqio: %s (status %s)", error, error.status) # never fail the sign-up
219
+ ```
220
+
221
+ ## Options
222
+
223
+ | Option | Default | |
224
+ | --- | --- | --- |
225
+ | `secret_key` | — | Your server key, `tq_sk_…` (first argument, required) |
226
+ | `endpoint` | `https://api.traqio.app` | Origin of the Traqio API |
227
+ | `timeout` | `10.0` | Seconds per attempt |
228
+ | `max_retries` | `2` | Retries after a network error, a 429 or a 5xx |
229
+ | `transport` | `urllib` | A custom transport (proxies, tests) |
230
+ | `debug` | auto | `True` / `False` forces debug mode on or off — see below |
231
+
232
+ ## Debug mode
233
+
234
+ Calls from a development machine are flagged as debug traffic. The client turns it on
235
+ by itself when `TRAQIO_DEBUG` is `1` or `true`, or when Python runs in development
236
+ mode (`python -X dev`); anything else is production. `Traqio(key, debug=True)` or
237
+ `debug=False` overrides the detection, and `traqio.is_debug` tells which mode is on.
238
+
239
+ Debug traffic shows in the console's **Debug** view, but it is never counted,
240
+ attributed, forwarded to ad networks or billed.
241
+
242
+ ## Requirements
243
+
244
+ Python 3.9+, no dependency. A Traqio product with a server key, and `@traqio/web`
245
+ on the site so the trackID is kept until sign-up.
246
+
247
+ ## Documentation
248
+
249
+ Full guide, the trackID and how web attribution works:
250
+ https://traqio.app/docs/sdks/python
251
+
252
+ ## License
253
+
254
+ MIT
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "traqio"
7
+ version = "0.1.0"
8
+ description = "Traqio server SDK for Python — report sign-ups and conversions from your backend and tie them to the ad click (trackID) the visitor came from. Django, Flask, FastAPI."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.9"
12
+ authors = [{ name = "khufu.io", email = "hello@khufu.io" }]
13
+ keywords = ["attribution", "web-attribution", "server-side-tracking", "conversion-tracking", "roas", "django", "fastapi"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Framework :: Django",
22
+ "Framework :: FastAPI",
23
+ "Framework :: Flask",
24
+ "Typing :: Typed",
25
+ ]
26
+ dependencies = []
27
+
28
+ [project.urls]
29
+ Homepage = "https://traqio.app/docs/sdks/python"
30
+ Documentation = "https://traqio.app/docs/sdks/python"
31
+
32
+ [tool.hatch.build.targets.sdist]
33
+ include = ["src/traqio", "tests", "README.md", "LICENSE", "pyproject.toml"]
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["src/traqio"]