File size: 7,835 Bytes
9672b2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Pay-Per-Event Apify Actor Starter Kit · Siftwright</title><meta name="description" content="A small, working Node.js template for a paid Apify Actor that charges users only for successful results. Schemas, charge-on-success loop, tests, publish checklist. $9 one-time, MIT."><style>:root{--bg:#F2F3F8;--card:#fff;--ink:#161934;--muted:#595E7E;--line:#DDE0EA;--navy:#2A2F6B;--gold:#F2C14E}
@media (prefers-color-scheme:dark){:root{--bg:#0D0F1F;--card:#15182D;--ink:#E9EAF5;--muted:#A3A8C6;--line:#272B4A;--navy:#AEB5FF}}
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:17px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}
main{max-width:920px;margin:0 auto;padding:32px 16px 56px}
.hero{background:radial-gradient(120% 140% at 100% 0%,#2A2F6B 0%,#1D2150 60%);color:#F4F4FB;border-radius:18px;padding:28px 24px}
.hero h1{font-size:clamp(26px,5vw,38px);line-height:1.12;margin:0 0 10px;letter-spacing:-.02em}.hero p{margin:0 0 18px;color:#B9BDE0;max-width:60ch}
.price{display:inline-block;background:rgba(255,255,255,.1);border-radius:999px;padding:4px 12px;font-size:15px;margin-bottom:16px}
.cta{display:inline-block;margin-right:10px;background:var(--gold);color:#1D2150;font-weight:700;text-decoration:none;padding:12px 20px;border-radius:999px}
.cta2{display:inline-block;color:#F4F4FB;border:1.5px solid rgba(255,255,255,.4);font-weight:600;text-decoration:none;padding:11px 18px;border-radius:999px;margin-top:8px}.by{display:block;margin-top:14px;font-size:14px;color:#B9BDE0}
h2{font-size:22px;margin:36px 0 12px}ul.f{padding-left:20px;margin:0}ul.f li{margin:6px 0}
figure{margin:0 0 18px;background:var(--card);border:1px solid var(--line);border-radius:14px;overflow:hidden}
figure img{display:block;width:100%;height:auto}figcaption{padding:10px 14px;font-size:15px;color:var(--muted)}
table{width:100%;border-collapse:collapse;background:var(--card);border:1px solid var(--line);border-radius:14px;overflow:hidden;font-size:15px}
td,th{padding:10px 12px;border-bottom:1px solid var(--line);text-align:left}tr:last-child td{border-bottom:0}
a{color:var(--navy)}footer{margin-top:40px;font-size:14px;color:var(--muted)}@media (max-width:640px){table{display:block;overflow-x:auto;max-width:100%}}</style></head><body><main>
<section class="hero"><h1>Pay-Per-Event Apify Actor Starter Kit</h1><p>A small, working Node.js template for a paid Apify Actor that charges users only for results they actually got. Copy it, swap in your own logic, set one event price, publish.</p><span class="price">$9 one-time · MIT licence · instant download (zip, about 9 KB)</span><br>
<a class="cta" href="https://buy.polar.sh/polar_cl_XmolAL821NucKjcWuwyYzutqK9a61YqXO9H6s0vySxc" target="_blank" rel="noopener">Buy for $9 →</a><a class="cta2" href="https://apify.com/siftwright" target="_blank" rel="noopener">See Actors built on this pattern</a><span class="by">By Siftwright · checkout by Polar · the same charging pattern runs in our 9 live Apify Store Actors</span></section>
<h2>What it is</h2><p>The example Actor takes a list of URLs and returns each page's title and meta description. Every page that loads is one charged <code>result</code> event. Invalid URLs, timeouts and HTTP errors are still written to the dataset so the user can see what went wrong, but they are <b>not charged</b>. Replace the fetch and the parser with your own work and keep the rule: charge after success, never before.</p>
<h2>What's inside</h2><pre style="background:var(--card);border:1px solid var(--line);border-radius:14px;padding:14px;overflow-x:auto;font-size:14px"><code>.actor/
  actor.json            metadata; links input, dataset and output schemas
  input_schema.json     Console input form (urls, maxResults, timeoutSecs)
  dataset_schema.json   table view for the results
  output_schema.json    Output tab; Apify requires it before you can publish
src/
  main.js               run loop with charge-on-success logic
  extract.js            pure parsing helpers (swap in your own)
test/
  extract.test.js       unit tests (node --test)
Dockerfile              apify/actor-node:22 base image
package.json            apify ^3.7.2, Node 20+
LICENSE                 MIT
README.md               setup, pricing steps and a publish checklist</code></pre>
<h2>The charging pattern</h2><p><code>Actor.pushData(item, eventName)</code> stores the row and charges the event in one call, so a row is never charged without being saved. <code>maxResults</code> caps charged rows, and the loop stops when the user's own max-cost-per-run is reached.</p>
<pre style="background:var(--card);border:1px solid var(--line);border-radius:14px;padding:14px;overflow-x:auto;font-size:14px"><code>const CHARGE_EVENT = 'result';

// success: save the row AND charge one event
const r = await Actor.pushData(item, CHARGE_EVENT);
if (r?.eventChargeLimitReached) break; // user's max cost per run reached

// failure: save the row, no charge
await Actor.pushData({ ...base, status: 'failed', error });</code></pre>
<h2>Real output</h2><p>A local run of the unmodified template (Node 22, apify 3.7.2) on 16 November 2026 with 4 inputs. The 2 pages that loaded are the rows that would be charged on the Apify platform; the 404 and the invalid URL are saved but free. Nothing is billed in a local run. The 3 bundled unit tests pass.</p>
<pre style="background:var(--card);border:1px solid var(--line);border-radius:14px;padding:14px;overflow-x:auto;font-size:14px"><code>$ node src/main.js
INFO  Done. 2 successful (charged) result(s) out of 4 URL(s).</code></pre>
<table><tr><th>url</th><th>status</th><th>httpStatus</th><th>title</th><th>error</th></tr>
<tr><td>https://example.com</td><td>ok</td><td>200</td><td>Example Domain</td><td>–</td></tr>
<tr><td>https://www.iana.org/help/example-domains</td><td>ok</td><td>200</td><td>Example Domains</td><td>–</td></tr>
<tr><td>https://example.com/this-page-does-not-exist-404</td><td>failed</td><td>404</td><td>–</td><td>HTTP 404</td></tr>
<tr><td>not-a-url</td><td>failed</td><td>–</td><td>–</td><td>Invalid URL</td></tr></table>
<h2>From zip to Store listing</h2><ol class="f"><li>Unzip, <code>npm install</code>, <code>npm test</code>, then <code>apify run -i '{"urls":["https://example.com"]}'</code> (needs the free <code>apify-cli</code>).</li><li><code>apify push</code> to build it on Apify.</li><li>Console → your Actor → Publication → Monetization → <b>Pay per event</b>: add an event named exactly <code>result</code> and set its price.</li><li>Rename it, rewrite the README for your users, run the included checklist, publish.</li></ol>
<h2>Good to know</h2><table><tr><th>Price</th><td>$9 one-time, paid through Polar; no subscription</td></tr><tr><th>Licence</th><td>MIT: personal or commercial Actors, attribution appreciated but not required</td></tr><tr><th>Needs</th><td>Node 20+, a free Apify account; the kit ships as JavaScript (no TypeScript, no browser crawler)</td></tr><tr><th>Not included</th><td>Support for your own scraping logic, proxies or Store marketing; it is a template, not a service</td></tr></table>
<p>Why pay-per-result pricing: <a href="https://siftwright.com/blog/pay-per-result-vs-subscription-api-pricing/" target="_blank" rel="noopener">pay-per-result vs subscription API pricing</a> on the Siftwright blog.</p>
<p><a class="cta" style="margin-top:12px" href="https://buy.polar.sh/polar_cl_XmolAL821NucKjcWuwyYzutqK9a61YqXO9H6s0vySxc" target="_blank" rel="noopener">Buy the starter kit for $9 →</a></p>
<footer>Made by Siftwright · <a href="https://siftwright.com/" target="_blank" rel="noopener">siftwright.com</a> · support@siftwright.com</footer>
</main></body></html>