Segmentation targeting with StorifyMe
In case you want your widget to be dynamic and to show different stories to different audiences you would need to add tags into the script. Once StorifyMe receives the demographic you want to show stories to, it will only show the stories within a widget that match the tags for that demographic.
Setup segments
In the following example we will create a segment for stories with tags of ["featured", "sport"].
You need to have the working StorifyMe setup as described in Initial SDK Setup
Set your tags in the StorifyMe platform
When publishing story in the StorifyMe platform, you will find an option named "Story tags". There you should set your tags (for example "featured", "sport") and we will only show those stories that have one (or more) of the defined tags.
Set your tags in the StorifyMe SDK
In order to show stories with specific tags, you need to configure them in the SDK itself. You can do that by using the following methods to update the widget configuration and add it to the storifyMeWidget:
var widgetConf = StorifyMeWidgetConfig()
widgetConf.setSegments(tags: ["featured", "sport"])
let storifyMeWidget = StorifyMeWidget()
storifyMeWidget.setWidgetConfig(config: widgetConf)
storifyMeWidget.setWidgetId(widgetId: WIDGET_ID)
storifyMeWidget.load()
Once the widget is loaded, we will show stories with the tags defined in this method.
Exclude specific tags from story display
To prevent stories containing certain tags from appearing in the widget, you can utilize the following method:
var widgetConf = StorifyMeWidgetConfig()
widgetConf.setExceptSegments(tags: ["sponsored", "ad"])
...
After the widget loads, stories with the tags specified in this method will be excluded from display.
Example usage
- If you do not give any parameters to segments, StorifyMe SDK will show all stories with/without tags that belong to this widget. This is the default behavior.
- If you set tags, StorifyMe SDK will show the stories that have one or more of the defined tags. For example, if you set segments
['featured', 'sport'], StorifyMe SDK will show all stories that belong to this widget and have eitherfeaturedorsporttag (or have both tags).
Set query parameters to any story
In order to send custom query parameters with every story, you can add them in the following way to your storifyMeWidget:
var conf = StorifyMeWidgetConfig()
conf.setQueryParameter(name: "cid", value: "1")
let storifyMeWidget = StorifyMeWidget()
storifyMeWidget.setWidgetConfig(config: widgetConf)
storifyMeWidget.setWidgetId(widgetId: WIDGET_ID)
storifyMeWidget.load()
All widget configuration (segments, excluded segments, and query parameters) must be set before calling the storifyMeWidget.load() method. Configuration changes made after the widget is loaded will not take effect.
Get server segments
After the widget has finished loading, you can retrieve the segments (tags) that were configured in the StorifyMe editor for that specific widget:
let serverSegments = storifyMeWidget.getServerSegments()
This method returns an array of segment tags as they are defined in the StorifyMe platform editor. Unlike the setSegments() method which configures client-side filtering, getServerSegments() retrieves the actual segments assigned to the widget on the server.
Call this method after the widget has successfully loaded to access the server-defined segments. This is useful for making dynamic content adjustments based on the widget's configured segments.