This is the iOS SDK used to send beacons to GroupBy.
-
From the Xcode menu click File > Swift Packages > Add Package Dependency.
-
In the dialog that appears, enter the repository URL: https://github.com/groupby/gb-ios-tracker-client
-
In Version, select Up to Next Major and take the default option.
-
Follow instructions here for setting up CocoaPods for the project, if not set up already: https://guides.cocoapods.org/using/using-cocoapods.html
-
Add the dependency to your pod file
pod 'GroupByTracker', '~> 1.0.1'
- Run
pod install
To import and use the tracker:
import GroupByTracker
// create the SDK instance
let tracker = GbTracker(customerId: "customer_id", area: "area", login: Login(loggedIn: false, username: ""))
// set the login data
tracker.setLogin(login: Login(loggedIn: true, username: "[email protected]"))
// create beacon
let atcBeacon = AddToCartBeacon(...)
// send beacon
tracker.sendAddToCartEvent(addToCartBeacon: atcBeacon) { error in
guard error == nil else {
guard let gbError = error as? GbError else {
// unknown error
...
return
}
// If there are data validation errors, a list of string with the error details will be returned.
// If there is a network or any other error, the code variable will contain the HTTP status code returned.
switch gbError {
case .error(let code, let errorDetails, let innerError):
guard let errorDetails = errorDetails else {
// network or other error
...
return
}
if (errorDetails.jsonSchemaValidationErrors.count > 0)
{
...
}
break
}
return
}
}
The constructor for the tracker client has an optional parameter for overriding the default url. By default, the url points to production endpoints. This can be overriden to point to a test endpoint or internal endpoint
let tracker = GbTracker(customerId: "customer_id", area: "area", login: Login(loggedIn: true, username: "[email protected]"), urlPrefixOverride: <some_url>) // Optional, overrides the URL the beacon is sent to. Useful for testing.
The user's login data can be set during the creation of the tracker instance or set when the user logs in after the tracker is already created.
Login data allows activities between multiple merchandiser applications and web to be attributed to the same user.
let tracker = GbTracker(customerId: "customer_id", area: "area", login: Login(loggedIn: true, username: "[email protected]"))
// or
let tracker = GbTracker(customerId: "customer_id", area: "area", login: Login(loggedIn: false, username: ""))
...
tracker.setLogin(login: Login(loggedIn: true, username: "[email protected]"))
On user logout:
tracker.setLogin(login: Login(loggedIn: false, username: ""))
VisitorId is a UUID used to anonymously track the user. This id is not tied to any external systems and can only be used to track activity within the same app install. VisitorId has an expiry time of 1 year since the last time the shopper visited. After that a new Id will be generated. This by default is stored in UserDefaults.standard.
See the docs for more detailed information about implementing beacons:
https://docs.groupbycloud.com/gb-docs/gb-implementation/beacons/overview