Offline hits



Before starting to implement the OffLine plugin, please ensure that you have initialised the AT Internet JavaScript tracker and selected the plugin from within the Tag Composer interface.



The OffLine plugin allows you to save hits that could not be sent, following a loss of Internet connection, to the user’s browser. To do this, the plugin uses the localStorage feature available in recent browsers. The status of the Internet connection (whether the browser is online or not) is determined by the browser’s onLine property available in HTML5.

This plugin is therefore dedicated to use in HTML5 applications, with support from localStorage.

Use of this feature is subject to the subscription to an option. This feature may increase the storage space occupied on the user’s browser.


Configuring the storage mode

The storage management mode can be set up directly from within the Tag Composer interface or via the configuration when initialising the Tracker.

Three modes are available:

  • required (by default): Hits are only stored when a loss of Internet connection is detected.
  • always: Hits are never sent. They are stored directly on the browser.
  • never: Hits are never stored. If a loss of Internet connection is detected at the same time that a hit is sent, the hit will be lost.

To change the hit storage mode, add the following code in the desired area:

Save hits when Internet connection is lost:

Always save hits:

Never save hits:


Sending saved hits

Once an Internet connection is established, you can request the sending of stored hits at any moment.

To do this, the Tracker exposes an offLine object offering a send method:

This method sends all stored hits and deletes them from localStorage after each send.

Using this method, you can decide at which moment your hits are sent. By setting the storage mode to always, you can simply call the send method to trigger sending at the desired moment.


Retrieving hits

You may, at any moment, retrieve the list of saved hits. To do this, the get method from the offLine class is made available in the Tracker.

This method returns a table of URLs.


Storage size

You may, at any moment, obtain the number of hits stored in the browser’s localStorage.

You may also obtain the estimated size (in bytes) of hits stored in the browser’s localStorage. To do this, the offLine class exposes a getLength method:

The storage size is 1MB by default. You may change this value from within the Tag Composer interface or via the configuration when initialising the Tracker:


Deleting hits

You may manually delete all stored hits using the remove method:


Was this post helpful?
Last update: 30/01/2018