VisitorServiceモジュール
使用方法
VisitorServiceモジュールは、Tealium Customer Data Hubのデータレイヤーエンリッチメント機能を実装します。
Tealium AudienceStreamのライセンスがある場合に、訪問者プロファイルを使用してモバイルアプリケーションのユーザーエクスペリエンスを強化するには、このモジュールを使用することをお勧めします。AudienceStreamのライセンスがない場合は、訪問者プロファイルが返されないため、このモジュールを使用することは推奨されません。
以下のプラットフォームがサポートされています。
- iOS
- tvOS
- watchOS
- macOS
インストール
VisitorServiceモジュールをCocoaPodsまたはCarthageによってインストールします。
CocoaPods
VisitorServiceモジュールをCocoaPodsによってインストールするには、Podfileに以下のポッドを追加します。
pod 'tealium-swift/TealiumCore'
pod 'tealium-swift/TealiumCollect' //or 'tealium-swift/TealiumTagManagement'
pod 'tealium-swift/TealiumVisitorService'
フレームワークは自動でインスタンス化され、TealiumCore
ポッドに加え、ディスパッチサービスポッドのうちの1つ(TealiumCollect
またはTealiumTagManagement
)に依存しています。iOS向けCocoaPodsのインストールの詳細については、こちらを参照してください。
Carthage
VisitorServiceモジュールをCarthageによってインストールするには、以下の手順に従います。
Xcodeで対象アプリの[General]構成ページに移動します。
以下のフレームワークを[Embedded Binaries]セクションに追加します。
TealiumVisitorService.framework
VisitorServiceモジュールを設定するには、次の必須のインポートステートメントをプロジェクトに追加します。
import TealiumCore import TealiumCollect //or import TealiumTagManagement import TealiumVisitorService
フレームワークは自動でインスタンス化され、TealiumCore
に加え、少なくとも1つのディスパッチサービス(TealiumCore
またはTealiumTagManagement
)に依存しています。追加のインポートステートメントは必要ありません。
iOS向けCarthageのインストールの詳細については、こちらを参照してください。
訪問者データオブジェクト
訪問者プロファイルは、各属性タイプのネイティブ構造体を格納するオブジェクトです。訪問者プロファイルオブジェクト内には、訪問者/訪問属性タイプの区別を可能にするcurrentVisit
プロパティがあります。オーディエンスを除き、各属性値には、サブスクリプトを使用してIDでアクセスできます。訪問者がサブスクリプトで照会されたオーディエンスのメンバーである場合、audiences
属性はtrue
/false
を単に返します。例については、下記のリストを参照してください。
属性タイプ
パラメータ | プロパティ | 値 |
---|---|---|
arraysOfBooleans |
id: String, value: [Bool] | id: "5129", value: [true,false,true,true] |
arraysOfNumbers |
id: String, value: [Double] | id: "57", value: [4.82125, 16.8, 0.5714285714285714] |
arraysOfStrings |
id: String, value: [String] | id: "5213", value: ["green shirts", "green shirts", "blue shirts"] |
audiences |
id: String, name: String | id: "tealiummobile\_demo\_103", name: "iOS Users" |
badges |
id: String, value: Bool | id: "2815", value: true |
booleans |
id: String, value: Bool | id: "4868", value: true |
currentVisit |
現在の訪問プロファイルのすべての属性。現在の訪問プロファイルにはオーディエンスまたはバッジは格納されません。 | TealiumCurrentVisitProfile(dates: [DateTime(id: "5376", value: 1567536668080), DateTime(id: "10", value: 1567536668000)], booleans: [Boolean(id: "4530", value: true], numbers: [Number(id: "32", value: 3.8)]) |
dates |
id: String, value: Int | id: "22", value: 1567120112000 |
numbers |
id: String, value: Double | id: "5728", value: 4.82125 |
setOfStrings |
id: String, value: Set[String] | id: "5211", value: ["green shirts", "red shirts", "blue shirts"] |
strings |
id: String, value: String | id: "5380", value: "green shirts" |
tallies |
id: String, value: [TallyValue] | id: "57", [[key: "category 1" count: 2.0], key: "category 2", count: 1.0]] |
tallyValue |
key: String, count: Double | [key: "category 1" count: 2.0] |
arraysOfBooleans
カスタムのサブスクリプトにより、ブール値の配列をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.arraysOfBooleans |
訪問者プロファイルのブール値のすべての配列を返します。 | [BooleanArray] |
[BooleanArray(id: "2333", value: [true,false]), BooleanArray(id: "1123", value: [true,true])] |
profile.arraysOfBooleans["2815"] |
IDによるブール値の配列を返します。 | [Bool] |
true |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return an array of booleans value
if let arraysOfBooleans = profile.arraysOfBooleans?["5279"] {
let numberOfPositiveBools = arraysOfBooleans.map { $0 == true }.count
print(numberOfPositiveBools)
}
}
arraysOfNumbers
カスタムのサブスクリプトにより、数値の配列をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.arraysOfNumbers |
訪問者プロファイルの数値のすべての配列を返します。 | [NumberArray] |
[NumberArray(id: "2333", value: [2.0, 1.0]), NumberArray(id: "1123", value: [4.82125, 3.0])] |
profile.arraysOfNumbers["2815"] |
IDによる数値の配列を返します。 | [Double] |
[4.82125, 3.0] |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return an array of numbers value
if let arraysOfNumbers = profile. arraysOfNumbers?["5279"] {
arraysOfNumbers.forEach { number in
if number > 3.0 {
// ... take action
}
}
}
}
arraysOfStrings
カスタムのサブスクリプトにより、文字列値の配列をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.arraysOfStrings |
訪問者プロファイルの文字列のすべての配列を返します。 | [StringArray] |
[StringArray(id: "1033", value: ["Foundation", "Perfume"), StringArray(id: "3390", value: ["Bootleg Jeans", "Dresses"])] |
profile.arraysOfStrings["3390"] |
IDによる文字列の配列を返します。 | [String] |
["Bootleg Jeans", "Dresses"] |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return an array of strings value
if let arraysOfStrings = profile.arraysOfStrings?["3390"] {
arraysOfStrings.forEach { string in
if string.lowercased().contains("Jeans") {
// ... take action
}
}
}
}
audiences
カスタムサブスクリプトにより、訪問者のオーディエンスメンバーシップをオーディエンスIDとオーディエンス名で確認できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.audiences |
訪問者がメンバーとなっているすべてのオーディエンスを返します。 | [Audience] |
[Audience(id: "tealiummobile\_demo\_103", name: "iOS Users"), Audience(id: "tealiummobile\_demo\_110", name: "Visitors - Known")] |
profile.audiences[id: "103"] |
渡されたIDに基づいて、訪問者がオーディエンスのメンバーであるかどうかに応じてtrue/falseを返します。 | Bool |
true |
profile.audiences[name: "ios users"] |
渡された名前に基づいて、訪問者がオーディエンスのメンバーであるかどうかに応じてtrue/falseを返します。名前では大文字と小文字が区別されません。 | Bool |
false |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return the current Audiences for which the user is assigned
if let currentVisitorAudiences = profile.audiences {
print("Visitor audiences: \(currentVisitorAudiences)")
// Check if an Audience is assigned to a user by id
if currentVisitorAudiences[id: "106"] {
print("Visitor is a member of audience id 106")
// ... Visitor is a member of this audience, take appropriate action
}
// Check if an Audience is assigned to a user by name
if currentVisitorAudiences[name: "ios users"] {
print("Visitor is a member of audience iOS Users")
// ... Visitor is a member of this audience, take appropriate action
}
}
}
badges
カスタムのサブスクリプトにより、バッジの値をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.badges |
訪問者プロファイルのすべてのバッジを返します。 | [Badge] |
[Badge(id: "2815", value: true), Badge(id: "2813", value: false)] |
profile.badges["2815"] |
訪問者にバッジが割り当てられているかどうかに応じてtrue/falseを返します。 | Bool |
true |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return a badge value
if let badgeAssigned = profile.badges?["5279"] {
print(badgeAssigned ? "Badge id 5279 is assigned" : "Badge id 5945 is not assigned")
}
}
booleans
カスタムのサブスクリプトにより、ブール値をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.booleans |
訪問者プロファイルのすべてのブール値を返します。 | [Boolean] |
[Boolean(id: "5784", value: true), Boolean(id: "1453", value: false)] |
profile.booleans["4692"] |
IDによるブール値を返します。 | Bool |
true |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return a boolean value
if let booleanValue = profile. booleans?["4479"] {
if booleanValue {
// ... do something
}
}
}
currentVisit
訪問者の生涯属性ではなく、現在の訪問の属性にアクセスします。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile. currentVisit |
現在の訪問をスコープとした属性を返します。 | TealiumCurrentVisitProfile |
TealiumCurrentVisitProfile(dates: [DateTime(id: "5376", value: 1567536668080), DateTime(id: "10", value: 1567536668000)], booleans: [Boolean(id: "4530", value: true], numbers: [Number(id: "32", value: 3.8)]) |
profile. currentVisit.### |
目的の属性を次の値に応じて返します。###.前述と同じすべてのメソッドが適用されます。ただし、オーディエンスとバッジは例外です。これらは訪問者限定の属性であり、訪問には適用されません。 | 不定 | 不定 |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return a current visit string attribute
if let currentVisit = profile.currentVisit,
let string = currentVisit.strings?["34"] {
print(string)
// ... take action
}
}
dates
カスタムのサブスクリプトにより、日付の値をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.dates |
訪問者プロファイルのすべての日付を返します。 | [DateTime] |
[DateTime(id: "22", value: 1567120112000), DateTime(id: "13", value: 1567120113245)] |
profile.dates["4692"] |
IDによる日付を返します。 | Int |
1567120112000 |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return a date value
if let date = profile.dates?["33"] {
print(date)
// .. take action
}
}
numbers
カスタムのサブスクリプトにより、数値をIDで照会できます。
Usege | 説明 | 型 | 例 |
---|---|---|---|
profile.numbers |
訪問者プロファイルのすべての数値を返します。 | [Number] |
[Number(id: "83", value: 0.5714285714285714), Number(id: "1399", value: 2.0)] |
profile.numbers["1399"] |
IDによる数値を返します。 | Double |
4.82125 |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return a number value
if let number = profile. numbers?["1399"] {
if number > 3.0 {
// ... take action
}
}
}
setsOfStrings
カスタムのサブスクリプトにより、文字列値のセットをIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.setsOfStrings |
訪問者プロファイルの文字列のすべてのセットを返します。 | [SetOfStrings] |
[SetOfStrings(id: "9938", value: ["shirts"]), SetOfStrings(id: "2300", value: ["Luxury Couch 1", "Luxury Couch 2"])] |
profile.setsOfStrings["2300"] |
IDによる文字列のセットを返します。 | Set<String> |
["Luxury Couch 1", "Luxury Couch 2"] |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return an set of strings value
if let setOfStrings = profile.setsOfStrings?["5279"] {
if setOfStrings.contains("toys") {
// ... take action
}
}
}
strings
カスタムのサブスクリプトにより、文字列値をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.strings |
訪問者プロファイルのすべての文字列を返します。 | [VisitorString] |
[Number(id: "83", value: "Toy Truck"), Number(id: "5699", value: "Toy Tea Set")] |
profile.strings["5699"] |
IDによる文字列を返します。 | String |
"Toy Tea Set" |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return a string value
if let string = profile.strings?["5699"] {
print(string)
// ... take action
}
}
tallies
およびtallyValue
カスタムのサブスクリプトにより、集計と集計値をIDで照会できます。
Usage | 説明 | 型 | 例 |
---|---|---|---|
profile.tallies |
訪問者プロファイルのすべての集計を返します。 | [Tally] |
[Tally(id: "2983", value: [TallyValue(key: "red shirts category", count: 4.0), TallyValue(key: "green shirts category", count: 2.0)]), Tally(id: "5643", value: [TallyValue(key: "girls", count: 3.0), TallyValue(key: "womens", count: 1.0)] ] |
profile.tallies[tally: "1399"] |
IDによる集計を返します。 | [TallyValue] |
[TallyValue(key: "girls", count: 3.0), TallyValue(key: "womens", count: 1.0)] |
profile.tallies[tally: "1399", key: "womens"] |
IDによる集計を返します。 | Double |
3.0 |
使用方法の例:
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// Return an entire tally
if let tally = profile.tallies?["1399"] {
print("Tally id 5377: \(tally)")
}
// Return a tally value by using the tally id and the key for the value desired
if let tallyValue = profile.tallies?[tally: "5381", key: "red shirts"]{
print("Tally value for id 5381 and key 'red shirts': \(tallyValue)")
}
}
APIリファレンス
クラスTealium
以下のAPIメソッドは、更新された訪問者プロファイルの操作に使用できます。
visitorService()
使用方法の例:
class MyHelperClass {
var tealium: Tealium?
public init () {
let config = TealiumConfig(account: "ACCOUNT",
profile: "PROFILE",
environment: "ENVIRONMENT",
datasource: "DATASOURCE",
optionalData: nil)
config.addVisitorServiceDelegate(self)
config.setVisitorServiceRefresh(interval: 10)
self.tealium = Tealium(config) {
// Note: this is inside the completion block after initialization
// self.tealium is guaranteed to be initialized inside the completion block
self.tealium?.visitorService()?.#### // where #### is any public API method on the visitorProfile object - see other methods for examples
}
}
}
requestVisitorProfile()
このメソッドは、現在のプロファイルを取得するためのVisitorServiceへの即時リクエストをトリガーします。プロファイルが前回のフェッチ以降に更新されている場合は、profileDidUpdate
デリゲートメソッドが呼び出されます。
このメソッドは、訪問者プロファイルの更新間隔が0
に設定されている場合、トラッキングリクエストが送信されるたびに自動的に呼び出されます。これよりも高い値を更新間隔に設定している場合は、このメソッドを呼び出して、スケジュールされた次回の更新を待たずにプロファイルをただちに取得できます。
self.tealium?.visitorService()?.requestVisitorProfile()
使用方法の例:
func track(title: String, data: [String: Any]?) {
tealium?.track(title: title, data: data, completion: { success, \_, error in
if error != nil {
print("*** Track not completed because of error: \n\(String(describing: error))")
}
if success {
print("*** Track with VisitorService completed ***")
self.tealium?.visitorProfile()?.requestVisitorProfile()
}
})
}
getCachedProfile()
新しいリクエストをトリガーすることなく、永続的ストレージから最後に取得した訪問者プロファイルを返します。インターネットに接続されていないが、以前のリクエストが正常に完了している状況で役立ちます。
例:
self.tealium?.visitorService()?.getCachedProfile(completion: { profile in
guard let profile = profile else { return }
if let json = try? JSONEncoder().encode(profile), let string = String(data: json, encoding: .utf8) {
print(string)
}
})
パラメータ | 説明 | 値の例 |
---|---|---|
completion: TealiumVisitorProfile? |
removeAllVisitorServiceDelegates()
すべての訪問者プロファイルデリゲートを削除します。
self.tealium?.visitorService()?.removeAllVisitorServiceDelegates()
addVisitorServiceDelegate()
VisitorServiceDelegate
に準拠する新しいクラスを追加します
self.tealium?.visitorService()?.addVisitorServiceDelegate(self)
パラメータ | 説明 | 例 |
---|---|---|
delegate: Class conforming to VisitorServiceDelegate |
ViewController, TealiumHelper |
removeSingleDelegate()
特定の訪問者プロファイルデリゲートを削除します。
例:
self.tealium?.visitorService()?.removeSingleDelegate(self)
パラメータ | 説明 | 値の例 |
---|---|---|
delegate: Class conforming to VisitorServiceDelegate |
ViewController, TealiumHelper |
クラス:TealiumVisitorServiceDelegate
profileDidUpdate()
このメソッドは、訪問者プロファイルが更新されるたびに呼び出されます。ほとんどの場合、requestVisitorProfile()
メソッドが使用されるたびに呼び出されます。
func profileDidUpdate(profile: TealiumVisitorProfile?) {
guard let profile = profile else { return }
// act on profile attributes
print(profile.audiences)
...
}
クラス:TealiumConfig
setVisitorServiceRefresh()
これにより、訪問者プロファイルの取得頻度を設定できます。この設定のデフォルト値は5分です。このメソッドは、頻度を調整するために使用します。requestVisitorProfile
メソッドをすべてのトラッキングコールに追加しても、このメソッドを0に設定しない限り、プロファイルは毎回取得されません。
let config = TealiumConfig(...)
config.setVisitorServiceRefresh(3)
パラメータ | 説明 | 例 |
---|---|---|
interval | 訪問者プロファイルを取得する頻度。整数、分。(デフォルト:5 ) |
3 |
addVisitorServiceDelegate()
config.addVisitorServiceDelegate(self)
profileDidUpdate
デリゲートメソッドを使用するには、デリゲートをVisitorServiceデリゲートの配列に追加します。デリゲートとして割り当てられた複数のオブジェクトが存在する可能性があります。
パラメータ | 説明 | 例 |
---|---|---|
class responsible for the profile updates (delegate) | ViewController, TealiumHelper |
getVisitorServiceDelegates()
VisitorServiceモジュールに割り当てられたデリゲートのリストを返します。
config.getVisitorServiceDelegates()
setVisitorServiceOverrideProfile()
訪問者プロファイルの取得元プロファイルをオーバーライドします。Collectモジュールでデータ収集に使用されているプロファイルと整合する必要があります。
config. setVisitorServiceOverrideProfile("PROFILE")
setVisitorServiceOverrideURL()
config. setVisitorServiceOverrideURL("https://overridden-subdomain.yourdomain.com/")
訪問者プロファイルの取得元ベースURLをオーバーライドします。アカウント、プロファイル、および訪問者IDがURLに自動的に追加されます。
リリースノート
- 8.0
- 最初のリリース