# Seline Analytics WordPress Plugin

## Installation

### Option 1: Upload Plugin Files
1. Download or copy the `seline-analytics` folder to your WordPress site
2. Upload the entire folder to `/wp-content/plugins/`
3. Go to your WordPress admin dashboard → Plugins
4. Find "Seline Analytics" in the list and click "Activate"

### Option 2: WordPress Admin Upload
1. Zip the `seline-analytics` folder
2. Go to WordPress admin → Plugins → Add New → Upload Plugin
3. Choose the zip file and click "Install Now"
4. Click "Activate Plugin"

## Setup

1. **Get Your Seline Token**
   - Sign up at [seline.com](https://seline.com) if you haven't already
   - Create a new project or use an existing one
   - Copy your tracking token

2. **Configure the Plugin**
   - Go to WordPress admin → Settings → Seline Analytics
   - Paste your token in the "Seline Token" field
   - Configure other settings as needed:
     - **Auto Page View**: Keep enabled for automatic page tracking
     - **Cookie Mode**: Enable for visitor identification across sessions
     - **Mask Patterns**: Hide sensitive URLs (e.g., `/user/*/profile` becomes `/user/*/profile`)
     - **Skip Patterns**: Don't track certain pages (e.g., `/admin/*`)

3. **Save Settings**
   - Click "Save Changes"
   - Your site will now start tracking automatically!

## Verification

To verify the plugin is working:

1. **Seline Dashboard**
   - Log into your Seline dashboard
   - Check if page views are being recorded

2. **Check Browser Console**
   - Open your site in a browser
   - Open Developer Tools (F12)
   - Look for any Seline-related messages in the console

3. **Check Network Tab**
   - In Developer Tools, go to Network tab
   - Navigate your site
   - Look for requests to your Seline API host (default: api.seline.com)



## Custom Event Tracking

### HTML Data Attributes
Add data attributes to any HTML element to track custom events:

```html
<!-- Button click tracking -->
<button data-sln-event="newsletter_signup">Subscribe</button>

<!-- Link tracking with additional data -->
<a href="/pricing"
   data-sln-event="pricing_click"
   data-sln-event-source="header"
   data-sln-event-plan="premium">
   View Pricing
</a>

<!-- Form tracking -->
<form data-sln-event="contact_form" data-sln-event-type="support">
  <!-- form fields -->
</form>
```

### JavaScript API
Use the global `window.seline` object for advanced tracking:

```javascript
// Track custom events
window.seline.track('video_play', {
  video_id: 'intro-video',
  duration: 120,
  quality: 'HD'
});

// Set user information
window.seline.setUser({
  userId: '12345',
  email: 'user@example.com',
  plan: 'premium'
});

// Manual page tracking (for SPAs)
window.seline.page('/custom/path');

// Enable/disable tracking
window.seline.doNotTrack();
window.seline.enableCookieMode();
```

### PHP Helper Functions
For theme and plugin developers:

```php
<?php
// Check if Seline is active
if (seline_analytics_is_active()) {
    // Track an event
    seline_analytics_track_event('form_submission', [
        'form_type' => 'contact',
        'user_id' => get_current_user_id()
    ]);
}

// Set user data when user logs in
add_action('wp_login', function($user_login, $user) {
    seline_analytics_set_user([
        'user_id' => $user->ID,
        'username' => $user_login,
        'user_role' => implode(',', $user->roles)
    ]);
}, 10, 2);

// Generate data attributes for buttons
$attributes = seline_analytics_data_attributes('purchase', [
    'product' => 'premium-plan',
    'price' => 29.99
]);
echo '<button ' . $attributes . '>Buy Now</button>';
?>
```

## Troubleshooting

### Plugin Not Tracking

1. **Check Token**: Ensure your Seline token is correctly entered
2. **Check Console**: Look for JavaScript errors in browser console
3. **Check Settings**: Verify "Auto Page View" is enabled
4. **Admin Exclusion**: By default, admin users aren't tracked

### Custom Events Not Working

1. **Check Data Attributes**: Ensure `data-sln-event` is present
2. **Element Type**: Some form elements need `type="submit"` to be tracked
3. **JavaScript Errors**: Check browser console for errors

### Performance Issues

1. **Use Minified Script**: Keep "Development Mode" disabled in settings
2. **Check Skip Patterns**: Add patterns for pages that don't need tracking
3. **Network Issues**: Verify connectivity to your Seline API host

## Advanced Configuration

### Custom API Host
If you're self-hosting Seline or using a custom domain:
1. Go to Settings → Seline Analytics
2. Update the "API Host" field
3. Save changes

### Privacy Compliance
For GDPR/privacy compliance:
- Disable "Cookie Mode" to avoid first-party cookies
- Use "Skip Patterns" to exclude sensitive pages
- The plugin respects "Do Not Track" browser settings

### Development Mode
Enable "Development Mode" in settings to:
- Use unminified JavaScript for debugging
- See detailed console logging
- Test configurations without affecting production analytics

## File Structure

```
seline-analytics/
├── seline-analytics.php     # Main plugin file
├── readme.txt              # WordPress plugin info
├── INSTALL.md              # This installation guide
├── assets/
│   ├── seline-tracker.js   # Readable tracking script
│   └── seline-tracker.min.js # Minified tracking script
└── includes/
    └── helpers.php         # PHP helper functions
```

## Support

For support with this WordPress plugin:
1. Check the troubleshooting section above
2. Review the plugin settings in WordPress admin
3. Contact Seline support at [seline.com](https://seline.com)

For Seline Analytics platform support:
- Visit the Seline documentation
- Contact Seline support team
- Check the Seline community forums
