HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: //var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/Events/PageViewEvent.php
<?php

namespace GoDaddy\WordPress\MWC\Core\Events;

use GoDaddy\WordPress\MWC\Common\Content\Context\Screen;
use GoDaddy\WordPress\MWC\Common\Events\Contracts\EventBridgeEventContract;
use GoDaddy\WordPress\MWC\Common\Helpers\StringHelper;
use GoDaddy\WordPress\MWC\Common\Traits\IsEventBridgeEventTrait;

/**
 * Page view event class.
 */
class PageViewEvent implements EventBridgeEventContract
{
    use IsEventBridgeEventTrait;

    /** @var Screen the WordPress screen object */
    protected $screen;

    /**
     * Page view event constructor.
     *
     * @param Screen $screen
     */
    public function __construct(Screen $screen)
    {
        $this->resource = 'page';
        $this->action = 'view';
        $this->screen = $screen;
    }

    /**
     * Gets the data for the event.
     *
     * @return array
     */
    protected function buildInitialData() : array
    {
        $data = $this->screen->toArray();
        $data['utm_params'] = [];

        foreach ($this->getUtmParameters() as $parameter => $value) {
            $data['utm_params'][StringHelper::replaceFirst($parameter, 'utm_', '')] = $value;
        }

        return $data;
    }

    /**
     * Gets the page's UTM URL query string parameters.
     *
     * @return array
     */
    protected function getUtmParameters() : array
    {
        return array_filter($_GET, static function ($parameter) {
            return StringHelper::startsWith($parameter, 'utm_');
        }, ARRAY_FILTER_USE_KEY);
    }
}