Datazoom is a high-availability real-time data collection solution. This document summarizes how to integrate the iOS Media Player with the Datazoom platform.
- Login to Datazoom here: https://app.datazoom.io
- Add a Collector as indicated here: How to add a Collector
- Copy the
config key
that was created at the end of the process
Click the icon indicated below to copy the Configuration Key
You will see this message:
4. Replace the <configuration id from Datazoom>
in Datazoom's DZNativeCollector.framework
file with the Key you copied above.
5. Replace the <url given by Datazoom>
with <https://platform.datazoom.io/beacon/v1/>
6. Replace the <AVPlayer Object>
with your playerInstance
identifier
Initial setup
Using XCFramework
Download
DZ_Collector_iOS.xcframework
file from here.Drag and drop the downloaded frameworks into your Xcode project. Drag the file to the files inspector on the left side of Xcode. Make sure you check the box "Copy items" in the popup menu that displays while drag and drop the file.
In selected Xcode target, go to the General tab and scroll down to Frameworks, Libraries and Embedded Content (Embedded Binaries in older Xcode versions). Make sure that the framework added in the above step is present. If not present, add the framework by clicking the "+" button available at the same section. Also, make sure that Embed option is set to Embed & Sign.
Using Swift Package Manager
In your code project select File > Add Packages and in
Search or Enter URL
field enter:
https://gitlab.com/datazoom/apple-ios-mobile/dzcollectorios-spm
Set dependency rule to
Branch
main
and specify name of your project.
On the next screen,
Choose package products
, make sure thatDZ_Collector_iOS
is selected and click onAdd package
.
Using Cocoapods
Open the terminal and check if Cocoapods is installed in your machine.
pod --version
If the above command returns no version number, then you'll need to install CocoaPods.
sudo gem install cocoapods
After installation, navigate to the Xcode project directory and create a
Podfile
configuration file if not present.pod init
Run the command:
open Podfile
Add the
DZNativeGold
pod in thePodfile
pod 'DZNativeGold','0.3.1',:source=>'https://gitlab.com/datazoom/pod-specs.git'
Pull and update the latest Cocoapods pod specs
pod repo update
Install the pods
pod install
Be sure to close any current Xcode sessions and use `your_project_name.xcworkspace` for this project from now on.
Steps for Swift Language based Applications
After including the framework file, open the ViewController/View file, where the AVPlayer(native player) is included.
Import the framework using the following command:
import DZ_Collector_iOS
Initialize the framework by passing along the 'Configuration ID', and URL given by Datazoom. Completion handler will return two values, success and error if happened.
let collector = DZ_Collector(configID: <configuration id from Datazoom>, url: "https://platform.datazoom.io") collector.start(completion: @escaping (Bool, Error?) -> ())
You can start recording events for your AVPlayer instance using this API call.
collector.startRecordingEvents(for: <AVPlayer object>)
You can also stop recording events of your AVPlayer instance using similar API call.
collector.stopRecordingEvents(for: <AVPlayer object>)
To stop recording event for ALL active AVPlayer instances use:
collector.stopRecordingEvents()
Run the app and observe the events captured in a Collector, data corresponding to MOBILE/iPhone in Platform, refers to the events tracked from iPhone.
Steps for ObjectiveC Language based Applications
After including the framework file, Create a bridging header file, to allow interoperability of languages.
open the ViewController/View file, where the AVPlayer(native player) is included.
Import the following:
#import <AVKit/AVKit.h> #import <AVFoundation/AVFoundation.h> @import DZ_Collector_iOS;
Initialize the swift class in the .h file.
DZ_Collector *collector;
In the .m file, allocate using:
collector = [[DZ_Collector alloc]initWithConfigId: <configuration id from Datazoom>, url: <>]; [collector startWithCompletion: ^(BOOL result, NSError *error) { ... }];
You can start recording events for your AVPlayer instance using this API call.
[collector startRecordingEventsFor: <AVPlayer* object>];
You can also stop recording events of your AVPlayer instance using similar API call.
[collector stopRecordingEventsFor: <AVPlayer* object>];
Run the app and observe the events captured in a Collector, data corresponding to MOBILE/iPhone in Platform, refers to the events tracked from iPhone.
Custom Events & Metadata
Datazoom allows customers to collect custom events and metadata that aren't emitted from the video player.
Custom Metadata
Create an NSDictionary with necessary metadata
let metaData = ["customMetadata":"MetadataValue"]
Add the metadata to DZEventCollector
collector.addCustom(metadata: metadata)
Example:func sendCustomMetadata(){ collector.addCustomMetadata(metadata: ["customPlayerName": "iOS Native Player"]) }
In Objective-C:
NSDictionary *metadata = @{@"customMetadata": @"MetadataValue"}; [collector addCustomWithMetadata:metadata];
Custom Events
Send Events like below:
collector.addCustomEvent(event: "custom_event_name", metadata: metadata|nil)
Example:@objc func buttonPushTouched() { collector.customEvents("buttonClick", metadata:["customPlayerName":"NativeiOSPlayer","customDomainName":"datazoom.io"]) }
In Objective-C:
[collector addCustomWithEvent:@"CustomEventName" metadata: metadata];
Comments
0 comments
Article is closed for comments.