Document analytics time to sign

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Document analytics time to sign is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Track document funnel analytics — sent → opened → viewed → signed — via native dashboards (PandaDoc, Proposify, Qwilr, DocuSign Insights), DocuSign Connect webhooks → PostHog / Mixpanel / Amplitude, custom dashboards. Track view-time per section, drop-off, time-to-sign, conversion rate. Use when the

How to use this skill

Skill file

Document analytics — Time-to-sign / view / drop-off / conversion

This skill ships the metrics + observability layer on doc + e-sign flows. Use native dashboards for quick wins; pipe webhook events to product-analytics for deep funnels.

When to use

User says:

Companion skills:

Setup

# DocuSign Connect (webhook config in DocuSign Admin UI)
# https://developers.docusign.com/platform/webhooks/connect/

# PandaDoc webhooks (Settings → Webhooks)
# https://developers.pandadoc.com/reference/webhooks

# Proposify webhooks (Account → Integrations)
# Qwilr webhooks (Settings → Integrations)

# Product-analytics MCPs (all available)
# posthog-mcp, mixpanel-mcp, amplitude-mcp

# Standalone SDKs
pip install posthog mixpanel-python amplitude-analytics

# Custom dashboard
pip install dash plotly streamlit pandas
# or BI tools: Looker / Metabase / Cube

Common recipes

Recipe 1: Standard event taxonomy

EVENTS = {
    "doc_created":      "Doc generated in PandaDoc / DocuSign / etc.",
    "doc_sent":         "Sent to recipient",
    "doc_first_opened": "Recipient first opened",
    "doc_section_viewed": "Recipient viewed section (per-section heatmap)",
    "doc_section_time": "Section view duration",
    "doc_commented":    "Recipient added comment",
    "doc_question":     "Recipient asked clarifying question",
    "doc_signed":       "Signature event",
    "doc_completed":    "All signers done",
    "doc_declined":     "Recipient declined",
    "doc_expired":      "TTL passed without action",
}
PROPERTIES = ["envelope_id","doc_id","template_id","template_version",
              "deal_id","deal_value","counterparty","party_role","sender_email","recipient_email",
              "time_to_first_open_s","time_to_sign_s","sections_viewed_count","sections_total"]

Standardize across PandaDoc / DocuSign / Proposify to enable cross-platform funnel.

Recipe 2: DocuSign Connect — webhook config

In DocuSign Admin → Connect → Add Configuration:

# Receiver
@app.post("/webhooks/docusign")
async def docusign_connect(req: Request):
    body = await req.body()
    # Verify signature
    sig = req.headers.get("X-DocuSign-Signature-1")
    if not verify_hmac(body, sig, os.environ["DOCUSIGN_CONNECT_KEY"]):
        return Response(status_code=401)
    payload = await req.json()
    env_data = payload["data"]
    event_name = {
        "envelope-sent":"doc_sent",
        "envelope-delivered":"doc_first_opened",   # DocuSign "delivered" = recipient opened
        "envelope-completed":"doc_completed",
        "envelope-declined":"doc_declined",
        "envelope-voided":"doc_expired"
    }.get(payload["event"])
    if event_name:
        track(event_name, {
            "envelope_id": env_data["envelopeId"],
            "recipient_email": env_data["recipients"][0]["email"],
            "timestamp": env_data["statusChangedDateTime"],
        })
    return {"ok": True}

Recipe 3: PandaDoc — webhook config

curl -X POST https://api.pandadoc.com/public/v1/webhooks \
  -H "Authorization: API-Key $PANDADOC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "PostHog Funnel",
    "url": "https://your-app/webhooks/pandadoc",
    "shared_key": "shared_secret",
    "events": [
      "document_state_changed",
      "document_updated",
      "recipient_completed"
    ]
  }'

Verify X-Pandadoc-Signature HMAC on inbound.

Recipe 4: PostHog — capture event

from posthog import Posthog
posthog = Posthog(project_api_key=POSTHOG_KEY, host="https://us.i.posthog.com")
posthog.capture(
    distinct_id=recipient_email,
    event="doc_first_opened",
    properties={
        "envelope_id": "env_abc123",
        "deal_value": 240000,
        "template_id": "msa-v3.1",
        "party_role": "customer",
    },
    timestamp=event_ts
)

Recipe 5: Mixpanel — capture event

from mixpanel import Mixpanel
mp = Mixpanel(MIXPANEL_TOKEN)
mp.track(
    distinct_id=recipient_email,
    event_name="doc_signed",
    properties={
        "$insert_id": f"sign-{envelope_id}",   # idempotent
        "envelope_id": envelope_id,
        "time_to_sign_hours": elapsed_h,
    }
)

Recipe 6: Amplitude — capture event

from amplitude import Amplitude, BaseEvent
amp = Amplitude(AMPLITUDE_API_KEY)
amp.track(BaseEvent(
    event_type="doc_signed",
    user_id=recipient_email,
    event_properties={"envelope_id": envelope_id, "deal_value": 240000},
    time=int(event_ts * 1000)
))

Recipe 7: Compute time-to-sign

