Sie sind auf Seite 1von 3

Chartbeat iOS SDK Implementation Instructions

To get started tracking your iOS app, be sure to download the 64-bit iOS SDK from our Mobile
Implementation page.

Two Things You Need


YOUR CHARTBEAT ACCOUNT ID

YOUR HOST DOMAIN

Your account ID should match the UID


included in the Chartbeat code, which has
been embedded on your website.

The host domain should match the domain


name you currently use for Chartbeat, e.g.
yoursite.com.

Installing Chartbeat SDK


1

Download the Chartbeat SDK


After downloading the iOS SDK, unzip it locally and drag the CBTracker.h and libChartbeat-iOSSDK.a into your Xcode project.

Getting Started
1

In your UIApplicationDelegate implementation file (.m) import CBTracker.h: #import


"CBTracker.h"

In the applicationDidBecomeActive method set your configuration variables:


startTrackerWithAccountID: the integer value of your Chartbeat account ID.
setDomain: a string of the domain that youre tracking with Chartbeat. If your desktop site is
tracked in Chartbeat as yoursite.com, we recommend you input setDomain to yoursite.com.
However, your app data can be sent to a separate dashboard if you prefer.
Your code should look similar to:

[[CBTracker sharedTracker] startTrackerWithAccountID:#####];


[[CBTracker sharedTracker] setDomain:@"yoursite.com"];

Tracking Views
Each view controller must import CBTracker.h and set authors/sections/zones on the shared
pinger instance, and call trackView.
When the app switches into a new view, you must call set authors, sections, and zones for the
new content. Then, call trackView for the new view and set a viewID and title.
You typically want to do this when the view is visible to the user. These methods should be
called in the `viewDidAppear` method.
Call setAuthors, setSections and setZones for the new view.

Each of these should be arrays of strings and refer specifically to the new view. If any of these
do not apply, just set to an empty array.
Authors and sections can take an array with multiple string elements, each of which will show up
as an author/section for that view. Note that there can only be one zone for a view.
Call trackView.

trackView: Refers to the new view, should be set to self.view.


viewId: A unique string introduced with slash, similar to a relative path on a website.
title: A string that specifies the content in the view, such as an article title.
Your code should look similar to:

[[CBTracker sharedTracker] setAuthors:@[@"John Smith", @"Jane Doe"]];


[[CBTracker sharedTracker] setSections:@[@"news", @
[[CBTracker sharedTracker] setZones:@[@yoursite/
[[CBTracker sharedTracker] trackView:self.view
viewId:@"/article/date/brandnewdriverlesscars" title:@"Driverless cars
will overpower humanity"];

Tracking Video
1

When a user clicks to play a video from a given view, you also need to call trackMedia with the
following arguments:
title: A string for the video being tracked.
thumbnail: A string that identifies a URL for a thumbnail. Chartbeat will only be
able to display web-hosted thumbnails.
Your code should look similar to:
(IBAction)onVideoPlayClick:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://media.w3.org/2010/05/sintel/
trailer.mp4"];
moviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
moviePlayer.moviePlayer.shouldAutoplay = NO;
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[[CBTracker sharedTracker] trackMedia:moviePlayer.moviePlayer title:@"Your
video title thumbnail:@http://www.yoursite.com/media/img123.jpg"];
}

Seeing your Data


To see your data, load up your app and head to the Chartbeat Publishing dashboard for the
domain you set with setDomain (e.g. internet.com). If the domain does not show in the list, head
to https://chartbeat.com/publishing/setup/code or contact support@chartbeat.com.

Got stuck along the way? No worries. Were happy to help.

SUPPORT@CHARTBEAT.COM

Das könnte Ihnen auch gefallen