Offline hits

Foreword

The AT Internet SDK enables you to store, on the users device, any hits that couldnt be sent due to loss of Internet connection. For this, the SDK uses Windows ApplicationDataContainer API.

Use of this feature is subject to the subscription to an option. This feature may increase the disk space that your application occupies on a users device.

Setting up the storage mode

You can set up the storage management mode directly within the Tag Composer interface, or via the Trackers SetConfigmethod.

Three modes are available:

Required: Hits are only stored when a loss of connection is detected.

Always: Hits are never sent. They are directly stored on the device.

Never (by default): Hits are never stored. If a loss of connection is detected at the same time as an attempt to send the hit, the hit will be lost.

To edit the hit storage mode, add the following code to the desired area:

Save hits during loss of connection:

C#

1

2

3

tracker.SetConfig("storage","required",null);

Always save hits:

C#

1

2

3

tracker.SetConfig("storage","always",null);

Never save hits:

C#

1

2

3

tracker.SetConfig("storage","never",null);

Sending saved hits

At any moment (if an Internet connection is established), you can request that stored hits be sent.

To do this, the Tracker exposes an offlineobject offering a sendmethod:

C#

1

2

3

SmartTag.Instance.defaultTracker.Offline.Dispatch();

This method sends all stored hits in an asynchronous manner, and deletes them if the send was successful. If the send failed, two new attempts will be made during the next hit send. If all attempts fail, the hit will be deleted from storage.

Thanks to this method, you may decide at which moment you want hits to be sent. By setting the storage mode to always, you can simply call the Sendmethod to trigger sending at the desired moment.

Recovering hits

Listing

You can recover the list of saved hits at any moment. To do this, the getmethod of the Offlineclass is available in the Tracker.

C#

1

2

3

IList hits=SmartTag.Instance.defaultTracker.Offline.Get();

This method returns an object list Hit. This object possesses the following properties:

url: URL of the hit

CreationDate: the date the hit was created

RetryCount: number of attempts to send the hit

IsOffline: indicates that the hit comes from storage

Type: type of hit (e.g. Screen, Touch )

First saved hit

You can recover the first hit saved via the Oldestmethod of the Offlineclass:

C#

1

2

3

Hit hit=SmartTag.Instance.defaultTracker.Offline.Oldest();

Last saved hit

You can recover the last saved hit via the latestmethod of the Offlineclass:

C#

1

2

3

Hit hit=SmartTag.Instance.defaultTracker.Offline.Lastest();

Counting

You may obtain the number of hits stored in the database at any moment. To do this, the Offlineclass exposes a Countmethod:

C#

1

2

3

intnbHits=SmartTag.Instance.defaultTracker.Offline.Count();

Deleting hits

You can manually delete stored hits thanks to the following static methods:

Delete: Deletes all stored hits

C#

1

2

3

SmartTag.Instance.defaultTracker.Offline.Delete();

Delete(Date olderThan): Deletes hits older than the date passed in the parameter