Track conversions and custom events
Grona measures campaigns against the goals you send it, such as a completed order, a sign-up or an add to basket. Use this page to send conversions from your own code with grona('track', ...), or with a goal snippet that the dashboard generates for you, and to understand when a conversion is counted.
Send a conversion from your code
Section titled “Send a conversion from your code”Call grona('track', eventName, data) when the conversion happens. Use the event name of the goal you set up in the dashboard as eventName, so the goal’s reports include the conversion, and pass details about the conversion in data. Avoid cart_updated and names that start with cart_reached_, which Grona records for its own basket measures.
grona('track', 'purchase', { order_id: 'ord_58213', currency: 'USD', items: ['sku_10432', 'sku_20877'],});data is free-form. Grona stores the fields with the conversion, and uses order and booking codes to count each order once (see De-duplication). The full signature is in the JavaScript API reference.
Call it before the script has loaded
Section titled “Call it before the script has loaded”main.js loads asynchronously, so your code can run before window.grona exists. Add this stub once, above any call to grona(). It queues calls, and the runtime replays them once it has started.
<script> window.grona = window.grona || function () { (window.grona.q = window.grona.q || []).push(arguments); };</script>Use a goal snippet from the dashboard
Section titled “Use a goal snippet from the dashboard”If you would rather not write the call yourself, create the goal as a conversion metric in the dashboard with the Custom Event type, and copy the snippet it generates. The snippet is self-contained: it adds the queue stub, loads main.js if the page does not already have it, and calls grona('track', ...) with your event name when its trigger fires.
| Trigger type | The snippet sends the conversion when |
|---|---|
| Page Load | the page path matches the URL pattern you enter, such as /thank-you. The pattern is a regular expression tested against the path, so /thank-you also matches /order/thank-you; use ^/thank-you$ to match only that page. |
| Click | the visitor clicks an element that matches the element selector, such as #submit-button, including elements added to the page later |
| Form Submit | the visitor submits a form that matches the form selector, such as #checkout-form, or a form that contains a matching element |
| Manual | trackConversion() is called. The generated snippet has this call commented out. The function exists only inside the snippet, so the call must stay inside it: code elsewhere on the page that calls trackConversion() fails with a ReferenceError. From your own code, call grona('track', ...) directly instead. |
-
In the dashboard, create a conversion metric with the Custom Event type, an event name such as
purchaseand a trigger type. -
Add any data fields the goal should carry, such as
order_id. The snippet contains a placeholder for each field: replace eachnullwith code that reads the real value on your page. -
Paste the snippet on the page where the conversion happens.
-
Trigger the conversion once in a normal browser window and check the request to
api.grona.aiin the network panel. See Debug in the browser.
On Shopify, goals use a Customer Events custom pixel instead of a page snippet. See the Shopify guide.
De-duplication
Section titled “De-duplication”When data carries one of these fields, Grona counts the goal once per code, even if the same order is sent more than once, for example when the visitor reloads the confirmation page:
order_idorder_codeorder_numberbooking_id
Send the same code your order system uses. A conversion with none of these fields is counted every time it is sent.
Conversions on pages without a campaign
Section titled “Conversions on pages without a campaign”You do not need a campaign on the page where the conversion happens. A conversion sent on a page where no campaign ran is credited to the campaigns the visitor saw in the previous 30 days, so a checkout page with no campaign still counts towards the campaign on your home page.
When conversions are not counted
Section titled “When conversions are not counted”A call to grona('track', ...) does not record a conversion when:
- the page is a preview. Preview links record nothing. See Preview and QA a variation.
- the visitor is a bot. Crawlers and testing tools that Grona recognises by their user agent never run campaigns or send conversions.
- the visitor has not consented in a workspace set to wait for consent. Grona has no visitor id for them, so nothing is sent. See Consent and storage.
- the request is blocked. A Content Security Policy without
https://api.grona.aiinconnect-src, or an ad blocker that blocks Grona, stops the request. See Content Security Policy. - the call was queued through the older stub, which drops the event name. Use the stub above.
- the order code was already counted for that goal.