# Install on OpenCart

> A folder next to index.php, loaded before OpenCart — no extension, on OpenCart 2, 3 and 4.

It is not an OpenCart extension: it is a folder PHP loads before the shop, on every request, through
`auto_prepend_file`. It works the same on OpenCart 2, 3 and 4 and survives theme and extension changes.

**Requirements:** PHP 8.1 or newer for the shop (on older PHP the file loads and does nothing); the PHP `curl`
extension or `allow_url_fopen`.

## Install

1. **Create a key** in Survelium → **Brand settings → Integrations → Create key**. It is shown once.
2. **Upload the folder.** Download `survelium-agent-analytics-opencart-x.y.z.zip` from
   [Releases](https://github.com/survelium/agent-analytics-opencart/releases) and extract it next to OpenCart's
   `index.php` (usually `public_html`), so you get `public_html/survelium/survelium.php`.
3. **Configure.** Copy `survelium/config.example.php` to `survelium/config.php` and paste the key into `api_key`.
   - Renamed the admin folder? Put its path in `deny_paths`, e.g. `['/my-admin']`.
   - Behind Cloudflare? Set `'ip_header' => 'HTTP_CF_CONNECTING_IP'`, or crawlers cannot be
     [verified](https://survelium.com/docs/ai-traffic/crawlers.md#verification).
4. **Load it before OpenCart**, with the absolute path to `survelium.php`. One of:
   - **`.user.ini`** next to `index.php` (PHP-FPM, most cPanel and LiteSpeed hosts; cPanel → MultiPHP INI Editor
     writes the same thing):

     ```ini
     auto_prepend_file = "/home/USER/public_html/survelium/survelium.php"
     ```

     PHP re-reads `.user.ini` every few minutes (300 seconds by default).
   - **`.htaccess`** (Apache with mod_php, LiteSpeed). OpenCart ships it as `.htaccess.txt`; if you never renamed
     it, create `.htaccess` with just this line:

     ```apache
     php_value auto_prepend_file "/home/USER/public_html/survelium/survelium.php"
     ```

     If the shop answers *500 Internal Server Error* right after, your host runs PHP-FPM: remove the line and use
     `.user.ini` instead.

   Not sure of the absolute path? It is the folder shown in your hosting file manager, or `pwd` over SSH.
5. **Check.** Open a few shop pages. Within about 15 minutes, **Brand settings → Integrations** shows the key as used.
   With SSH:

   ```bash
   php survelium/status.php          # what is buffered, last send, last error
   php survelium/status.php --send   # send now
   ```

The `survelium` folder ships an `.htaccess` that blocks web access to it (your key, the buffer). On nginx, point
`storage_path` outside the web root, or deny `/survelium/` in the server block.

## What it counts

Page views only (`GET`/`HEAD`, not the cart's AJAX calls or form posts), and nothing under `/admin`. Sending happens
after the page has gone out, in batches.

## Update

Extract the new zip over the old folder. `config.php` is not in the zip, so your settings stay.

## Uninstall

Remove the `auto_prepend_file` line **first**, then delete the `survelium` folder. The other way around, PHP fails on
every request until the line is gone.
