Tracking Data
In the Flagship SDK
, a Hit is a user interaction with your application that is tracked and sent to the Flagship server whenever a user performs a specific action or reaches a certain point in your application.
The SDK does not directly send hits as they are emitted. It uses the tracking manager, which is a mechanism that sends them to Flagship by batch through HTTPS. The tracking manager's batch processing reduces network traffic, prevents hits loss through caching, and resends any failed hits.
There are five different types of Hits, each corresponding to a specific KPI: Page
, Screen
, Transaction]
, Item
, and Event
. For additional details, refer to your specific SDK reference documentation.
The sendHit
method of the visitor instance is used to send these hits to the Flagship server.
Below are examples in different programming environments:
import { HitType, EventCategory } from "@flagship.io/js-sdk";
// ... other code
visitor.sendHit({
type: HitType.EVENT,
category: EventCategory.USER_ENGAGEMENT,
action: "click",
label: "label",
value: 100,
});
import React from "react";
import { FlagshipProvider, useFlagship, HitType, EventCategory } from "@flagship.io/react-sdk";
const App = () => (
<>
<FlagshipProvider
envId="<ENV_ID>"
apiKey="<API_KEY>"
visitorData={{
id: "<VISITOR_ID>",
hasConsented: true,
context: {
isVIP: true,
}
}}
>
<Component/>
</FlagshipProvider>
</>
);
const Component = () => {
const { sendHit } = useFlagship();
return (
<div>
<h1>My component</h1>
<button onClick={() =>{
sendHit({
type: HitType.EVENT,
category: EventCategory.USER_ENGAGEMENT,
action: "click",
label: "label",
value: 100,
});
}}>
Send event</button>
</div>
);
};
import React from "react";
import { FlagshipProvider, useFlagship, HitType, EventCategory } from "@flagship.io/react-native-sdk";
const App = () => (
<>
<FlagshipProvider
envId="<ENV_ID>"
apiKey="<API_KEY>"
visitorData={{
id: "<VISITOR_ID>",
hasConsented: true,
context: {
isVIP: true,
}
}}
>
<Component/>
</FlagshipProvider>
</>
);
const Component = () => {
const { sendHit } = useFlagship();
return (
<div>
<h1>My component</h1>
<button onClick={() =>{
sendHit({
type: HitType.EVENT,
category: EventCategory.USER_ENGAGEMENT,
action: "click",
label: "label",
value: 100,
});
}}>
Send event</button>
</div>
);
};
use Flagship\Enum\EventCategory;
// ... other code
$event = new Event(EventCategory::ACTION_TRACKING, "click");
$event->setLabel("label")->setValue(100);
$visitor->sendHit($event);
using Flagship.Hit;
// ... other code
var eventHit = new Event(EventCategory.ACTION_TRACKING, "click")
{
Label = "label",
Value = 100=
};
_ = visitor.SendHit(eventHit);
Information
When a visitor sets consent to false, the data collection features (visitorExposed and Track data) will be deactivated for them. All hits related to the visitor will be flushed from the pool and the cache.
Please consult the reference documentation for your specific SDK for more detailed information:
Updated 5 months ago