javascript - How to access _ga parameter in PHP

one text

I have a form on my website that have some hotels. When someone choose hotel and hit reserve, the link is being created from the server and then it redirect that person to subdomain for next actions. I need to add _ga parameter to the end of that link, but I don't know how to do it. My function is being written in PHP and to generate _ga parameter I have to use google analytics code written in JS

This is function for decorating URL and getting _ga parameter to the end of the link

function decorateUrl(urlString) {
  var ga = window[window['GoogleAnalyticsObject']];
  var tracker;
  if (ga && typeof ga.getAll === 'function') {
    tracker = ga.getAll()[0]; // Uses the first tracker created on the page
    urlString = (new window.gaplugins.Linker(tracker)).decorate(urlString);
  }
  return urlString;
}

And this is part of my code that is generating URL when someone will click on the reserve button

public function getLink()
    {
        $tab = $this->booking->getTab();
        if (!$tab) {
            return null;
        }
        $link = $this->booking->custom_link ?? $tab->link;

        $link = str_replace('%%code%%', $this->booking->code, $link);

        if (isset($this->request['booking_from'])) {
            $link = str_replace(
                ['%%from%%', '%%fromWithoutDashes%%'],
                [$this->request['booking_from'], str_replace('-', '', $this->request['booking_from'])],
                $link
            );
        }

        if (isset($this->request['booking_to'])) {
            $link = str_replace(
                ['%%to%%', '%%toWithoutDashes%%'],
                [$this->request['booking_to'], str_replace('-', '', $this->request['booking_to'])],
                $link
            );
        }

        if (isset($this->request['lang']) && isset($this->mapping_lang[$this->request['lang']])) {
            $map = $this->mapping_lang[$this->request['lang']];
            $link = str_replace(array_keys($map), $map, $link);
        }

        if (isset($this->request['booking_nights'])) {
            $link = str_replace('%%nights%%', $this->request['booking_nights'], $link);
        }

        if (isset($this->request['quests'])) {
            $quests = $this->request['quests'];
        } else {
            $quests = 2;
        }

        $link = str_replace('%%adults%%', $quests, $link);

        $link = str_replace('%%ga%%', $<something should be here>, $link);
    
        return $link;

Is it possible to combine these two functions?

I have tried to access _ga parameter, but without URL it won't work. But URL is being generated in the moment someone is clicking reserve button.

Source