04Tracking
Custom events
How to send your own events to Gauss with gauss('event', …) — naming rules, parameter limits, recommended GA4 names, and examples for a button, form and React.
Automatic events cover page views, forms and contact links. A successful lead, a sign-up, a click on a key button or a purchase is something your site marks up itself, with one line of JavaScript.
The call
gauss('event', 'callback_request', { placement: 'header', plan: 'pro' });- the first argument is always
'event'; the tracker doesn't support other commands yet; - the second is the event name;
- the third is an optional parameters object.
The event is sent right away, along with the current page URL.
Queue stub for early calls
The snippet loads with defer, so gauss isn't available immediately. To keep calls made before the script loads, add this stub to the <head> before the snippet:
<script>
window.gauss = window.gauss || function () { (window.gauss.q = window.gauss.q || []).push(arguments); };
</script>
<script defer data-site="YOUR_SITE_ID" src="https://collect.gausslab.io/js/gauss.js"></script>The stub queues calls, and once the tracker loads it sends them in order, right after the page_view. With the stub in place, you can call gauss(...) anywhere on the page without checking whether the script has loaded. Without it, a call made before the script loads throws a ReferenceError. If your site uses a Content Security Policy, the inline script needs a nonce or a hash; see Installation.
Naming rules
Event names and parameter keys:
- use only lowercase Latin letters
a–z, digits0–9and_; - start with a letter;
- are no longer than 40 characters.
An event name can't start with gauss_, ga_, google_ or firebase_; these prefixes are reserved.
| Name | Result |
|---|---|
callback_request | accepted |
CallbackRequest | dropped: uppercase letters |
2nd_step | dropped: starts with a digit |
ga_lead | dropped: reserved prefix |
An event with an invalid name isn't sent, and the console shows a [gauss] dropped <name> warning.
Parameters and limits
| What | Limit |
|---|---|
| Number of parameters | up to 25 |
| Value type | string, number or true/false |
| String length | up to 100 characters; longer strings are truncated |
items (products) | array, up to 50 entries |
What happens to anything beyond that:
- parameters past the 25th, keys with invalid names, object values, arrays and
NaNare dropped, with[gauss] dropped <key>in the console; - empty strings,
nullandundefinedare skipped silently; itemskeeps the first 50 entries and drops the rest with a warning;- the rest of the event is still sent. A markup mistake doesn't break the page: the tracker never throws exceptions into your site's code.
Don't send email addresses, phone numbers, names or other personal details in parameters. How Gauss cleans such values on the server is covered in What data is collected.
Recommended names
For common actions, use names from the GA4 vocabulary. If your site is already tagged for GA4, you don't need to change event or parameter names; see GA4 compatibility.
| Event | When | Parameters |
|---|---|---|
generate_lead | a lead was submitted successfully | lead_id (optional), value, currency |
sign_up | sign-up | — |
login | login | — (no user identifier) |
view_item | product view | items |
add_to_cart | add to cart | items, value, currency |
begin_checkout | checkout started | items, value, currency |
purchase | purchase | transaction_id, value, currency, items |
refund | refund | transaction_id, value, currency |
How to tag purchases, products and conversion value is covered in Conversions and e-commerce.
Examples
A button click:
<button type="button" onclick="gauss('event', 'pricing_click', { placement: 'hero' })">See pricing</button>A form sent with fetch: form_submit arrives automatically, and generate_lead is sent only after the server responds successfully.
const form = document.querySelector('#callback');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const response = await fetch('/api/lead', { method: 'POST', body: new FormData(form) });
if (response.ok) {
gauss('event', 'generate_lead', { form_id: 'callback', value: 50, currency: 'USD' });
}
});React (with the stub in the <head>, window.gauss always exists):
export function DemoButton() {
return (
<button onClick={() => window.gauss?.('event', 'demo_request', { placement: 'pricing' })}>
Request a demo
</button>
);
}For TypeScript, declare the type once:
declare global {
interface Window {
gauss?: (command: 'event', name: string, params?: Record<string, unknown>) => void;
}
}
export {};Use debug mode to confirm the event goes out and nothing was dropped.