Store

class cleaninsights.store.Store(debug: Callable[[str], None] | None = None, **kwargs)

The store holds the user’s consents to the different Feature`s and `Campaign`s, and their `Visit and Event measurements.

If you want to implement your own persistence of the store (e.g. because you want to write it in a database instead of the file system) and your own implementation of the transmission to the Matomo/CIMP backend (e.g. because you want to tunnel the requests through a proxy or add your own encryption layer), then create a subclass of this class and implement the #__init__, #persist and #send methods.

load(**kwargs) Dict[str, Consents | List[DataPoint]] | None

This method gets called from the constructor and will receive the same parameters, as the constructor got.

Parameters:
  • args – Arguments your implementation might need for loading the store.

  • kwargs – Arguments your implementation might need for loading the store.

Returns:

Deserialized store data.

persist(asynchronous: bool, done: Callable[[Exception | None], None])

This method gets called, when the SDK is of the opinion, that persisting the Store is in order.

This is partly controlled by the Configuration.persist_every_n_times configuration option, and by calls to CleanInsights#persist.

If possible, try to honor the async flag: If it’s true, it is set so, because the SDK wants to reduce impact on user responsivity as much as possible. If it’s false, the SDK wants to make sure, that the call finishes before the app gets killed.

Parameters:
  • asynchronous – Indicates, if the persistence should be done asynchronously or synchronously. E.g. a persist call during the exit of an app should be done synchronously, otherwise the operation might never get finished because the OS kills the server too early.

  • done – Callback, when the operation is finished, either successfully or not. If no error is returned, the operation is considered successful and the internal counter will be set back again.

send(data: str, server: str, timeout: int, done: Callable[[Exception | None], None])

This method gets called, when CleanInsights gathered enough data for a time period and is ready to send the data to a CIMP (CleanInsights Matomo Proxy).

Parameters:
  • data – The serialized JSON for a POST request to a CIMP.

  • server – The server URL from Configuration.server.

  • timeout – The timeout in seconds from Configuration.timeout.

  • done – Callback, when the operation is finished, either successfully or not. If no error is returned, the data sent will be removed from the store and the store persisted.