Retrieving Audiences
void Glimr.getTags( string clientId, function(array, object) callback )
Fetch all tags associated with the current browser client. The callback should accept 1 array and 1 object parameter. Depending on the version of the Glimr API used, the object parameter might be empty.
Glimr.getTags("YOUR_CLIENT_ID", function(tags, tagMappings) {
console.log("Tags for client:", tags);
console.log("... :", tagMappings);
});
Note
If you call
setTagCacheTimeInSeconds
the tags will be cached for that duration, and not make a network request until after the time. OtherwisegetTags
-call is cached for the duration of the page load and will be emptied on page load. Calling it multiple times will only result in one call to the Glimr servers.
.setTagCacheTimeInSeconds
number Glimr.setTagCacheTimeInSeconds( number desiredSecondsToCache )
number Glimr.getTagCacheTimeInSeconds( )
The tags from Glimr.getTags
can be cached for a duration of up to 5 minutes. The tags don't change too often so it's a good idea to limit network traffic on the client.
Glimr.setTagCacheTimeInSeconds(300);
// Max cache time is 5 minutes because otherwise you risk losing tags
// Passing anything > 300 will become 300
Glimr.setTagCacheTimeInSeconds(600);
console.log(Glimr.getTagCacheTimeInSeconds());
// ... 300
.getCachedURLTags
array Glimr.getCachedURLTags( string clientId )
Glimr crawls your web property and knows which URL indicates a set of tags, based on filters you setup in the dashboard. The Glimr SDK can download and cache this database in an efficiant manner, and you can use it to get tags without having to make a network request. To fetch the tags associated with the current browser URL you call Glimr.getCachedURLTags
which does a fast synchronous lookup.
var tags = Glimr.getCachedURLTags("YOUR_CLIENT_ID");
console.log("Cached tags", tags);
Note: This method used to be called .getCachedTags
. For backwards compatibility it will exist until the next major release.
.getCachedBehaviorTags
array Glimr.getCachedBehaviorTags( string clientId ): Array | boolean
If Glimr.setTagCacheTimeInSeconds
has been called this method can be used to peek into the cache without calling Glimr.getTags
. If the cache is still valid, an array will be returned, otherwise false
.
Note: This returns a different class of tags than Glimr.getCachedURLTags
. Behavior tags are based on the user and not the current web URL.
var tags = Glimr.getCachedBehaviorTags("YOUR_CLIENT_ID");
console.log("Cached tags", tags);
.getCachedBehaviorTagsAndUpdateInBackground
array Glimr.getCachedBehaviorTagsAndUpdateInBackground( string clientId, options: { onUpdate: (tags: Array) => void}): Array<string>
For some implementors tags need to be used in a synchronous manner, but still need to be updated when possible. Also invalidated tags should still be used. This method works for that use case.
Glimr.setTagCacheTimeInSeconds(300);
var tags = Glimr.getCachedBehaviorTagsAndUpdateInBackground("YOUR_CLIENT_ID");
An optional options object can be passed in with an onUpdate
callback that is passed as a callback to the Glimr.getTags
call
Glimr.setTagCacheTimeInSeconds(300);
var oldTags = Glimr.getCachedBehaviorTagsAndUpdateInBackground("YOUR_CLIENT_ID", {
onUpdate: function(newTags) {
console.log("tags are updated. New tags", newTags);
}
});
Updated less than a minute ago