openemail.tracking
Каждый метод этого пространства имён: его сигнатура, параметры, что он возвращает, и пример.
Методы
Opens and clicks on tracked messages, one message at a time or rolled up.
tracking.list()
List one page of tracked messages in a time window
def list( *, limit: int | None = None, cursor: str | None = None, opened: bool | None = None, clicked: bool | None = None, days: int | None = None, minutes: int | None = None, grain: TrackingGrain | None = None, api_key: str | None = None, timeout: float | None = None,) -> Page[TrackingResource]Returns one page of the messages the workspace tracked and sent in the window, newest first, each as a full engagement report with its recipients and links. It covers the whole mailbox, not only mail sent through this API: messages from the composer, the MCP tools and the assistant appear too, with sendId set to None where no send record exists. A report built off emails.list would describe the API rather than the mailbox.
Messages that carried no pixel and no rewritten link are absent entirely and never appear as a zero. opened=False therefore means tracked and not opened, and clicked= narrows the same way. Both filters work on counted opens and clicks, so a message fetched only by Apple Mail Privacy Protection or a link scanner still counts as unopened.
The window defaults to 30 days. minutes= wins over days= when both are set, and the start of the window is floored to the grain in UTC, so days=7 covers today plus the six whole days before it. Paging is keyset: nextCursor is the tmsg_ id of the last report on the page, and passing it back as cursor= with the same filters continues strictly after it, so every tracked message in the window is reachable. list_all and iterate do that walk for you.
Параметры
limitintReports per page, from 1 to 200, defaulting to 50.
cursorstrThe
nextCursorfrom the previous page, atmsg_id. One that names no tracked message in the workspace is a 400invalid_cursor.openedboolLeave it out for both.
Truekeeps opened messages andFalsekeeps tracked messages nobody opened.clickedboolLeave it out for both.
Truekeeps messages with a counted click andFalsekeeps those without.daysintWindow length in days, a whole number from 1 to 365, defaulting to 30.
minutesintWindow length in minutes, from 1 to 527040. Takes precedence over
days.grainTrackingGrainminute,hourorday, defaulting today. It only floors the window start so this list matchesget_statsread at the same grain, and shapes nothing in the response.api_keystrLists with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
Page[TrackingResource], a dict with items, hasMore and nextCursor. Each item has id, sendId, subject, from, source, sentAt, opens, clicks, opened, clicked, attributable, the counted and raw open and click counts, recipients and links.
Пример
from openemail import openemail page = openemail.tracking.list(opened=False, days=7, limit=200) for message in page['items']: print(message['sentAt'], message['subject'], len(message['recipients'])) if page['hasMore']: following = openemail.tracking.list( opened=False, days=7, limit=200, cursor=page['nextCursor'] ) print(len(following['items']))Примечания
A window shorter than a day needs a finer grain.
minutes=60at the defaultdaygrain is rounded to one bucket and starts at midnight UTC.A key with an address allowlist sees only messages sent from those addresses.
Only messages that were actually sent are listed, so a scheduled message that has not gone yet is absent even if tracking was requested.
Также доступно в
- API
GET /tracking- TypeScript
tracking.list()- Ruby
tracking.list- CLI
openemail tracking list
tracking.list_all()
Collect every tracked message in a window into one list
def list_all( *, limit: int | None = None, cursor: str | None = None, opened: bool | None = None, clicked: bool | None = None, days: int | None = None, minutes: int | None = None, grain: TrackingGrain | None = None, api_key: str | None = None, timeout: float | None = None,) -> builtins.list[TrackingResource]Follows nextCursor from page to page and returns once the last page has been read, with every tracked message in the window in one list, newest first. It takes the same filters as list and returns the same full engagement reports.
Everything is held in memory before the call returns. Narrow the window or the filters, or switch to iterate when you want to stop early. limit= sets the page size of each underlying request, not the total.
Параметры
limitintPage size per request, from 1 to 200, defaulting to 50 on the server.
cursorstrA
tmsg_id to start after, skipping everything newer.openedboolLeave it out for both.
Truekeeps opened messages andFalsekeeps tracked messages nobody opened.clickedboolLeave it out for both.
Truekeeps messages with a counted click andFalsekeeps those without.daysintWindow length in days, a whole number from 1 to 365, defaulting to 30.
minutesintWindow length in minutes, from 1 to 527040. Takes precedence over
days.grainTrackingGrainminute,hourorday, defaulting today. It only floors the window start.api_keystrLists with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
list[TrackingResource] holding every report across all pages.
Пример
from openemail import openemail unopened = openemail.tracking.list_all(opened=False, days=30, limit=200) print(len(unopened), [message['subject'] for message in unopened])Примечания
A failure on any page raises, and the reports already fetched are discarded.
A key with an address allowlist sees only messages sent from those addresses, on every page.
Также доступно в
- API
GET /tracking- TypeScript
tracking.listAll()- Ruby
tracking.list_all
tracking.iterate()
Stream tracked messages one at a time across pages
def iterate( *, limit: int | None = None, cursor: str | None = None, opened: bool | None = None, clicked: bool | None = None, days: int | None = None, minutes: int | None = None, grain: TrackingGrain | None = None, api_key: str | None = None, timeout: float | None = None,) -> Iterator[TrackingResource]Returns a generator that yields tracked messages one at a time, newest first, and requests the next page only once the current one is drained. Nothing is fetched until you start consuming it, and breaking out of the loop stops the requests.
The walk is keyset based, following nextCursor from page to page, so a message tracked while you iterate lands ahead of where you started and is never yielded, and nothing already yielded comes round again.
Параметры
limitintPage size per request, from 1 to 200, defaulting to 50 on the server.
cursorstrA
tmsg_id to start after, skipping everything newer.openedboolLeave it out for both.
Truekeeps opened messages andFalsekeeps tracked messages nobody opened.clickedboolLeave it out for both.
Truekeeps messages with a counted click andFalsekeeps those without.daysintWindow length in days, a whole number from 1 to 365, defaulting to 30.
minutesintWindow length in minutes, from 1 to 527040. Takes precedence over
days.grainTrackingGrainminute,hourorday, defaulting today. It only floors the window start.api_keystrLists with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
Iterator[TrackingResource], a generator that yields one report per step.
Пример
from openemail import openemail for message in openemail.tracking.iterate(clicked=True, days=90): if any('/pricing' in link['url'] for link in message['links']): print(message['id'], message['subject']) breakПримечания
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Также доступно в
- API
GET /tracking- TypeScript
tracking.iterate()- Ruby
tracking.iterate
tracking.get_stats()
Summarise engagement across a time window
def get_stats( *, days: int | None = None, minutes: int | None = None, grain: TrackingGrain | None = None, offset_minutes: int | None = None, api_key: str | None = None, timeout: float | None = None,) -> TrackingStatsResourceReturns the numbers behind an engagement panel in one request: how many messages were tracked, opened and clicked, the open and click rates, hit totals, a time series, the top links, mail clients and countries. It covers every tracked message sent from the mailbox in the window, whichever surface sent it.
Rates and totals count different things, and mixing them is how open rates above 100% get published. opened and clicked count distinct messages. totalOpens and totalClicks count hits. openRate is a percentage of trackedForOpens, the messages that actually carried a pixel, and clickRate is a percentage of trackedForClicks, the messages that had a link to rewrite, which is usually far fewer than tracked because most replies contain no links.
byDay is sparse: a bucket in which nothing was sent has no entry, so a chart must fill the gaps. grain= sets the bucket width and the key shape, YYYY-MM-DD, YYYY-MM-DDTHH or YYYY-MM-DDTHH:MM, and offset_minutes= shifts bucket boundaries so days break where the reader's day does. The window starts at the beginning of the oldest bucket, so that bucket is whole, and ends now, so the newest is partial.
Параметры
daysintWindow length in days, from 1 to 365, defaulting to 30.
minutesintWindow length in minutes, from 1 to 527040. Takes precedence over
days, and only useful below a day with a finergrain.grainTrackingGrainBucket width for
byDay:minute,hourorday, defaulting today.offset_minutesintMinutes east of UTC to bucket in, from -840 to 840, defaulting to 0. Pass
time.localtime().tm_gmtoff // 60for the zone the code runs in.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
TrackingStatsResource with tracked, trackedForOpens, trackedForClicks, opened, clicked, openRate, clickRate, totalOpens, totalClicks, machineOpens, medianTimeToOpenSeconds (None when nothing was opened), byDay, topLinks, clients and countries.
Пример
import time from openemail import openemail stats = openemail.tracking.get_stats( days=7, grain='day', offset_minutes=time.localtime().tm_gmtoff // 60) print(stats['openRate'], 'percent of', stats['trackedForOpens'], 'messages opened')print(stats['byDay'], stats['topLinks'][:3])Примечания
openRateandclickRateare percentages rounded to one decimal place, such as42.5, not fractions between 0 and 1.machineOpens,clientsandcountriesare counted from individual hit records rather than from the counters on the per-message report.A key with an address allowlist gets figures for mail sent from those addresses only, not the whole workspace.
topLinksholds at most 10 links that were clicked at least once, whileclientsandcountrieshold at most 8 each.
Также доступно в
tracking.get()
Read one message's engagement report
def get( id: str, *, api_key: str | None = None, timeout: float | None = None,) -> TrackingResourceReturns the whole report for one tracked message: totals, one entry per tracked copy under recipients, and every rewritten link with its clicks under links. It accepts either identifier a caller may hold. A msg_ id is looked up as the send it went out as, and anything else is treated as a tmsg_ tracking id, which is what tracking.list and webhook payloads carry for mail sent outside this API.
openCount and clickCount are counted readings: opens that looked like a person, with repeat fetches within thirty seconds collapsed. openCountRaw and clickCountRaw include every hit, machine fetches such as Apple Mail Privacy Protection and corporate scanners among them. Gmail's image proxy is a real person displaying the message and is counted, but only once, because later views are served from its cache.
recipients is one entry per tracked copy, which is not always one entry per person. When one body went to the whole list, or the bytes could not vary per recipient, the shared copy has email set to None and attributed set to False. Branch on attributed and on the message-level attributable before saying that a named person has or has not read anything.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
TrackingResource with id, sendId, threadId, subject, from, source, sentAt, opens, clicks, opened, clicked, attributable, counted and raw open and click counts, first and last open and click times, recipients and links.
Пример
from openemail import openemail report = openemail.tracking.get('tmsg_8b2e4d71c09f3a65e1d7b402')followed = [link['label'] or link['url'] for link in report['links'] if link['clickCount']] print(report['opened'], report['openCount'], report['openCountRaw'])print(followed)Примечания
A 404 means nothing was tracked for that message, which is not the same as nobody having opened it.
opensandclicksrecord what was applied when the message was sent. Turning tracking on later does not make earlier mail start reporting.Only links in the new part of a body are rewritten, so quoted history under a reply never appears in
links.
Также доступно в
- API
GET /tracking/{id}- TypeScript
tracking.get()- Ruby
tracking.get- CLI
openemail tracking get
tracking.list_opens()
List the individual opens behind a message's open count
def list_opens( id: str, *, limit: int | None = None, cursor: str | None = None, include_machine: bool | None = None, api_key: str | None = None, timeout: float | None = None,) -> Page[TrackingOpenResource]Returns one page of the raw open hits for one tracked message, newest first. nextCursor is the opn_ id of the last hit on the page, and passing it back as cursor= continues strictly after it, so every stored hit is reachable. list_all_opens and iterate_opens do that walk for you. Each hit says which copy was fetched, how it was classified, whether it moved the numbers, and what the User-Agent and the edge could tell about the client, device and location.
kind is human for something that looked like a person reading, proxy for an image proxy such as Gmail's, which is a genuine reading by a reader the tracker cannot see, and machine for a scanner or Apple Mail Privacy Protection, which fetches on delivery and only proves the message arrived. By default only counted hits come back. include_machine=True adds the hits that did not count, which is every machine hit plus repeat fetches within thirty seconds of a counted one on the same copy, so it filters on counted rather than on kind.
A msg_ send id is resolved first, and one that names no tracked message is a 404 rather than an empty list, since an empty list reads as nobody having opened it. A tmsg_ id is taken as given without a lookup, so one that never existed or belongs to another workspace comes back as an empty list. Only read an empty result as an answer about readers when the id came from this API.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.limitintHits per page, from 1 to 200, defaulting to 50.
cursorstrThe
nextCursorfrom the previous page, anopn_id. Anything else, or one from another message's log, is a 400invalid_cursor.include_machineboolDefaults to
False.Truealso returns hits withcountedset toFalse, machine fetches and collapsed repeats alike.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
Page[TrackingOpenResource], a dict with items, hasMore and nextCursor. Each item has object set to open, id, trackedMessageId, recipient, kind, counted, userAgent, client, device, os, country, region, city and createdAt.
Пример
from openemail import openemail page = openemail.tracking.list_opens( 'msg_3f9a1c07d2b84e6a9c5b1f20', include_machine=True, limit=200)machine = [hit for hit in page['items'] if hit['kind'] == 'machine'] print(len(page['items']), len(machine), page['hasMore'])Примечания
An open row carries no IP address, and
country,regionandcityare what the edge already knew, so on a proxied hit they describe the proxy rather than the reader. The address the request came from is still kept: it goes into the event log for the message, whichemails.list_eventsreturns, and into theemail.openedwebhook payload.recipientisNoneon a shared copy, for the same reasonemailon that copy's entry inrecipientsisNoneon the report.
Также доступно в
tracking.list_all_opens()
Collect every open hit on one message into one list
def list_all_opens( id: str, *, limit: int | None = None, cursor: str | None = None, include_machine: bool | None = None, api_key: str | None = None, timeout: float | None = None,) -> builtins.list[TrackingOpenResource]Walks every page of one tracked message's open log and returns all of its hits in one list, newest first. It takes the same arguments as list_opens, so by default only counted hits come back and include_machine=True adds the rest.
A message opened by a mailing list of thousands can hold a great many rows. Prefer iterate_opens when you can stop early. limit= sets the page size of each request, not the total.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.limitintPage size per request, from 1 to 200, defaulting to 50 on the server.
cursorstrAn
opn_id to start after, skipping every newer open.include_machineboolDefaults to
False.Truealso returns hits withcountedset toFalse.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
list[TrackingOpenResource] holding every hit across all pages, newest first.
Пример
from collections import Counter from openemail import openemail opens = openemail.tracking.list_all_opens( 'msg_3f9a1c07d2b84e6a9c5b1f20', include_machine=True, limit=200)by_country = Counter(hit['country'] or 'unknown' for hit in opens) print(by_country.most_common(5))Примечания
A failure on any page raises, and the hits already fetched are discarded.
The same id rules as
list_opensapply: amsg_id that names no tracked message is a 404, and an unknowntmsg_id collects an empty list.
Также доступно в
tracking.iterate_opens()
Stream the open hits on one message one at a time
def iterate_opens( id: str, *, limit: int | None = None, cursor: str | None = None, include_machine: bool | None = None, api_key: str | None = None, timeout: float | None = None,) -> Iterator[TrackingOpenResource]Returns a generator over one tracked message's open log that yields hits one at a time, newest first, and fetches the next page only when the current one is drained. Nothing is requested until you consume it, and breaking out of the loop stops further requests.
The walk ends when hasMore is False. Hits recorded after the walk starts are newer than its cursor and are not yielded.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.limitintPage size per request, from 1 to 200, defaulting to 50 on the server.
cursorstrAn
opn_id to start after, skipping every newer open.include_machineboolDefaults to
False.Truealso returns hits withcountedset toFalse.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
Iterator[TrackingOpenResource], a generator that yields one hit per step.
Пример
from openemail import openemail for hit in openemail.tracking.iterate_opens('tmsg_8b2e4d71c09f3a65e1d7b402'): if hit['kind'] == 'human': print('Most recently read by a person at', hit['createdAt'], 'in', hit['client']) breakПримечания
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Также доступно в
tracking.list_clicks()
List the individual link clicks on a message
def list_clicks( id: str, *, limit: int | None = None, cursor: str | None = None, include_machine: bool | None = None, api_key: str | None = None, timeout: float | None = None,) -> Page[TrackingClickResource]Returns one page of the raw click hits for one tracked message, newest first. nextCursor is the clk_ id of the last hit on the page, and passing it back as cursor= continues strictly after it, so every stored hit is reachable. list_all_clicks and iterate_clicks do that walk for you. Each hit has the same classification and client detail as an open, plus linkId and url naming the link that was followed, where url is the original destination rather than the redirect.
A click is stronger evidence of reading than an open. Mail clients block images far more often than readers leave links unfollowed, so a message with clicks and no opens was certainly read. Link scanners that follow every URL on delivery are classified as machine and excluded from the default result, and include_machine=True brings them back along with repeat hits collapsed by the thirty second window.
Only links in the new part of the body were rewritten, so nothing here can be a click on quoted history under a reply. The id rules match list_opens: a msg_ id that names no tracked message is a 404, while a tmsg_ id is used without a lookup and an unknown one returns an empty list.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.limitintHits per page, from 1 to 200, defaulting to 50.
cursorstrThe
nextCursorfrom the previous page, aclk_id. Anything else, or one from another message's log, is a 400invalid_cursor.include_machineboolDefaults to
False.Truealso returns hits withcountedset toFalse, scanner clicks and collapsed repeats alike.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
Page[TrackingClickResource], a dict with items, hasMore and nextCursor. Each item has object set to click, id, trackedMessageId, linkId, url, recipient, kind, counted, userAgent, client, device, os, country, region, city and createdAt.
Пример
from collections import Counter from openemail import openemail page = openemail.tracking.list_clicks('tmsg_8b2e4d71c09f3a65e1d7b402', limit=200)by_url = Counter(click['url'] for click in page['items']) print(by_url.most_common(), page['hasMore'])Примечания
Repeated destinations share one
linkIdon the report, so a page linked from a header image, a button and a footer is one link. Group bylinkIdto matchlinksontracking.get.A key with an address allowlist gets a 404 for a
msg_id sent from an address outside it, and atmsg_id is then looked up rather than taken as given.
Также доступно в
tracking.list_all_clicks()
Collect every click hit on one message into one list
def list_all_clicks( id: str, *, limit: int | None = None, cursor: str | None = None, include_machine: bool | None = None, api_key: str | None = None, timeout: float | None = None,) -> builtins.list[TrackingClickResource]Walks every page of one tracked message's click log and returns all of its hits in one list, newest first. It takes the same arguments as list_clicks, so by default only counted hits come back and include_machine=True adds the rest.
A message opened by a mailing list of thousands can hold a great many rows. Prefer iterate_clicks when you can stop early. limit= sets the page size of each request, not the total.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.limitintPage size per request, from 1 to 200, defaulting to 50 on the server.
cursorstrA
clk_id to start after, skipping every newer click.include_machineboolDefaults to
False.Truealso returns hits withcountedset toFalse.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
list[TrackingClickResource] holding every hit across all pages, newest first.
Пример
from openemail import openemail clicks = openemail.tracking.list_all_clicks('tmsg_8b2e4d71c09f3a65e1d7b402')people = {click['recipient'] for click in clicks if click['recipient']} print(len(people), 'people clicked')Примечания
A failure on any page raises, and the hits already fetched are discarded.
The same id rules as
list_clicksapply: amsg_id that names no tracked message is a 404, and an unknowntmsg_id collects an empty list.
Также доступно в
tracking.iterate_clicks()
Stream the click hits on one message one at a time
def iterate_clicks( id: str, *, limit: int | None = None, cursor: str | None = None, include_machine: bool | None = None, api_key: str | None = None, timeout: float | None = None,) -> Iterator[TrackingClickResource]Returns a generator over one tracked message's click log that yields hits one at a time, newest first, and fetches the next page only when the current one is drained. Nothing is requested until you consume it, and breaking out of the loop stops further requests.
The walk ends when hasMore is False. Hits recorded after the walk starts are newer than its cursor and are not yielded.
Параметры
idstrОбязательноA
tmsg_tracking id or themsg_send id the message went out as.limitintPage size per request, from 1 to 200, defaulting to 50 on the server.
cursorstrA
clk_id to start after, skipping every newer click.include_machineboolDefaults to
False.Truealso returns hits withcountedset toFalse.api_keystrReads with this key instead of the client's.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Возвращает
Iterator[TrackingClickResource], a generator that yields one hit per step.
Пример
from openemail import openemail for click in openemail.tracking.iterate_clicks('tmsg_8b2e4d71c09f3a65e1d7b402'): if '/unsubscribe' in click['url']: print(click['recipient'], click['createdAt']) breakПримечания
The generator is lazy, so an abandoned loop costs only the pages you consumed.