Skip to content
Frameworks

PHP website analytics with Reveata

2 min read · Updated · By the Reveata team

Short answerPaste the Reveata snippet once into the header file every PHP page includes. Two small PHP files can serve the script from your own domain, even on shared hosting, and checkout.php can copy the visitor id into the checkout's metadata.

Plenty of profitable sites are plain PHP: a header.php, a few pages, a checkout.php. Reveata fits that shape exactly, with no framework, no Composer package for tracking and no build step.

What you get

  • Every page tracked from one shared header.
  • First-party serving from two small PHP files that pass the visitor's address with your proxy secret.
  • Payments credited to visits, from the metadata your checkout script adds.
  • Your own billing posted to the Payments API with a website key.

How to install it

  1. Open the file that prints <head>, for example the header.php you include at the top of each page (PHP's include documentation (opens in a new tab)).
  2. Paste the snippet before </head> and upload the file.
  3. Pages that don't share the header need the snippet pasted in themselves.

For WordPress, use the plugin instead (WordPress analytics). For Laravel, see Laravel analytics.

Linking payments to visits

Add two hidden fields to the form with your buy button, filled from window.reveata.metadata() when the form is sent. In checkout.php, copy them into the Checkout Session's metadata with stripe/stripe-php, or read Reveata's cookies directly:

php
<?php
function reveata_id(string $cookie): ?string {
    $id = explode('.', $_COOKIE[$cookie] ?? '')[0];
    return preg_match('/^[a-z0-9]{8,64}$/', $id) ? $id : null;
}
$metadata = array_filter([
    'reveata_visitor_id' => $_POST['reveata_visitor_id'] ?? reveata_id('_dt_v'),
    'reveata_session_id' => $_POST['reveata_session_id'] ?? reveata_id('_dt_s'),
]);

Keep checkout.php free of output before header(), or the redirect to Stripe fails. More in Stripe Checkout attribution. If Reveata doesn't connect to your provider, send each payment to the Payments API.

Serving the script from your own domain

Hosting Option
Any PHP host, shared hosting included Proxy with plain PHP
You manage the web server NGINX or Caddy
No server changes at all The managed proxy, one DNS record

Frequently asked questions

Do I need Composer to use Reveata?

Not for tracking: it is a script tag. You only need a Stripe library if your own checkout script creates sessions.

Will a Content Security Policy block it?

If your site sends one, allow the Reveata script and endpoint, or use the proxy so 'self' covers both (Content Security Policy).

Why are my local visits not counted?

The script ignores localhost unless you add data-allow-localhost="true". Test the live site.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationStripe Checkout analytics and attributionAdd the Reveata visitor and session ids to the metadata of each Stripe Checkout Session your server creates. When Stripe reports the payment, Reveata reads the ids and credits the money to the exact visit that started the checkout.IntegrationWordPress analytics with the Reveata pluginThe Reveata WordPress plugin adds the tracking script to every page, leaves logged-in administrators out by default, and shows your last seven days in the wp-admin dashboard. You connect it with a website API key.IntegrationLaravel analytics with revenue attributionPaste the Reveata snippet into the Blade layout that renders your pages' head, optionally inside @production. Inertia navigation is tracked automatically, and you pass the visitor id as checkout metadata so each payment is credited to its visit.IntegrationAngular analytics with ReveataPaste the Reveata snippet before the closing head tag of src/index.html. ng build keeps it in the built page, server-side rendering included, and the Angular Router's History API navigation is counted automatically. HashLocationStrategy needs data-hash="true".IntegrationAstro analytics with revenue attributionPaste the Reveata snippet with is:inline into the Astro layout that renders the head of every page. Astro then leaves the tag as written, view transitions are tracked, and payment links or checkouts started from your pages are credited to the visit behind them.IntegrationDjango analytics with revenue attributionPaste the Reveata snippet before the closing head tag of the base template your Django templates extend. Every page is tracked, the Django admin is not, and two hidden form fields let your checkout view put the visitor id into the payment's metadata.