Finalize
Finalizing (or closing) a context publishes any unpublished events before
"sealing" it. Any track
calls after a context has been finalized will throw
an error.
Some examples of when you may want to finalize a context:
- When your application is being destroyed.
- When a user logs out. In this case, you no longer know if the current user
is the same user as before. It is best to finalize the original context,
create a new one and pass it an
anonymous_id
.
- Javascript
- Python3
- React
- Swift
- Vue2
- Vue3
- Java
- Go
- .NET
- PHP
- Ruby
- Flutter/Dart
Call the context.finalize()
method before letting a process using the SDK exit, as
this method gracefully shuts down the SDK by clearing caches, and closing
connections. It will also call context.publish()
to flush the remaining
unpublished impressions.
// You can just finalize and remove the variable reference
context.finalize();
context = null;
// finalize() returns a promise, so if you want to
// navigate to another page without losing impressions, you
// can do that once the promise resolves.
context.finalize().then(function () {
context = null;
document.location.replace("another_page");
});
After finalize()
is called and finishes, any subsequent invocations to the
treatment()
method will still return the right variant, but will result in a
warning to let you know that you might be losing impressions.
The close()
and close_async()
methods will ensure all events have been
published to the ABsmartly collector, like publish()
, and will also "seal"
the context, throwing an error if any method that could generate an event is
called.
context.close()
Call the context.finalize()
method before letting a process using the SDK exit, as
this method gracefully shuts down the SDK by clearing caches, and closing
connections. It will also call context.publish()
to flush the remaining
unpublished impressions.
context.finalize().then(() => {
document.location.replace("another_page");
});
After finalize()
is called and finishes, any subsequent invocations to the
treatment()
method will still return the right variant, but will result in a
warning to let you know that you might be losing impressions.
The close()
methods will ensure all events have been published to the
ABsmartly collector, like publish()
, and will also "seal" the context,
throwing an error if any method that could generate an event is called.
context.close().done {
print("context closed")
}
The finalize()
method will ensure all events have been published to the
ABsmartly collector, like publish()
, and will also "seal" the context,
throwing an error if any method that could generate an event is called.
await this.$absmartly.finalize().then(() => {
window.location = "https://www.absmartly.com";
});
The finalize()
method will ensure all events have been published to the
ABsmartly collector, like publish()
, and will also "seal" the context,
throwing an error if any method that could generate an event is called.
await this.$absmartly.finalize().then(() => {
window.location = "https://www.absmartly.com";
});
The close()
and closeAsync()
methods will ensure all events have been
published to the ABsmartly collector, like publish()
, and will also "seal"
the context, throwing an error if any method that could generate an event is
called.
context.close();
The Close()
and CloseAsync()
methods will ensure all events have been
published to the ABsmartly collector, like Publish()
, and will also "seal"
the context, throwing an error if any method that could generate an event is
called.
context.Close();
The ABsmartly Context implements IDisposable
and IAsyncDisposable
interfaces to ensure
that all events have been published to the ABsmartly collector, like Publish()
,
and the context has been "sealed". An error will then be thrown if any method that
could generate an event is called.
To implement this, instead of calling Publish()
directly, the using
pattern can be used.
using var context = _abSdk.CreateContext(config);
The close()
method will ensure all events have been published to the
ABsmartly collector, like Context->publish()
, and will also "seal" the context,
throwing an error if any method that could generate an event is called.
$context->close();
The close()
method will ensure all events have been published to the
ABsmartly collector, like publish()
, and will also "seal" the context, throwing
an error if any method that could generate an event is called.
context.close
The close()
method will ensure all events have been published to the
ABsmartly collector, like publish()
, and will also "seal" the context, throwing
an error if any method that could generate an event is called.
context.close();