How the Script Works in Wirelytic

Learn how the javascript works to track events.

Wirelytic provides a script that allows you to seamlessly integrate tracking and analytics capabilities into your website. This script empowers you to monitor pageviews and events, gaining valuable insights into user interactions and behaviors. Let's delve into how the script works and how you can effectively utilize it.

Get the script

  1. Add a website
  2. Click on the Show script button
Show script
Show script
  1. Copy the script from the modal
Script modal
Script modal

If you already have a website click on the Settings button and get the script under JavaScript Snippet

Script in the website settings
Script in the website settings
  1. Add the script to the Head of your website

Custom Pageview Tracking

To track a pageview, you can use the following JavaScript code:

wirelytic.trackView(url, [referrer], [website_id]);
  • url: The URL of the page being tracked.
  • referrer (optional): The referrer of the page.
  • website_id (optional): The unique identifier of the website.

If the referrer and website_id are not provided, the script will default to using the page referrer and the data-website-id defined by the script.

For simple pageview tracking, use:


Tracking Events

Class Event Tracking

Class events allow you to track custom events without requiring JavaScript. By adding specific classes to HTML elements, you can trigger event tracking. For example:


<button id="class-button" class="button wirelytic--click--signup-button">
  Trigger Class

JavaScript (JS) Event Tracking

JavaScript event tracking provides flexibility in tracking custom events with more data. You can track events without data using:

wirelytic('js button click');

For events with data, use the trackEvent method:

wirelytic.trackEvent([name], [data], [url], [website_id]);
  • name: The event name
  • data (optional): Add custom meta data to your event
  • url (optional): The url where the event is triggered
  • website_id (optional): The unique identifier of the website.
  'trackEvent button click',
  { type: 'test_event', userId: 123 },

Script options

Disable Auto Tracking

Add data-auto-track="false"

Disable User Tracking

You can configure Wirelytic to respect the visitor’s Do Not Track setting. Add data-do-not-track="true"

Allow to track on specific domains

Add data-domains=","

Google Tag Manager

Google Tag Manager will strip the attributes from the tracker, so you can bypass this by using the format below.

  (function () {
    var el = document.createElement('script');
    el.setAttribute('src', '');
    el.setAttribute('data-website-key', '123456789');
    el.setAttribute('data-api', '');

The Wirelytic script seamlessly integrates into your website, allowing you to collect data on pageviews and user interactions. This data is then presented in your Wirelytic dashboard, enabling you to gain valuable insights into user behavior, optimize user experiences, and make informed decisions for your website or application.