Set Up User Context on Joomla

Pass the logged-in user's info using a System Plugin or template override

Back to User Context
Standard & Pro Plans

What You're Setting

User Context is a client-side JavaScript object. On every page where the widget loads for a logged-in user, you attach an object to window.Asyntai.userContext describing who they are. The widget sends this with each message, so the AI can reply with their name, order status, plan tier, or anything else relevant.

Keys act as labels the AI sees, so make them descriptive — use "Customer name" or "Loyalty points", not just "name" or "points".

window.Asyntai = window.Asyntai || {};
window.Asyntai.userContext = {
  "Customer name": "Sarah Chen",
  "Email": "sarah@example.com",
  "Subscription plan": "Pro",
  "Loyalty points": 1840,
  "Last order": "#8847, out for delivery"
};

Two ways to set it

Either assign synchronously (if data is already on the page), or provide a fetcher that runs when the chat opens. The second option is better for performance — user data is only loaded when someone actually opens the chat.

// Option A — synchronous (data already available)
window.Asyntai.userContext = { "Customer name": "Sarah", ... };

// Option B — async fetch on chat open (better performance)
window.Asyntai.fetchUserContext = function() {
  return fetch('/api/chat-context/')
    .then(r => r.json())
    .then(data => { window.Asyntai.userContext = data; });
};

Security & size: Never include passwords, credit card numbers, API tokens, or anything sensitive — this data is on the client and visible to anyone inspecting the page. Context is capped at 2,000 characters on Standard and 10,000 characters on Pro; if you exceed it, the tail is truncated.

How Joomla Exposes the User

Joomla's user API — Factory::getApplication()->getIdentity() (Joomla 4+) or JFactory::getUser() (Joomla 3) — returns the currently logged-in user. The simplest integration is a System Plugin that hooks onBeforeCompileHead and injects the script, or a template override that outputs it in the footer.

Option 1 — Template Override (quickest)

Edit your active template's index.php to output the script just before the closing body tag.

1
Open your template's index.php Joomla admin → System → Site Templates → click your active template → Files → open index.php. It's a mix of PHP and HTML.
2
Paste the PHP block below just before </body> Save. The script will run on every front-end page of your site.
<?php
// Joomla 4+
use Joomla\CMS\Factory;
$user = Factory::getApplication()->getIdentity();
if ($user && !$user->guest):
  $context = [
    'Name'   => $user->name,
    'Email'  => $user->email,
    'Username' => $user->username,
    'Groups' => implode(', ', array_values($user->get('groups', []))),
  ];
?>
<script>
  window.Asyntai = window.Asyntai || {};
  window.Asyntai.userContext = <?php echo json_encode($context); ?>;
</script>
<?php endif; ?>

Joomla 3 note: If you're still on Joomla 3, replace Factory::getApplication()->getIdentity() with JFactory::getUser(). The rest is identical.

Option 2 — System Plugin (survives template updates)

A small system plugin is more robust since it survives template updates. It hooks into onBeforeCompileHead and injects the script via $document->addCustomTag().

<?php
// plugins/system/asyntaicontext/asyntaicontext.php
defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;

class PlgSystemAsyntaicontext extends CMSPlugin {
  public function onBeforeCompileHead() {
    $app = Factory::getApplication();
    if (!$app->isClient('site')) return;

    $user = $app->getIdentity();
    if (!$user || $user->guest) return;

    $context = json_encode([
      'Name'  => $user->name,
      'Email' => $user->email,
      'Groups' => implode(', ', array_values($user->get('groups', []))),
    ]);

    $doc = Factory::getDocument();
    $doc->addScriptDeclaration(
      'window.Asyntai=window.Asyntai||{};window.Asyntai.userContext=' . $context . ';'
    );
  }
}

Package it with a standard Joomla plugin XML manifest, install, and enable under Extensions → Plugins → search "asyntai".

Troubleshooting

The AI doesn't seem to know who I am

Open your browser DevTools → Console → type window.Asyntai.userContext after the page loads. You should see your object. If it says undefined, your script didn't run — check the script order (context must be set after the widget script loads, or be re-set whenever the user logs in).

Context works on some pages but not others

The widget reads window.Asyntai.userContext on every message. If a page loads fresh (no SPA routing), you need to set context on that page too. For single-page apps, set it once after login and update it whenever user data changes.

Data is stale after the user updates their profile

Re-assign window.Asyntai.userContext with the fresh data after any update. The next message the user sends will include the updated values — no page reload needed.

Context is truncated

You're over the size limit (2k chars Standard, 10k Pro). Trim verbose fields — keep order history to last 2-3 items, truncate long descriptions, drop fields the AI doesn't need.

User Context status page shows "Not receiving context"

Visit the User Context settings page while logged in as a test user, then send a chat message. The status refreshes within a few seconds. If still empty, check the browser console for JavaScript errors and verify the object is set before the chat message is sent.

Privacy reminder: Only share fields relevant to the conversation. Passing a customer's full purchase history when they just want to ask a general question is wasteful and can confuse the AI. Scope context to what helps.