- What Laravel versions does devhelp/piwik-api support?
- The package is designed for Laravel 5.x and likely works with newer versions, but no explicit Laravel 10+ support is documented. Test compatibility by checking the package’s Guzzle HTTP client version and Laravel’s dependency constraints in `composer.json`. If issues arise, consider wrapping the API calls with Laravel’s HTTP client for better version alignment.
- How do I securely store the Piwik API token in Laravel?
- Use Laravel’s `.env` file to store the `PIWIK_TOKEN` and bind it to the package’s configuration. For enhanced security, leverage Laravel Vault or environment variables with encrypted values. Avoid hardcoding tokens in configuration files or source code.
- Can I use this package with Matomo (Piwik’s successor) v4+?
- The package should work with Matomo, but compatibility isn’t guaranteed due to lack of recent updates. Verify the API endpoints (e.g., `Actions.getPageUrl`) match Matomo’s v4+ documentation. If issues arise, consider forking the package or using Matomo’s official PHP SDK as a fallback.
- How do I mock Piwik API responses in PHPUnit tests?
- Use Laravel’s HTTP testing helpers or libraries like VCR or Mockery to stub the Piwik API responses. For example, mock the `PiwikGuzzleClient` to return predefined JSON responses. Alternatively, create a test double that implements the same interface as the Piwik client.
- Does this package support custom Piwik segments or complex queries?
- The package supports runtime arguments and lazy-loaded parameters, including segments, but complex queries may require manual overrides. For advanced use cases, extend the `Param` interface or pass custom arrays to method calls. Check the [Piwik API documentation](http://developer.piwik.org/api-reference/reporting-api-segmentation) for segment syntax.
- How do I handle API rate limits or timeouts in production?
- The package lacks built-in retry logic, so integrate Laravel’s HTTP client for retries and timeouts. Configure Guzzle’s retry middleware or use Laravel’s `Http::timeout()` and `Http::retry()` methods. Cache frequent API responses with Laravel’s cache system to reduce load.
- What’s the best way to integrate this into a Laravel service container?
- Register the Piwik client as a singleton in `AppServiceProvider` using Laravel’s dependency injection. Bind the `PiwikApi` class to the container with your `.env` configuration, then inject it into services or facades. Example: `$this->app->singleton(PiwikApi::class, fn($app) => new PiwikApi(config('piwik.token')));`.
- Are there alternatives to this package for Laravel?
- Consider Matomo’s official PHP SDK for active maintenance and full feature support. For lightweight needs, use Laravel’s HTTP client directly with Guzzle or Symfony’s HTTP client. If you need a facade-like interface, wrap the official SDK in a Laravel-specific package.
- How do I lazy-load dynamic parameters like `token_auth`?
- Implement the `Param` interface or use callbacks for dynamic values. For example, pass a closure to resolve `token_auth` at runtime, such as fetching it from the current user’s session. The package resolves these values when `call()` is invoked, enabling flexible parameter handling.
- Can I use this package for real-time analytics tracking?
- The package is optimized for querying historical data (e.g., visits, events) rather than real-time tracking. For real-time needs, use Piwik’s JavaScript tracker or Matomo’s official API directly. Cache frequent queries to reduce latency in your Laravel application.