feat: integrate First8 Marketing hyper-personalization system

Enhanced Umami Analytics with First8 Marketing integration for
hyper-personalized recommendation engine.

Database Enhancements:
- PostgreSQL 17 with Apache AGE 1.6.0 (graph database)
- TimescaleDB 2.23.0 (time-series optimization)
- Extended schema for WooCommerce event tracking
- Custom tables for recommendation engine integration

Features Added:
- Real-time ETL pipeline to recommendation engine
- Extended event tracking (WordPress + WooCommerce)
- Graph database for relationship mapping
- Time-series optimization for analytics queries
- Custom migrations for hyper-personalization

Documentation:
- Updated README with integration details
- Added system architecture documentation
- Documented data flow and components
- Preserved original Umami Software credits

Integration Components:
- First8 Marketing Track plugin (event tracking)
- Recommendation Engine (ML backend)
- First8 Marketing Recommendation Engine plugin (presentation)

Status: Production-ready
Version: Based on Umami latest + First8 Marketing enhancements
This commit is contained in:
iskandarsulaili 2025-11-05 19:17:57 +08:00
parent a6d4519a98
commit 5f496fdb79
16 changed files with 8856 additions and 9790 deletions

View file

@ -0,0 +1,75 @@
# PostgreSQL 17 with Apache AGE 1.6.0 and TimescaleDB 2.23.0
# For Umami Analytics Upgrade - Hyper-Personalized Marketing System
FROM postgres:17-alpine
# Install build dependencies
RUN apk add --no-cache \
build-base \
clang \
llvm \
git \
cmake \
bison \
flex \
readline-dev \
zlib-dev \
curl \
ca-certificates
# Set PostgreSQL version for compatibility
ENV PG_MAJOR=17
ENV PG_VERSION=17
# Install TimescaleDB 2.23.0
ENV TIMESCALEDB_VERSION=2.23.0
RUN set -ex \
&& apk add --no-cache --virtual .fetch-deps \
ca-certificates \
openssl \
tar \
&& mkdir -p /tmp/timescaledb \
&& cd /tmp/timescaledb \
&& wget -O timescaledb.tar.gz "https://github.com/timescale/timescaledb/archive/${TIMESCALEDB_VERSION}.tar.gz" \
&& tar -xzf timescaledb.tar.gz -C /tmp/timescaledb --strip-components=1 \
&& cd /tmp/timescaledb \
&& ./bootstrap -DREGRESS_CHECKS=OFF -DPROJECT_INSTALL_METHOD="docker" \
&& cd build && make install \
&& cd / \
&& rm -rf /tmp/timescaledb \
&& apk del .fetch-deps
# Install Apache AGE 1.6.0
ENV AGE_VERSION=1.6.0
RUN set -ex \
&& mkdir -p /tmp/age \
&& cd /tmp/age \
&& wget -O age.tar.gz "https://github.com/apache/age/archive/refs/tags/v${AGE_VERSION}.tar.gz" \
&& tar -xzf age.tar.gz -C /tmp/age --strip-components=1 \
&& cd /tmp/age \
&& make PG_CONFIG=/usr/local/bin/pg_config install \
&& cd / \
&& rm -rf /tmp/age
# Clean up build dependencies
RUN apk del build-base clang llvm git cmake bison flex
# Configure PostgreSQL to load extensions
RUN echo "shared_preload_libraries = 'timescaledb,age'" >> /usr/local/share/postgresql/postgresql.conf.sample
# Add initialization script
COPY init-scripts/* /docker-entrypoint-initdb.d/
# Set proper permissions
RUN chmod +x /docker-entrypoint-initdb.d/*.sh || true
# Expose PostgreSQL port
EXPOSE 5432
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD pg_isready -U postgres || exit 1
# Use the default PostgreSQL entrypoint
CMD ["postgres"]

140
docker/postgres/README.md Normal file
View file

@ -0,0 +1,140 @@
# PostgreSQL 17 + Apache AGE + TimescaleDB Docker Image
This directory contains the Dockerfile and initialization scripts for building a custom PostgreSQL 17 image with Apache AGE 1.6.0 and TimescaleDB 2.23.0 extensions.
## What's Included
- **PostgreSQL 17** - Latest PostgreSQL version
- **Apache AGE 1.6.0** - Graph database extension for user journey tracking
- **TimescaleDB 2.23.0** - Time-series database extension for analytics
## Building the Image
```bash
# From the umami directory
docker build -t postgres:17-age-timescaledb -f docker/postgres/Dockerfile docker/postgres
```
## Using with Docker Compose
The image is automatically built when using `docker-compose.upgraded.yml`:
```bash
# Start the upgraded stack
docker-compose -f docker-compose.upgraded.yml up -d
# View logs
docker-compose -f docker-compose.upgraded.yml logs -f
# Stop the stack
docker-compose -f docker-compose.upgraded.yml down
```
## Running Migrations
After the database is up, run the Prisma migrations:
```bash
# Generate Prisma client
pnpm prisma generate
# Run migrations
pnpm prisma migrate deploy
```
## Verifying Extensions
Connect to the database and verify extensions are installed:
```bash
# Connect to PostgreSQL
docker-compose -f docker-compose.upgraded.yml exec db psql -U umami -d umami
# Check installed extensions
SELECT extname, extversion FROM pg_extension WHERE extname IN ('timescaledb', 'age');
# Check Apache AGE graph
SELECT * FROM ag_catalog.ag_graph;
# Check TimescaleDB hypertables
SELECT * FROM timescaledb_information.hypertables;
```
## Configuration
The PostgreSQL instance is configured with optimized settings for performance:
- `shared_buffers = 256MB`
- `effective_cache_size = 1GB`
- `maintenance_work_mem = 128MB`
- `max_connections = 200`
Adjust these in `docker-compose.upgraded.yml` based on your server resources.
## Initialization Scripts
Scripts in `init-scripts/` run automatically when the container is first created:
- `01-init-extensions.sh` - Installs TimescaleDB and Apache AGE extensions
## Troubleshooting
### Extensions not loading
If extensions fail to load, check the logs:
```bash
docker-compose -f docker-compose.upgraded.yml logs db
```
### Build failures
If the build fails, ensure you have enough disk space and memory:
```bash
# Check Docker resources
docker system df
# Clean up if needed
docker system prune -a
```
### Connection issues
Verify the database is healthy:
```bash
docker-compose -f docker-compose.upgraded.yml ps
docker-compose -f docker-compose.upgraded.yml exec db pg_isready -U umami
```
## Production Deployment
For production, use a managed PostgreSQL service or dedicated server instead of Docker. See the main [DEPLOYMENT.md](../../recommendation-engine/docs/DEPLOYMENT.md) for details.
## Data Persistence
Database data is stored in the `umami-db-data` Docker volume. To backup:
```bash
# Backup
docker-compose -f docker-compose.upgraded.yml exec db pg_dump -U umami umami > backup.sql
# Restore
docker-compose -f docker-compose.upgraded.yml exec -T db psql -U umami umami < backup.sql
```
## Security Notes
- Change default passwords in production
- Use environment variables for sensitive data
- Enable SSL/TLS for database connections
- Restrict network access to the database port
## Support
For issues or questions, refer to:
- [PostgreSQL Documentation](https://www.postgresql.org/docs/17/)
- [Apache AGE Documentation](https://age.apache.org/docs/)
- [TimescaleDB Documentation](https://docs.timescale.com/)

View file

@ -0,0 +1,41 @@
#!/bin/bash
# Initialize PostgreSQL extensions for Umami
# This script runs automatically when the container is first created
set -e
echo "=================================================="
echo "Initializing PostgreSQL 17 with Extensions"
echo "=================================================="
# Wait for PostgreSQL to be ready
until pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"; do
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done
echo "PostgreSQL is ready. Installing extensions..."
# Connect to the database and install extensions
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
-- Install TimescaleDB extension
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
-- Install Apache AGE extension
CREATE EXTENSION IF NOT EXISTS age CASCADE;
-- Load AGE into search path
SET search_path = ag_catalog, "\$user", public;
-- Verify installations
SELECT extname, extversion FROM pg_extension WHERE extname IN ('timescaledb', 'age');
EOSQL
echo "=================================================="
echo "Extensions installed successfully!"
echo "- TimescaleDB: Installed"
echo "- Apache AGE: Installed"
echo "=================================================="
echo "Database is ready for Umami migrations."