title: How to create a purchase event for GA4 using variables from another code?
body: <p>I would like to send events to GA4 using the variables from lines 29-57. I understand little about programming, how to do this?</p>
  <p>I want to send a buy event to GA4 using the variables from lines 29-57.</p>
  <p>I'm having trouble because I don't know where and how to inject the code.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php defined('ALTUMCODE') || die() ?&gt;
  
  &lt;div class="container"&gt;
      &lt;?= \Altum\Alerts::output_alerts() ?&gt;
  
      &lt;div class="d-flex flex-column align-items-center justify-content-center text-center"&gt;
          &lt;img src="&lt;?= ASSETS_FULL_URL . 'images/thank_you.svg' ?&gt;" class="col-10 col-md-6 col-lg-4 mb-4" alt="&lt;?= l('pay_thank_you.header') ?&gt;" /&gt;
  
          &lt;h1&gt;&lt;?= l('pay_thank_you.header') ?&gt;&lt;/h1&gt;
  
          &lt;?php if(isset($_GET['code_days'])): ?&gt;
              &lt;p class="text-muted"&gt;&lt;?= sprintf(l('pay_thank_you.plan_redeemed'), (int) $_GET['code_days']) ?&gt;&lt;/p&gt;
          &lt;?php elseif(isset($_GET['payment_processor']) &amp;&amp; in_array($_GET['payment_processor'], ['paypal', 'stripe', 'coinbase', 'payu', 'paystack', 'razorpay', 'mollie', 'yookassa', 'crypto_com', 'paddle'])): ?&gt;
              &lt;p class="text-muted"&gt;&lt;?= l('pay_thank_you.plan_custom_will_start') ?&gt;&lt;/p&gt;
          &lt;?php elseif(isset($_GET['payment_processor']) &amp;&amp; $_GET['payment_processor'] == 'offline_payment'): ?&gt;
              &lt;p class="text-muted"&gt;&lt;?= l('pay_thank_you.plan_custom_pending') ?&gt;&lt;/p&gt;
          &lt;?php else: ?&gt;
              &lt;p class="text-muted"&gt;&lt;?= sprintf(l('pay_thank_you.plan_trial_start'), (int) $_GET['trial_days']) ?&gt;&lt;/p&gt;
          &lt;?php endif ?&gt;
  
          &lt;a href="&lt;?= url('dashboard') ?&gt;" class="btn btn-outline-primary mt-4"&gt;&lt;?= l('pay_thank_you.button') ?&gt;&lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;?php ob_start() ?&gt;
  &lt;script&gt;
      let current_url = new URL(window.location.href);
  
      /* Here you could add your thank you page affiliate tracker code and use the already ready variables from below */
      let plan_id = current_url.searchParams.get('plan_id');
  
      /* The payment gateway name (ex: stripe) */
      let payment_processor = current_url.searchParams.get('payment_processor');
  
      /* The payment frequency (monthly, annual, lifetime) */
      let payment_frequency = current_url.searchParams.get('payment_frequency');
  
      /* The payment type (one_time, recurring) */
      let payment_type = current_url.searchParams.get('payment_type');
  
      /* Discount code, if any */
      let code = current_url.searchParams.get('code');
  
      /* Paid amount */
      let total_amount = current_url.searchParams.get('total_amount');
  
      /* Unique random identifier for this transaction */
      let unique_transaction_identifier = current_url.searchParams.get('unique_transaction_identifier');
  
      /* User id of the current logged in user */
      let user_id = current_url.searchParams.get('user_id');
  
  &lt;/script&gt;
  &lt;?php \Altum\Event::add_content(ob_get_clean(), 'javascript') ?&gt;</code></pre>
  </div>
  </div>
  </p>