# Comparison contract for one purchase reconciliation.
# Fill every field before running a query. Save it beside the results so
# another person can reproduce the expected population and totals.
# Propose it for martech-context/ and write it there only after approval.

contract_version: 1
prepared_by: ""            # role, not a personal email
prepared_on: ""            # YYYY-MM-DD

analytics:
  tool: "GA4"
  property_id: ""                      # numeric property ID: the export dataset is analytics_<property_id>, API calls use properties/<property_id>
  measurement_ids: ["G-XXXXXXXXXX"]    # web stream measurement IDs; placeholders in shared files
  streams: []                          # stream IDs in scope, mapped to store_id
  export_dataset: "YOUR_PROJECT.analytics_PROPERTY_ID"
  export_location: ""                  # the order side must sit in the same location to join in BigQuery
  reporting_time_zone: ""              # from the property, not assumed
  reporting_currency: ""
  consent_mode: ""                     # basic, advanced or none, from decisions.md
  purchase_senders: []                 # every sender found: platform app, theme code, GTM tag, custom pixel, server container, Measurement Protocol
  sender_architecture: ""              # browser only, server confirmed or mixed; named beside the verdict

orders:
  system: ""                           # order database, Shopify, Stripe, WooCommerce, billing platform
  table_or_export: ""
  extracted_at: ""                     # timestamp of the extract
  latest_timestamp_present: ""
  classification_runs_in: ""           # bigquery_saved_table, bigquery_inline_literal or order_warehouse

business_outcome: ""                   # one sentence, for example "one purchase per paid online order, counted when payment is confirmed"
business_timestamp: "paid_at"          # paid_at or placed_at
paid_definition: "captured"            # captured or authorized. Use authorized when the business counts revenue at a successful
                                       # authorization (manual capture at fulfilment); business_ts is then the authorization time.
                                       # Under captured, authorized orders not yet captured are excluded as authorized_not_captured.
comparison_time_zone: ""               # one clock for both sides, usually the property's

period:
  start: ""                            # YYYY-MM-DD, complete days only
  end: ""
  scan_window_start: ""                # period start minus 1 day; earlier when eligible orders were placed earlier and may send purchase at placement
  scan_window_end: ""                  # period end plus 3 days
  frozen_on: ""                        # run date: the last scan-window day ended at least 3 days before, so scan_window_end plus 4 days or later
                                       # (with the default window, 6 days after the period ended: period ending 2026-09-13 runs on 2026-09-20)

eligible_population:
  channels_included: ["web"]
  statuses_included: ["paid"]
  test_order_rule: ""                  # the field and value that marks test orders
  cancelled_rule: ""                   # cancelled before payment excluded; cancelled after payment kept and handled as a refund
  stores: []
  exclusion_reasons: ["test_order", "other_channel", "cancelled_before_payment", "authorized_not_captured", "unpaid", "missing_amounts", "outside_period"]

join_key:
  analytics_field: "transaction_id"
  order_field: ""                      # proved on ten orders in step 3
  alternate_order_field: ""            # provisional or display number, or empty
  normalisation_rule: "TRIM and UPPER only"
  proof_orders: []                     # ten order keys traced to their raw transaction_id

value_rule:
  analytics_field: "value parameter"
  order_definition: "items x quantity after discounts, without tax and shipping"
  tax_inclusive_prices: ""             # yes or no; if yes, say whether included tax is removed
  gift_cards: ""                       # redemption is a tender and does not lower expected_value; say whether gift cards sold count as items
  currency_rule: "compare per currency, never sum across currencies"
  tolerance: "one minor unit per item line"

refund_rule: "refunds are compared separately; purchase value is compared gross of later refunds"

server_sending:                        # fill only when purchase is or will be sent from the server
  orders_without_client_id: ""         # send_generated_marked (new user per order, data_source=server_no_client) or do_not_send
  paid_after_24_hours: ""              # send_without_session or report_from_warehouse

thresholds:
  source: "skill defaults"             # or "metrics.md, approved on YYYY-MM-DD"
  unexplained_gap_pass_max: 0.02
  unexplained_gap_investigate_max: 0.05
  duplicate_flag_rate_max: 0.005
  value_flag_rate_max: 0.01
  late_flag_rate_investigate: 0.02
  control_segment: "in-page checkout flow with at least 100 eligible orders and the lowest miss rate"
  control_min_orders: 100
  suspect_segment_min_orders: 20
  suspect_segment_min_ratio_to_control: 2.0
  suspect_segment_min_excess_points: 0.05
  server_recoverable_share_min: 0.02
  minimum_eligible_orders: 200

consent_evidence: ""                   # source and period of the consent rates or per-order consent states, or "none"
blocker_evidence: ""                   # first-party log join, client_id capture rate, or "not measured"
known_changes_in_period: []            # releases to tags, checkout, payment methods or CMP, with dates
