Using SPM on Mobile
You can use Sailthru's Site Personalization Manager (SPM) to send personalized content to your users across channels - Onsite, Email and Mobile.
On mobile this is dead simple, and similar to implementing our JavaScript Client Library in Custom Mode.
This guide assumes that you've set up SPM on the web, and linked your Sailthru Client with your Sailthru Mobile App.
Tracking Content Metrics
Content Metrics overview
When providing personalized content, tracking a user's interests is of great importance. Interest tracking allows you to recommend items or articles to the user that they actually care about, making them more likely to convert through your recommended content. SPM provides three different types of tracking metrics:
- A pageview is an indication that a user has seen a given item of content's detail view - for example, a page for a certain product in an online store, or a full news article in a news site.
- An impression is a reasonable assumption that a user has seen a given piece of content - maybe they've scrolled past it in a list view, or seen it in a "Recommended" panel on another content item.
- A click is exactly what it sounds like: it means that a user has clicked - or in this case tapped - on a given piece of content to learn more. This usually, but not always, means that a user will now transition to that content's detail view.
Implementing Content Metrics
Tracking Pageviews
EngageBySailthru's trackPageview
method should be passed a URL corresponding to the web URL of the content being viewed, as well as an array of tags. If the tags array is empty or null, EngageBySailthru will use any tags for this page stored in your content library - otherwise, those stored tags will be overridden by any passed to trackPageview
.
NSArray<NSString*> *tags = @[@"blazer", @"beige", @"tan"];
NSURL *contentUrl = [NSURL URLWithString:@"https://varickandvandam.com/products/1153128"];
[[EngageBySailthru new] trackPageviewWithUrl: contentUrl, andTags: tags, andResponse: ^(NSError *error) {
if (error) {
// Handle error case
} else {
// Things went right, hooray!
}
}];
// Alternatively, if we don't mind too much if the track request fails, use a nil block:
[[EngageBySailthru new] trackPageviewWithUrl: contentUrl, andTags: tags, andResponse: nil]
let tags = ["blazer", "beige", "tan"]
let contentUrl = URL(string: "https://varickandvandam.com/products/1153128")
EngageBySailthru().trackPageview(withUrl: contentUrl, andTags: tags) { (errorOrNil) in
if let error = errorOrnil {
print(error)
return
}
// Track success! 🙌
}
// Alternatively, if we don't mind too much if the track request fails, just omit the block:
EngageBySailthru().trackPageview(withUrl: contentUrl, andTags: tags)
ArrayList<String> tags = new ArrayList(Arrays.asList("blazer", "beige", "tan"));
URI contentUrl = URI.create("https://varickandvandam.com/products/1153128");
new EngageBySailthru().trackPageview(contentUrl, tags, new EngageBySailthru.TrackHandler() {
@Override
public void onSuccess() {
// We're good
}
@Override
public void onFailure(Error error) {
// Handle errors here
}
});
// Alternatively, if we don't mind too much if the track request fails, use a null handler:
new EngageBySailthru().trackPageview(contentUrl, tags, null)
val tags = listOf("blazer", "beige", "tan")
val contentUrl = URI.create("https://varickandvandam.com/products/1153128")
EngageBySailthru().trackPageview(contentUrl, tags, object : EngageBySailthru.TrackHandler {
override fun onSuccess() {
// We're good
}
override fun onFailure(error: Error?) {
// Handle errors here
}
})
// Alternatively, if we don't mind too much if the track request fails, use a null handler:
EngageBySailthru().trackPageview(contentUrl, tags, null)
var url = "https://varickandvandam.com/products/1153128";
var tags = ["blazer", "beige", "tan"];
EngageBySailthru.trackPageview(url, tags).then(function() {
// handle success
}, function(error) {
// handle error
});
// Alternatively, if we don't mind too much if the track request fails, omit then handler:
EngageBySailthru.trackPageview(url, tags);
string contentUrl = "https://varickandvandam.com/products/1153128";
string[] tags = { "blazer", "beige", "tan" };
new EngageBySailthru().TrackPageview(contentUrl, tags);
We recommend tracking pageviews as views within your app are being initialized. For example, on Android, you might call trackPageview
in a Fragment's onCreateView
method, whereas on iOS you might place it in a ViewController's viewDidAppear
method.
Tracking Impressions
An impression should be tracked when a section of recommended content is seen by a user. EngageBySailthru's trackImpression
method takes a SPM Section ID as its first argument, and a list of URLs corresponding to the URLs of the items in the section.
NSArray<NSURL*> *urls = @[
[NSURL URLWithString:@"https://varickandvandam.com/products/1153128"],
[NSURL URLWithString:@"https://varickandvandam.com/products/1098230"],
[NSURL URLWithString:@"https://varickandvandam.com/products/1078590"]
];
NSString *sectionID = @"A very real section ID";
[[EngageBySailthru new] trackImpressionWithSession: sectionID, andUrls: urls, andResponse: ^(NSError *error) {
if (error) {
// Handle error case
} else {
// Things went right, hooray!
}
}];
// Alternatively, if we don't mind too much if the track request fails, use a nil block:
[[EngageBySailthru new] trackImpressionWithSession: sectionID, andUrls: urls, andResponse: nil]
let urls = [
URL("https://varickandvandam.com/products/1153128"),
URL("https://varickandvandam.com/products/1098230"),
URL("https://varickandvandam.com/products/1078590")
]
let sectionID = "a very real section ID"
EngageBySailthru().trackImpression(withSection: sectionID, andUrls: urls) { (errorOrNil) in
if let error = errorOrnil {
print(error)
return
}
// Track success! 🙌
}
// Alternatively, if we don't mind too much if the track request fails, just omit the block:
EngageBySailthru().trackImpression(withSection: sectionID, andUrls: urls)
ArrayList<URI> urls = new ArrayList(Arrays.asList(
URI.create("https://varickandvandam.com/products/1153128"),
URI.create("https://varickandvandam.com/products/1098230"),
URI.create("https://varickandvandam.com/products/1078590")
));
String sectionID = "a very real section ID";
new EngageBySailthru().trackImpression(sectionID, urls, new EngageBySailthru.TrackHandler() {
@Override
public void onSuccess() {
// We're good
}
@Override
public void onFailure(Error error) {
// Handle errors here
}
});
// Alternatively, if we don't mind too much if the track request fails, use a null handler:
new EngageBySailthru().trackImpression(sectionID, urls, null)
val tags = listOf(URI("https://varickandvandam.com/products/1153128"),
URI("https://varickandvandam.com/products/1098230"),
URI("https://varickandvandam.com/products/1078590"))
val sectionID = "a very real section ID"
EngageBySailthru().trackImpression(sectionID, tags, object : EngageBySailthru.TrackHandler {
override fun onSuccess() {
// We're good
}
override fun onFailure(error: Error?) {
// Handle errors here
}
})
// Alternatively, if we don't mind too much if the track request fails, use a null handler:
EngageBySailthru().trackImpression(sectionID, tags, null)
var urls = ["https://varickandvandam.com/products/1153128",
"https://varickandvandam.com/products/1098230",
"https://varickandvandam.com/products/1078590"]
var sectionID = "a very real section ID";
EngageBySailthru.trackImpression(sectionID, urls).then(function() {
// handle success
}, function(error) {
// handle error
});
// Alternatively, if we don't mind too much if the track request fails, omit then handler:
EngageBySailthru.trackImpression(sectionID, urls);
string sectionID = "A very real section ID";
string[] urls = {
"https://varickandvandam.com/products/1153128",
"https://varickandvandam.com/products/1098230",
"https://varickandvandam.com/products/1078590"
}
new EngageBySailthru().TrackImpression(sectionID, urls);
We recommend that you call trackImpression
as a recommendation section enters the user's viewport on their device. On Android, you might do this by attaching an OnChildAttachStateChangeListener to a RecyclerView, and placing a call to trackImpression
in the body of its onChildViewAttachedToWindow
method. On iOS, you might consider calling trackImpression
in the UITableViewDelegate
method tableView:willDisplayCell.
Tracking Clicks
A click should be tracked when a user clicks on an item present in a section of recommendations, passing the section ID as the first argument, and the URL of the item being navigated to as the second argument.
NSURL *url = [NSURL URLWithString:@"https://varickandvandam.com/products/1153128"];
NSString *sectionID = @"A very real section ID";
[[EngageBySailthru new] trackClickWithSession: sectionID, andUrl: url, andResponse: ^(NSError *error) {
if (error) {
// Handle error case
} else {
// Things went right, hooray!
}
}];
// Alternatively, if we don't mind too much if the track request fails, use a nil block:
[[EngageBySailthru new] trackClickWithSession: sectionID, andUrl: url, andResponse: nil]
let url = URL("https://varickandvandam.com/products/1153128")
let sectionID = "a very real section ID"
EngageBySailthru().trackClick(withSection: sectionID, andUrl: url) { (errorOrNil) in
if let error = errorOrnil {
print(error)
return
}
// Track success! 🙌
}
// Alternatively, if we don't mind too much if the track request fails, just omit the block:
EngageBySailthru().trackClick(withSection: sectionID, andUrl: url)
URI url = URI.create("https://varickandvandam.com/products/1078590");
String sectionID = "a very real section ID";
new EngageBySailthru().trackClick(sectionID, url, new EngageBySailthru.TrackHandler() {
@Override
public void onSuccess() {
// We're good
}
@Override
public void onFailure(Error error) {
// Handle errors here
}
});
// Alternatively, if we don't mind too much if the track request fails, use a null handler:
new EngageBySailthru().trackClick(sectionID, url, null)
val url = URI("https://varickandvandam.com/products/1078590")
val sectionID = "a very real section ID"
EngageBySailthru().trackClick(sectionID, url, object : EngageBySailthru.TrackHandler {
override fun onSuccess() {
// We're good
}
override fun onFailure(error: Error?) {
// Handle errors here
}
})
// Alternatively, if we don't mind too much if the track request fails, use a null handler:
EngageBySailthru().trackClick(sectionID, url, null)
var url = "https://varickandvandam.com/products/1078590";
var sectionID = "a very real section ID";
EngageBySailthru.trackClick(sectionID, url).then(function() {
// handle success
}, function(error) {
// handle error
});
// Alternatively, if we don't mind too much if the track request fails, omit then handler:
EngageBySailthru.trackClick(sectionID, urls);
string sectionID = "A very real section ID";
string url ="https://varickandvandam.com/products/1153128"
new EngageBySailthru().TrackClick(sectionID, url);
Updated 7 months ago