Segments API
Integration of segments through SDK. Methods of operation.
List of methods
Properties:
gp.segments.list
- list of segments. FREE
Checks:
gp.segments.has()
- check if the player is in the segment. FREE
Events:
gp.segments.on('enter')
- subscribe to the moment of entering a segment.gp.segments.on('leave')
- subscribe to the moment of leaving a segment.
Properties
List of segments
FREEYou have access to the entire list of segments at once when the game starts and the player loads, in the format of a string array.
- JavaScript
- Unity
gp.segments.list;
GP_Segments.List()
Example content:
[
'HAS_PAYMENTS',
'VIP',
'NEWBLE',
'VERY_ACTIVE'
]
Checks
Segment check
gp.segments.has(tag)
FREE
- JavaScript
- Unity
// By Tag
const hasPayments = gp.segments.has('HAS_PAYMENTS');
// Check
if (hasPayments) {
// Player is in the HAS_PAYMENTS segment
}
// By Tag
bool hasPayments = GP_Segments.Has('HAS_PAYMENTS');
// Check
if (hasPayments) {
// Player is in the HAS_PAYMENTS segment
}
Events
Enter segment
The callback returns the segment tag as a string:
- JavaScript
- Unity
gp.segments.on('enter', (segmentTag) => {
// player entered the segment
});
// Subscribe to event
private void OnEnable()
{
GP_Segments.OnSegmentEnter += OnEnter;
}
// Unsubscribe from event
private void OnDisable()
{
GP_Segments.OnSegmentEnter -= OnEnter;
}
// Player enter segment
public void OnEnter(string tag)
{
ConsoleUI.Instance.Log("Enter segment: " + tag);
}
Leave segment
The callback returns the segment tag as a string:
- JavaScript
- Unity
gp.segments.on('leave', (segmentTag) => {
// player left the segment
});
// Subscribe to event
private void OnEnable()
{
GP_Segments.OnSegmentLeave += OnLeave;
}
// Unsubscribe from event
private void OnDisable()
{
GP_Segments.OnSegmentLeave -= OnLeave;
}
// Player leave segment
public void OnLeave(string tag)
{
ConsoleUI.Instance.Log("Leave segment: " + tag);
}
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!