import pandas as pd
events = pd.read_csv("doc_events.csv")    # via Recipe 4-6 ingestion → BI
pivot = events.pivot_table(
    index="envelope_id",
    columns="event",
    values="timestamp",
    aggfunc="min"
)
pivot["time_to_first_open_h"] = (pivot["doc_first_opened"] - pivot["doc_sent"]).dt.total_seconds() / 3600
pivot["time_to_sign_h"] = (pivot["doc_signed"] - pivot["doc_sent"]).dt.total_seconds() / 3600
print(pivot[["time_to_first_open_h","time_to_sign_h"]].describe())

Recipe 8: Funnel chart — sent → opened → signed

import plotly.graph_objects as go
sent = len(events[events.event=="doc_sent"])
opened = len(events[events.event=="doc_first_opened"])
signed = len(events[events.event=="doc_signed"])
fig = go.Figure(go.Funnel(
    y=["Sent","Opened","Signed"],
    x=[sent, opened, signed],
    textinfo="value+percent initial"
))
fig.write_html("funnel.html")

Recipe 9: Per-section view-time heatmap (PandaDoc)

# PandaDoc webhook includes recipient activity with per-section time
@app.post("/webhooks/pandadoc")
async def pandadoc_webhook(req: Request):
    body = await req.json()
    if body["event"] == "recipient_completed":
        # Pull doc analytics from PandaDoc API
        analytics = requests.get(
            f"https://api.pandadoc.com/public/v1/documents/{body['data']['id']}/details",
            headers={"Authorization": f"API-Key {PANDADOC_KEY}"}
        ).json()
        # Section timings (if your template uses named sections)
        for section in analytics.get("sections", []):
            posthog.capture(
                distinct_id=body["data"]["recipient_email"],
                event="doc_section_time",
                properties={
                    "section_name": section["name"],
                    "time_spent_s": section["time_spent"],
                    "envelope_id": body["data"]["id"]
                }
            )

Recipe 10: Drop-off detection

# Drop-off = opened but not signed within X hours
import pandas as pd
threshold_h = 72
opened_only = pivot[(pivot["doc_first_opened"].notna()) & (pivot["doc_signed"].isna())]
opened_only["hours_since_open"] = (pd.Timestamp.utcnow() - opened_only["doc_first_opened"]).dt.total_seconds() / 3600
dropoffs = opened_only[opened_only["hours_since_open"] > threshold_h]
print(f"Drop-offs: {len(dropoffs)}")
# Auto-nudge via Slack
for env_id in dropoffs.index:
    slack_post(f"📉 Drop-off alert: {env_id} stuck >72h after open. Suggest follow-up.")

Recipe 11: A/B test template versions

# Random assign template at send time
import random
template_uuid = random.choice(["tmpl_v3.1_concise", "tmpl_v3.1_detailed"])
pdoc = create_pandadoc(template_uuid=template_uuid, ...)
posthog.capture(
    distinct_id=recipient_email,
    event="doc_template_assigned",
    properties={"envelope_id": env_id, "template_variant": template_uuid}
)
# Compare signed % per variant in PostHog funnel

Recipe 12: Cohort metrics — by deal size

events["deal_bucket"] = pd.cut(events.deal_value, bins=[0, 25000, 100000, 500000, float("inf")],
                                labels=["<25K","25-100K","100-500K","500K+"])
cohort = events.groupby(["deal_bucket","event"]).size().unstack(fill_value=0)
cohort["close_rate"] = cohort.get("doc_signed", 0) / cohort.get("doc_sent", 1)
print(cohort[["doc_sent","doc_signed","close_rate"]])

Recipe 13: Streamlit dashboard skeleton

import streamlit as st, pandas as pd
events = pd.read_parquet("events.parquet")
st.title("Document Analytics")
col1, col2, col3 = st.columns(3)
col1.metric("Sent (30d)", len(events[events.event=="doc_sent"]))
col2.metric("Signed (30d)", len(events[events.event=="doc_signed"]))
col3.metric("Median time-to-sign (h)", events.median_tts_h.median())
st.subheader("Funnel")
st.plotly_chart(make_funnel_chart(events))
st.subheader("Drop-offs (open > 72h, no sign)")
st.dataframe(get_dropoffs(events))

Examples

Example 1: AE dashboard — time-to-sign per rep

Goal: Show each AE their median time-to-sign + drop-off rate.

Steps:

  1. Recipe 2-6 — pipe events to PostHog with sender_email property.
  2. Recipe 7 — compute TTS per AE.
  3. Recipe 12 — cohort by AE.
  4. Recipe 13 — Streamlit dash.

Result: Reps see their own funnel; sales leader sees team's.

Example 2: Auto-nudge stalled deals

Goal: Reduce drop-offs by auto-nudging buyers stuck >48h after open.

Steps:

  1. Recipe 10 — drop-off detection cron.
  2. slack-mcp alerts AE.
  3. AE one-click sends nudge via PandaDoc resend.

Result: Close-rate uplift via faster nudges.

Example 3: A/B test "concise" vs "detailed" proposal

Goal: Find which template wins.

Steps:

  1. Recipe 11 — random template at send.
  2. Recipe 8 — funnel per variant.
  3. After 50 sends per arm, report.

Result: Data-driven template iteration.

Edge cases / gotchas

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.