{"id":35324630,"url":"https://github.com/91369673/reddit-pixel-shopify-server-side-tracking","last_synced_at":"2026-04-10T12:31:22.635Z","repository":{"id":325567733,"uuid":"1101675053","full_name":"91369673/reddit-pixel-shopify-server-side-tracking","owner":"91369673","description":"Server-side conversion tracking for Reddit Ads using Shopify webhooks and Reddit Conversions API","archived":false,"fork":false,"pushed_at":"2025-11-22T03:29:33.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-22T05:30:14.380Z","etag":null,"topics":["conversions-api","docker","ecommerce","nodejs","reddit","reddit-ads","reddit-pixel","server-side-tracking","shopify","webhooks"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/91369673.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-22T03:13:56.000Z","updated_at":"2025-11-22T03:29:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/91369673/reddit-pixel-shopify-server-side-tracking","commit_stats":null,"previous_names":["91369673/reddit-pixel-shopify-server-side-tracking"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/91369673/reddit-pixel-shopify-server-side-tracking","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/91369673%2Freddit-pixel-shopify-server-side-tracking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/91369673%2Freddit-pixel-shopify-server-side-tracking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/91369673%2Freddit-pixel-shopify-server-side-tracking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/91369673%2Freddit-pixel-shopify-server-side-tracking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/91369673","download_url":"https://codeload.github.com/91369673/reddit-pixel-shopify-server-side-tracking/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/91369673%2Freddit-pixel-shopify-server-side-tracking/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31642672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T07:40:12.752Z","status":"ssl_error","status_checked_at":"2026-04-10T07:40:11.664Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conversions-api","docker","ecommerce","nodejs","reddit","reddit-ads","reddit-pixel","server-side-tracking","shopify","webhooks"],"created_at":"2025-12-31T01:09:29.366Z","updated_at":"2026-04-10T12:31:22.620Z","avatar_url":"https://github.com/91369673.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reddit Pixel Shopify Server-Side Tracking\n\nServer-side conversion tracking for Reddit Ads using Shopify webhooks and Reddit Conversions API. This implementation bypasses browser-based tracking limitations (ad blockers, privacy settings, iOS restrictions) to capture conversions that client-side pixels miss.\n\n## Why Server-Side Tracking?\n\nReddit officially recommends using both Pixel and Conversions API together for optimal tracking accuracy. According to their documentation:\n\n\u003e \"CAPI is more resilient to signal loss because it operates server-side, making it less susceptible to ad blockers and browser restrictions.\"\n\nClient-side pixel tracking loses 30-50% of conversions due to:\n- Ad blockers\n- Browser privacy settings (Safari, Firefox)\n- iOS App Tracking Transparency\n- Third-party cookie blocking\n\nThis server-side implementation captures conversions that browser-based tracking misses by sending data directly from your server to Reddit's API.\n\n## Features\n\n- ✅ Production-ready Docker setup\n- ✅ HMAC webhook verification (Shopify security)\n- ✅ PII hashing (SHA-256 for privacy)\n- ✅ Event deduplication (PostgreSQL)\n- ✅ Automatic retry logic with exponential backoff\n- ✅ Rate limiting handling (429 responses)\n- ✅ Comprehensive logging (Winston)\n- ✅ Health check endpoint\n- ✅ SSL/HTTPS support (Nginx reverse proxy example)\n\n## Quick Start\n\n**Prerequisites:**\n- Linux server with Docker installed\n- Domain/subdomain pointing to your server\n- Reddit Ads account with Pixel created\n- Shopify store with admin access\n\n**Installation (5 minutes):**\n\n```bash\n# Clone repository\ngit clone https://github.com/91369673/reddit-pixel-shopify-server-side-tracking.git\ncd reddit-pixel-shopify-server-side-tracking\n\n# Copy environment template\ncp .env.example .env\n\n# Edit .env with your credentials\nnano .env\n\n# Start services\ndocker compose up -d\n\n# Check logs\ndocker compose logs -f reddit-capi\n```\n\n## Configuration\n\n### 1. Reddit Ads Manager\n\n1. Go to Reddit Ads Manager → Events Manager\n2. Create new Pixel\n3. Copy **Pixel ID** (format: `t2_abc123`)\n4. Go to Settings → Conversions API\n5. Generate **Access Token**\n6. Add to `.env`:\n\n```env\nREDDIT_PIXEL_ID=t2_your_pixel_id\nREDDIT_ACCESS_TOKEN=your_access_token_here\n```\n\n### 2. Shopify Webhooks\n\n1. Shopify Admin → Settings → Notifications → Webhooks\n2. Create webhook:\n   - **Event:** Order creation\n   - **Format:** JSON\n   - **URL:** `https://your-domain.com/webhooks/shopify`\n   - **API version:** Latest\n3. Copy **Signing Secret** → add to `.env`:\n\n```env\nSHOPIFY_WEBHOOK_SECRET=your_webhook_secret\n```\n\n4. Restart: `docker compose restart reddit-capi`\n\n### 3. Nginx Reverse Proxy (Optional but Recommended)\n\nCreate `/etc/nginx/sites-available/reddit-tracking.conf`:\n\n```nginx\nserver {\n    listen 443 ssl http2;\n    server_name your-domain.com;\n\n    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;\n\n    location / {\n        proxy_pass http://127.0.0.1:3000;\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto https;\n    }\n}\n```\n\nEnable and reload:\n```bash\nln -s /etc/nginx/sites-available/reddit-tracking.conf /etc/nginx/sites-enabled/\nnginx -t\nsystemctl reload nginx\n```\n\n## Architecture\n\n```\nShopify Store (order created)\n    |\n    v\nShopify Webhook (HTTPS POST)\n    |\n    v\nNginx Reverse Proxy (SSL termination)\n    |\n    v\nNode.js Application (Docker container)\n    |\n    v\n1. HMAC Verification\n2. Event Transformation\n3. PII Hashing (SHA-256)\n4. Deduplication Check\n5. Send to Reddit CAPI\n6. Log Result\n    |\n    v\nReddit Ads Platform\n```\n\n## Environment Variables\n\n| Variable | Required | Description | Example |\n|----------|----------|-------------|---------|\n| `SHOPIFY_WEBHOOK_SECRET` | Yes | Shopify webhook signing secret | `ba32d1d12da1ffc...` |\n| `REDDIT_PIXEL_ID` | Yes | Reddit Pixel ID from Events Manager | `t2_abc123` |\n| `REDDIT_ACCESS_TOKEN` | Yes | Reddit Conversions API access token | `eyJhbGciOiJSUzI1...` |\n| `DB_PASSWORD` | Yes | PostgreSQL database password | `strong_password` |\n| `PORT` | No | Application port (default: 3000) | `3000` |\n\n## Testing\n\n**Health check:**\n```bash\ncurl https://your-domain.com/health\n```\n\n**Expected response:**\n```json\n{\n  \"status\": \"healthy\",\n  \"timestamp\": \"2025-11-22T12:00:00.000Z\",\n  \"uptime\": 12345.67,\n  \"database\": \"connected\"\n}\n```\n\n**Send test webhook from Shopify:**\n1. Shopify Admin → Settings → Notifications → Webhooks\n2. Click on your webhook\n3. \"Send test notification\"\n4. Check logs: `docker compose logs -f reddit-capi`\n\n**Verify in Reddit:**\n1. Reddit Ads Manager → Events Manager\n2. Click your Pixel → \"Test Events\" tab\n3. Event should appear within a few minutes\n\n## Monitoring\n\n**View logs:**\n```bash\ndocker compose logs -f reddit-capi\n```\n\n**Check recent events:**\n```bash\ndocker compose exec postgres psql -U reddit_capi -d reddit_capi -c \\\n  \"SELECT event_id, event_type, status, created_at FROM events ORDER BY created_at DESC LIMIT 10;\"\n```\n\n**Failed events:**\n```bash\ndocker compose exec postgres psql -U reddit_capi -d reddit_capi -c \\\n  \"SELECT event_id, error_message FROM events WHERE status = 'failed';\"\n```\n\n## Troubleshooting\n\n### Events Not Appearing in Reddit\n\n**Check logs for API errors:**\n```bash\ndocker compose logs reddit-capi | grep \"Reddit API error\"\n```\n\n**Common errors:**\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| \"unexpected type number\" | Value sent as decimal | Verify multiplication by 100 in transformer |\n| \"unknown field event_id\" | Invalid field in payload | Remove `event_id` from Reddit event object |\n| 401 Unauthorized | Invalid access token | Regenerate token in Reddit Events Manager |\n| 429 Too Many Requests | Rate limiting | Handled automatically with retry logic |\n\n### HMAC Verification Failed\n\n```bash\n# Check if secret matches\ndocker compose exec reddit-capi printenv SHOPIFY_WEBHOOK_SECRET\n\n# Update .env and restart\ndocker compose restart reddit-capi\n```\n\n### Database Connection Issues\n\n```bash\n# Check PostgreSQL status\ndocker compose ps postgres\n\n# Test connection\ndocker compose exec postgres pg_isready -U reddit_capi\n```\n\n## Database Schema\n\n```sql\nCREATE TABLE events (\n  event_id VARCHAR(255) PRIMARY KEY,\n  event_type VARCHAR(50) NOT NULL,\n  shopify_id VARCHAR(255) NOT NULL,\n  shopify_payload JSONB,\n  reddit_payload JSONB,\n  reddit_response JSONB,\n  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  sent_at TIMESTAMP,\n  status VARCHAR(20) DEFAULT 'pending',\n  error_message TEXT\n);\n```\n\n## Security Features\n\n1. **HMAC Verification:** Every webhook validated with SHA-256 HMAC\n2. **HTTPS Only:** TLS 1.2/1.3 encryption\n3. **Localhost Binding:** Container only accessible via reverse proxy\n4. **PII Hashing:** Email/phone SHA-256 hashed before sending to Reddit\n5. **Environment Secrets:** All sensitive data in `.env` (git-ignored)\n\n## Advanced Configuration\n\n### Multi-Currency Support\n\nThe implementation automatically handles different currencies. For currencies with non-standard decimal places:\n\n```javascript\n// Zero-decimal currencies (JPY, KRW): multiply by 1\n// Standard currencies (USD, EUR): multiply by 100\n// Three-decimal currencies (BHD, KWD): multiply by 1000\n\nvalue: Math.round(parseFloat(order.total_price) * 100)\n```\n\n### Additional Event Types\n\nExtend `src/services/shopifyTransformer.js` for more events:\n\n```javascript\nexport function transformProductView(product) {\n  return {\n    event_at: new Date().toISOString(),\n    event_type: { tracking_type: 'ViewContent' },\n    // ... user data\n    event_metadata: {\n      conversion_id: `product_${product.id}_${Date.now()}`,\n      item_id: String(product.id),\n    },\n  };\n}\n```\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions welcome! Please:\n1. Fork the repository\n2. Create a feature branch\n3. Test your changes\n4. Submit a pull request\n\n## Support\n\n- **Issues:** [GitHub Issues](https://github.com/91369673/reddit-pixel-shopify-server-side-tracking/issues)\n- **Documentation:** [Full setup guide](https://www.tva.sg/reddit-pixel-tracking-for-shopify-server-side-implementation-with-conversions-api/)\n- **Reddit API Docs:** [Reddit Conversions API](https://reddithelp.com/hc/en-us/articles/4410892225940-Reddit-Conversions-API)\n\n## Acknowledgments\n\nBased on production implementation for live Shopify stores. Tested with:\n- Reddit Conversions API v2.0\n- Shopify API 2025-01\n- Docker Compose v2.x\n- PostgreSQL 16\n- Node.js 18\n\n---\n\n**⭐ If this helped you, consider starring the repo!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F91369673%2Freddit-pixel-shopify-server-side-tracking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F91369673%2Freddit-pixel-shopify-server-side-tracking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F91369673%2Freddit-pixel-shopify-server-side-tracking/lists"}