Markdown Converter
Agent skill for markdown-converter
The Snowplow PHP Tracker is a library for sending analytics events to Snowplow collectors. It provides a robust event tracking system with multiple emitter strategies, configurable payloads, and comprehensive event types. The tracker follows an object-oriented architecture with clear separation betw
Sign in to like and favorite skills
The Snowplow PHP Tracker is a library for sending analytics events to Snowplow collectors. It provides a robust event tracking system with multiple emitter strategies, configurable payloads, and comprehensive event types. The tracker follows an object-oriented architecture with clear separation between event construction, payload management, and event transmission.
# Install dependencies docker-compose run --rm snowplow composer.phar install # Run test suite docker-compose run --rm snowplow script/tests.sh # Run specific PHPUnit tests php vendor/bin/phpunit # Run tests with coverage php vendor/bin/phpunit --coverage-clover=build/logs/clover.xml
The tracker uses a layered architecture with three core components:
Tracker: Event tracking orchestration and APIPayload: Event data structure and encodingSubject: User context and session informationEmitter: Base class for event transmission strategiesConstants: Configuration constants and defaults// ✅ Each class has single responsibility $subject = new Subject(); $emitter = new SyncEmitter($uri); $tracker = new Tracker($emitter, $subject);
// ✅ Different emitter strategies new SyncEmitter($uri); // Synchronous sending new CurlEmitter($uri); // Async with curl new SocketEmitter($uri); // Socket-based
// ✅ Events built through Payload objects $payload = new Payload($timestamp); $payload->add("e", "pv");
src/)Tracker.php, Subject.php, Payload.php, Emitter.phpConstants.php - Central configurationsrc/Emitters/)RetryRequestManager.phptests/)ClassInitTests/ - Class initialization testsEmitterTests/ - Emitter-specific testsIntegrationTest.php - End-to-end testing// ✅ Correct namespace usage namespace Snowplow\Tracker; use Snowplow\Tracker\Emitters\CurlEmitter;
// ✅ External dependencies first use Ramsey\Uuid\Uuid; use ErrorException; // Then internal dependencies use Snowplow\Tracker\Emitter;
// ✅ Track page view $tracker->trackPageView($page_url, $page_title); // ✅ Track structured event $tracker->trackStructEvent($category, $action, $label);
// ✅ Configure emitter with buffer $emitter = new CurlEmitter( $uri, "https", // protocol "POST", // type 50 // buffer_size );
// ✅ Set user context $subject = new Subject(); $subject->setUserId("user123"); $subject->setPlatform("web");
// ✅ Payload with base64 encoding $payload->addJson($data, true, "ue_px", "ue_pr"); // ✅ Add standard fields $payload->add("e", "pv"); // Event type $payload->add("url", $url); // Page URL
// ✅ Structured event fields array( "e" => "se", // Event type "se_ca" => $cat, // Category "se_ac" => $action // Action )
// ❌ Not flushing buffer $tracker->trackPageView($url); // ✅ Force flush when needed $tracker->flushEmitters();
// ❌ Wrong timestamp format $tracker->trackPageView($url, null, null, time()); // ✅ Use milliseconds $tracker->trackPageView($url, null, null, time() * 1000);
// ❌ Raw context array $context = ["user" => "123"]; // ✅ Properly structured context $context = [ ["schema" => "iglu:...", "data" => ["user" => "123"]] ];
// ❌ Single emitter as array element $tracker = new Tracker([$emitter], $subject); // ✅ Single emitter or array $tracker = new Tracker($emitter, $subject); // Or multiple: new Tracker([$e1, $e2], $subject);
snowplow-php-tracker/ ├── src/ │ ├── Constants.php # Configuration constants │ ├── Tracker.php # Main tracker class │ ├── Subject.php # User context │ ├── Payload.php # Event payload │ ├── Emitter.php # Base emitter │ └── Emitters/ │ ├── CurlEmitter.php │ ├── SyncEmitter.php │ ├── SocketEmitter.php │ └── FileEmitter.php ├── tests/ │ ├── bootstrap.php │ ├── ClassInitTests/ │ ├── EmitterTests/ │ └── IntegrationTest.php ├── composer.json ├── phpunit.xml └── docker-compose.yml
trackPageView()trackStructEvent()trackUnstructEvent()trackScreenView()trackEcommerceTransaction()e: Event type (required)tv: Tracker version (auto-added)tna: Namespace (optional)aid: App ID (optional)dtm: Device timestamp (auto-added)// ✅ Test with mock collector $emitter = new SyncEmitter("localhost", "http", "POST", 1, true); $tracker = new Tracker($emitter, new Subject());
When adding or updating content in this document, please follow these guidelines:
wc -c CLAUDE.md// ❌ and // ✅ to clearly show wrong vs right approachesWhen editing files in this repository, always check for CLAUDE.md guidance: