Resources

How to Add Custom Events with Truly Analytics

Word count
499 words
Estimated reading time
3 min read
Date created
Created
Last modified date
Updated

This article is for customers and their integration agents and partners to get some details on how to actually utilize Truly Analytics alongside Google Analytics or independently.

Truly analytics is effectively a drop-in replacement for Google Analytics. So your code can be essentially completely replaced with just the Truly Analytics object and everything will work totally fine as it did for Google Analytics code.

A lot of this article is going to be concentrated on standalone Truly Analytics installations. We’ll follow the drop-in replacement of Google Analytics in a different article.

The event call

If your website already detects when an action happens, send it to Truly Analytics with window.ta.event(eventName, parameters). Keep the existing trigger and pass the event name followed by an object containing any useful parameters.

The Truly Analytics script must be installed on the page. Call window.ta.event() when the tracked action occurs:

if (window.ta && typeof window.ta.event === "function") {
  window.ta.event("event_name", {
    item_id: "guide-123",
    page_path: window.location.pathname
  });
}

The first argument is the event name. The second is an object of event parameters. Pass an empty object ({}) when the event does not need parameters. The readiness check prevents an error if the Truly Analytics script has not loaded yet.

For an existing JavaScript event handler, keep the handler and replace its analytics call with window.ta.event(), reusing the event name and parameter values where they fit. This sends the event into the site’s Truly Analytics setup. Any forwarding to Google Analytics or another destination depends on that setup; keep a separate analytics call if another tool still needs to receive the event directly.

Examples from this website

The contact form sends generate_lead after the form submission succeeds:

window.ta.event("generate_lead", {
  method: "contact_form",
  form_id: "contact-form",
  page_path: window.location.pathname,
  page_title: document.title
});

Links can use the cta_click event with details such as the link location, destination and text. The site also records video events including video_start, video_play, video_pause, video_progress, video_seek and video_complete, with parameters such as video_id, video_name and video_percent.

These names are examples from the site’s implementation. Choose event names that describe meaningful actions on your own site, then use the same name consistently wherever that action is tracked.

Choose useful parameters

Parameters add context that helps you interpret an event. Keep them relevant to the action and use stable, descriptive keys, for example:

window.ta.event("resource_download", {
  resource_name: "analytics-guide",
  page_path: window.location.pathname
});

Do not include names, email addresses, form contents or other personal information in event parameters. Send only the details needed to understand the action.

Test the event

Trigger the action on the page and check that the event appears in the configured Truly Analytics reporting flow with the expected name and parameters. Confirm it fires once per action, including on the relevant mobile and desktop interactions. If the event should also reach Google Analytics or a connected workflow, confirm that destination is configured to receive it. Event Hooks can route selected events to configured downstream systems as part of the managed Truly Analytics service.

Keep Reading

Related Articles

What 140 Directory Listings Revealed

A case study on using Truly Analytics First Party Attribution to assess 140 directory submissions, measure referral value, inspect traffic quality and separate direct attribution from unsupported channel claims.

Read article →