Use in mobile apps
Use in mobile apps
This is for:
Developer
The Server experiences API reference is located in the APIs section. |
In this article, we’ll show you how you can use a Server Experience in a mobile application.
Intro
Once a Server Experience has been built, you can use it in /en/qbb1t254/[mobile applications].
iOS
Swift
To fetch an experience, make the following call:
QubitSDK.fetchExperiences(withIds: [$EXPID], onSuccess: { (experiences) in
if let exp = experiences.first {
// list out the payload values
print("Got experience - payload:")
for (key, value) in exp.payload {
print("\(key) -> \(value)")
}
// mark the experience as shown
exp.shown()
}
}, onError: { (error) in
print("Got error: (error.localizedDescription)")
}, preview: false, ignoreSegments: false, variation: nil)
Where:
-
$EXPID
is the experience Id from app.qubit.com
An array of experiences experiencePayLoads
will be returned.
If the experience specified in $EXPID
is live, it will be in the first item in the array.
Within that object, the payload field will contain the variable set in the variation.
To preview an experience in development, set the following:
-
preview
totrue
-
variation
to the variation Id you wish to preview -
ignoreSegments
totrue
if you wish to bypass the segmentation logic for preview purposes
Objective-C
To fetch an experience, make the following call:
[QubitSDK fetchExperiencesWithIds:@[@$EXPID] onSuccess:^(NSArray<QBExperienceEntity *> * _Nonnull experiences) {
QBExperienceEntity* firstEntity = experiences.firstObject;
[firstEntity shown]; // mark the experience as shown
} onError:^(NSError * _Nonnull error) {
NSLog(@"%@", error.description);
} preview:false variation:false ignoreSegments:false];
Where:
-
$EXPID
is the experience Id from app.qubit.com
An array of experiences experiencePayLoads
will be returned.
If the experience specified in $EXPID
is live, it will be in the first item in the array.
Within that object, the payload field will contain the variable set in the variation.
To preview an experience in development, set the following:
-
preview
totrue
-
variation
to the variation Id you wish to preview -
ignoreSegments
totrue
if you wish to bypass the segmentation logic for preview purposes
Android
Java
To fetch a live experience:
List<Integer> experienceIds = new ArrayList<>();
experienceIds.add($EXPID);
QubitSDK.tracker().getExperiences(
listOfExperienceIds,
experienceList -> {
for (Experience experience : experienceList) {
experience.shown(); // mark the experience as shown
}
return Unit.INSTANCE;
},
throwable -> {
Log.d(TAG, throwable.toString());
return Unit.INSTANCE;
}, $VARID, true, true
);
Where:
-
$EXPID
is the experience Id from app.qubit.com
An array of experiences experiencePayLoads
will be returned.
If the experience specified in $EXPID
is live, it will be in the first item in the array.
Within that object, the payload field will contain the variable set in the variation.
To preview an experience in development, set the following:
-
preview
totrue
-
variation
to the variation Id you wish to preview -
ignoreSegments
totrue
if you wish to bypass the segmentation logic for preview purposes
Example - preview experience 123, variation 678, and check segmentation:
List<Integer> experienceIds = new ArrayList<>();
experienceIds.add(123);
QubitSDK.tracker().getExperiences(
experienceIds,
experienceList -> {
for (Experience experience : experienceList) {
experience.shown(); // mark the experience as shown
}
return Unit.INSTANCE;
},
throwable -> {
Log.d(TAG, throwable.toString());
return Unit.INSTANCE;
}, 678, true, false
);
Example - preview experience 123, variation 678, and bypass segmentation:
List<Integer> experienceIds = new ArrayList<>();
experienceIds.add(123);
QubitSDK.tracker().getExperiences(
experienceIds,
experienceList -> {
for (Experience experience : experienceList) {
experience.shown(); // mark the experience as shown
}
return Unit.INSTANCE;
},
throwable -> {
Log.d(TAG, throwable.toString());
return Unit.INSTANCE;
}, 678, true, true
);
Kotlin
QubitSDK.tracker().getExperiences(
experienceIdList = listOf($EXPID), // list of experience IDs (integers)
onSuccess = {
experienceList -> experienceList.forEach {
it.shown() // mark the experience as shown
}
},
onError = {
throwable -> Log.e(TAG, "Error: ", throwable)
},
variation = null,
preview = true,
ignoreSegments = true
)
-
Where $EXPID is the experience Id from app.qubit.com.
An array of experiences experiencePayLoads will be returned. If the experience specified in $EXPID is live, it will be in the first item in the array. Within that object, the payload field will contain the variable set in the variation.
To preview an experience in development, set the following:
-
preview: true
-
variation: variation Id you wish to preview
-
ignoreSegments : true if you wish to bypass the segmentation logic for preview purposes