The line
When something on your site has no page, form or button Trace can watch, your site can tell Trace itself with one line of JavaScript:
trace.track('quote_sent');
quote_sent is the event name. In Trace, add a result with A custom event and type the same name. Capitals do not matter: Quote_Sent counts for quote_sent. Anything else in the name must match exactly.
Pick a short name with letters, numbers and underscores, like quote_sent or brochure_request. Leave out quote marks. form_submit, contact_click and element_click are taken by Trace’s own events and never count.
Send a value with it
To give each result its own value, such as the amount of a quote, add conversion_value:
trace.track('quote_sent', { conversion_value: 120 });
The value is a number in the same currency as your results, with no currency sign and no quote marks around it: 120 or 49.99, not '£120'. A value sent this way is used in place of the value set on the result.
Where to put it
Put the line where the thing has just happened, not where it might happen:
- After a form is sent successfully, in the code that runs once the form has gone through.
- On a confirmation page, which runs it as the page opens. Trace’s tag loads alongside your page, so wait for it:
<script>
window.addEventListener('load', function () {
if (window.trace) trace.track('quote_sent');
});
</script>
- When someone clicks something, in the code that runs on that click.
With Google Tag Manager
- Add a new tag of the type Custom HTML.
- Paste the line inside script tags:
<script>trace.track('quote_sent');</script> - Set its trigger to the moment the result happens, for example a form submission or a thank you page view.
- To send a value, use a variable:
<script>trace.track('quote_sent', { conversion_value: {{Quote value}} });</script>, whereQuote valueis a variable holding a number. - Publish the container.
Check it arrived
- Open your site in your browser. If your site asks about cookies, accept them first, or the visit is not counted.
- Right click anywhere and choose Inspect, then open the Console tab.
- Type
trace.track('quote_sent'), with your own name, and press Enter. If the console saystrace is not defined, Trace’s tag is not on that page: see Verify your installation. - Open Conversions in Trace. The result shows as seen once it has arrived. It counts as a real result from your own visit.
Then do the real thing on your site, such as sending a quote, to check the line runs where you put it.
