Skip to content

Instantly share code, notes, and snippets.

@joelhooks
Created November 18, 2022 18:24
Show Gist options
  • Save joelhooks/94b3b25b062868a79b07bb42a0fd8e33 to your computer and use it in GitHub Desktop.
Save joelhooks/94b3b25b062868a79b07bb42a0fd8e33 to your computer and use it in GitHub Desktop.

Revisions

  1. joelhooks created this gist Nov 18, 2022.
    38 changes: 38 additions & 0 deletions convertkit-stats.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    // Name: ck stats for site
    // Snippet: ;ck

    import "@johnlindquist/kit"

    const sites = [
    {
    name: "Some Account",
    ck_secret: await env("SOME_ACCOUNT_CK_SECRET"),
    }
    ]

    // load subscriber count from convertkit api
    async function loadSubscriberCount(apiSecret: string): Promise<number> {
    const url = `https://api.convertkit.com/v3/subscribers?api_secret=${apiSecret}`;

    const response = await fetch(url).then(response => {
    return response.json();
    })
    return response.total_subscribers;
    }

    let report = `* [[active partner products]]\n\n`

    for (let index = 0; index < sites.length; index++) {
    const site = sites[index];
    const siteSubscriberCount = await loadSubscriberCount(site.ck_secret);
    report += ` * [[${site.name}]]\n
    * convertkit subscribers:: ${siteSubscriberCount}\n\n`;
    }

    copy(report);

    // let html = await highlight(report)
    // await div(html)

    await setSelectedText(report)