Foreword

Principle

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:

JavaScript

1

2

3

4

varconfig={Offline:{storageMode:'required'}};

vartag=newATInternet.Tracker.Tag(config);

Always save hits:

JavaScript

1

2

3

4

varconfig={Offline:{storageMode:'always'}};

vartag=newATInternet.Tracker.Tag(config);

Never save hits:

JavaScript

1

2

3

4

varconfig={Offline:{storageMode:'never'}};

vartag=newATInternet.Tracker.Tag(config);

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:

JavaScript

1

2

3

tag.offline.send();

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.

JavaScript

1

2

3

varhits=tag.offline.get();

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.

JavaScript

1

2

3

varcount=tag.offline.get().length;

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:

JavaScript

1

2

3

varlength=tag.offline.getLength();

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: