mixpanel-swift/docs/docsets/Mixpanel.docset/Contents/Resources/Documents/index.html
2022-02-03 11:31:22 -08:00

296 lines
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Mixpanel Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>
<a title="Mixpanel Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">Mixpanel 3.1.3 Docs</a> (84% documented)</p>
<p class="header-right"><a href="https://github.com/mixpanel/mixpanel-swift"><img src="img/gh.png"/>View on GitHub</a></p>
<p class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html">Mixpanel Reference</a>
<img id="carat" src="img/carat.png" />
Mixpanel Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Classes/Group.html">Group</a>
</li>
<li class="nav-group-task">
<a href="Classes/Mixpanel.html">Mixpanel</a>
</li>
<li class="nav-group-task">
<a href="Classes/MixpanelInstance.html">MixpanelInstance</a>
</li>
<li class="nav-group-task">
<a href="Classes/People.html">People</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Extensions/Array.html">Array</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Bool.html">Bool</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Date.html">Date</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Dictionary.html">Dictionary</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Double.html">Double</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Float.html">Float</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Int.html">Int</a>
</li>
<li class="nav-group-task">
<a href="Extensions/NSArray.html">NSArray</a>
</li>
<li class="nav-group-task">
<a href="Extensions/NSNull.html">NSNull</a>
</li>
<li class="nav-group-task">
<a href="Extensions/NSNumber.html">NSNumber</a>
</li>
<li class="nav-group-task">
<a href="Extensions/NSString.html">NSString</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Optional.html">Optional</a>
</li>
<li class="nav-group-task">
<a href="Extensions/String.html">String</a>
</li>
<li class="nav-group-task">
<a href="Extensions/UInt.html">UInt</a>
</li>
<li class="nav-group-task">
<a href="Extensions/URL.html">URL</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Protocols/MixpanelDelegate.html">MixpanelDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/MixpanelType.html">MixpanelType</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Typealiases.html">Type Aliases</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Typealiases.html#/s:8Mixpanel10Propertiesa">Properties</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<p align="center">
<img src="https://github.com/mixpanel/mixpanel-android/blob/assets/mixpanel.png?raw=true" alt="Mixpanel Swift Library" height="150"/>
</p>
<p><a href="http://isitmaintained.com/project/mixpanel/mixpanel-swift" title="Average time to resolve an issue"><img src="http://isitmaintained.com/badge/resolution/mixpanel/mixpanel-swift.svg" alt="Average time to resolve an issue"></a>
<a href="http://isitmaintained.com/project/mixpanel/mixpanel-swift" title="Percentage of issues still open"><img src="http://isitmaintained.com/badge/open/mixpanel/mixpanel-swift.svg" alt="Percentage of issues still open"></a>
<a href="https://mixpanel.com"><img src="http://img.shields.io/cocoapods/v/Mixpanel-swift.svg" alt="CocoaPods Compatible"></a>
<a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg" alt="Carthage compatible"></a>
<a href="https://github.com/apple/swift-package-manager"><img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg" alt="Swift Package Manager compatible"></a>
<a href="https://mixpanel.com"><img src="http://img.shields.io/cocoapods/l/Mixpanel-swift.svg" alt="Apache License"></a>
<a href="https://mixpanel.github.io/mixpanel-swift"><img src="https://mixpanel.github.io/mixpanel-swift/badge.svg" alt="Documentation"></a></p>
<h1 id='table-of-contents' class='heading'>Table of Contents</h1>
<!-- MarkdownTOC -->
<ul>
<li><a href="#overview">Overview</a></li>
<li><a href="#quick-start-guide">Quick Start Guide</a>
<ul>
<li><a href="#1-install-mixpanel">Install Mixpanel</a></li>
<li><a href="#2-initialize-mixpanel">Initialize Mixpanel</a></li>
<li><a href="#3-send-data">Send Data</a></li>
<li><a href="#4-check-for-success">Check for Success</a></li>
<li><a href="#complete-code-example">Complete Code Example</a></li>
</ul></li>
<li><a href="#faq">FAQ</a></li>
<li><a href="#i-want-to-know-more">I want to know more!</a></li>
</ul>
<!-- /MarkdownTOC -->
<p><a name="introduction"></a></p>
<h1 id='overview' class='heading'>Overview</h1>
<p>Welcome to the official Mixpanel Swift Library</p>
<p>The Mixpanel Swift library for iOS is an open-source project, and we&rsquo;d love to see your contributions!
We&rsquo;d also love for you to come and work with us! Check out <strong><a href="https://mixpanel.com/jobs/#openings">Jobs</a></strong> for details.</p>
<p>If you are using Objective-C, we recommend using our <strong><a href="https://github.com/mixpanel/mixpanel-iphone">Objective-C Library</a></strong>.</p>
<p>Check out our <a href="swift">Advanced iOS Swift Guide</a> for additional advanced configurations and use cases, like setting up your project with European Union data storage.</p>
<h1 id='quick-start-guide' class='heading'>Quick Start Guide</h1>
<p>Our master branch and our releases are on Swift 5. If you wish to use our Swift 4.2 implementation, please point to the v2.6.1 release. For Swift 4/4.1 implementation, please point to the v2.4.5 release. For Swift 3 implementation, please point to the v2.2.3 release.</p>
<h2 id='1-install-mixpanel' class='heading'>1. Install Mixpanel</h2>
<p>You will need your project token for initializing your library. You can get your project token from <a href="https://mixpanel.com/settings/project">project settings</a>.</p>
<h3 id='installation-option-1-swift-package-manager-v2-8-0' class='heading'>Installation Option 1: Swift Package Manager (v2.8.0+)</h3>
<p>The easiest way to get Mixpanel into your iOS project is to use Swift Package Manager.</p>
<ol>
<li>In Xcode, select File &gt; Add Packages&hellip;</li>
<li>Enter the package URL for this repository <a href="https://github.com/mixpanel/mixpanel-swift">Mixpanel Swift library</a>.</li>
</ol>
<h3 id='installation-option-2-cocoapods' class='heading'>Installation Option 2: CocoaPods</h3>
<ol>
<li>If this is your first time using CocoaPods, Install CocoaPods using <code>gem install cocoapods</code>. Otherwise, continue to Step 3.</li>
<li>Run <code>pod setup</code> to create a local CocoaPods spec mirror.</li>
<li>Create a Podfile in your Xcode project directory by running <code>pod init</code> in your terminal, edit the Podfile generated, and add the following line: <code>pod &#39;Mixpanel-swift&#39;</code>.</li>
<li>Run <code>pod install</code> in your Xcode project directory. CocoaPods should download and install the Mixpanel library, and create a new Xcode workspace. Open up this workspace in Xcode or typing <code>open *.xcworkspace</code> in your terminal.</li>
</ol>
<h3 id='installation-option-3-carthage' class='heading'>Installation Option 3: Carthage</h3>
<p>Mixpanel supports Carthage to package your dependencies as a framework. Include the following dependency in your Cartfile:</p>
<pre class="highlight swift"><code><span class="n">github</span> <span class="s">"mixpanel/mixpanel-swift"</span>
</code></pre>
<p>Check out the <a href="https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos">Carthage docs</a> for more info.</p>
<h2 id='2-initialize-mixpanel' class='heading'>2. Initialize Mixpanel</h2>
<p>Import Mixpanel into AppDelegate.swift, and initialize Mixpanel within application:didFinishLaunchingWithOptions:</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Mixpanel</span>
<span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="n">_</span> <span class="nv">application</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span>
<span class="n">didFinishLaunchingWithOptions</span> <span class="nv">launchOptions</span><span class="p">:</span> <span class="p">[</span><span class="kt">NSObject</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>
<span class="o">...</span>
<span class="kt">Mixpanel</span><span class="o">.</span><span class="nf">initialize</span><span class="p">(</span><span class="nv">token</span><span class="p">:</span> <span class="s">"MIXPANEL_TOKEN"</span><span class="p">)</span>
<span class="o">...</span>
<span class="p">}</span>
</code></pre>
<p><a href="https://mixpanel.github.io/mixpanel-swift/Classes/MixpanelInstance.html">See all configuration options</a></p>
<h2 id='3-send-data' class='heading'>3. Send Data</h2>
<p>Let&rsquo;s get started by sending event data. You can send an event from anywhere in your application. Better understand user behavior by storing details that are specific to the event (properties). After initializing the library, Mixpanel will <a href="https://mixpanel.com/help/questions/articles/which-common-mobile-events-can-mixpanel-collect-on-my-behalf-automatically">automatically collect common mobile events</a>. You can enable/disable automatic collection through your <a href="https://help.mixpanel.com/hc/en-us/articles/115004596186#enable-or-disable-common-mobile-events">project settings</a>. Also, Mixpanel automatically tracks some properties by default. <a href="https://help.mixpanel.com/hc/en-us/articles/115004613766-Default-Properties-Collected-by-Mixpanel#iOS">learn more</a></p>
<pre class="highlight swift"><code><span class="kt">Mixpanel</span><span class="o">.</span><span class="nf">mainInstance</span><span class="p">()</span><span class="o">.</span><span class="nf">track</span><span class="p">(</span><span class="nv">event</span><span class="p">:</span> <span class="s">"Sign Up"</span><span class="p">,</span> <span class="nv">properties</span><span class="p">:</span> <span class="p">[</span>
<span class="s">"source"</span><span class="p">:</span> <span class="s">"Pat's affiliate site"</span><span class="p">,</span>
<span class="s">"Opted out of email"</span><span class="p">:</span> <span class="kc">true</span>
<span class="p">])</span>
</code></pre>
<p>In addition to event data, you can also send <a href="https://developer.mixpanel.com/docs/swift#storing-user-profiles">user profile data</a>. We recommend this after completing the quickstart guide.</p>
<h2 id='4-check-for-success' class='heading'>4. Check for Success</h2>
<p><a href="http://mixpanel.com/report/live">Open up Live View in Mixpanel</a> to view incoming events. </p>
<p>Once data hits our API, it generally takes ~60 seconds for it to be processed, stored, and queryable in your project.</p>
<h2 id='complete-code-example' class='heading'>Complete Code Example</h2>
<p>Here&rsquo;s a runnable code example that covers everything in this quickstart guide.</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Mixpanel</span>
<span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="n">_</span> <span class="nv">application</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span>
<span class="n">didFinishLaunchingWithOptions</span> <span class="nv">launchOptions</span><span class="p">:</span> <span class="p">[</span><span class="kt">NSObject</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>
<span class="o">...</span>
<span class="kt">Mixpanel</span><span class="o">.</span><span class="nf">initialize</span><span class="p">(</span><span class="nv">token</span><span class="p">:</span> <span class="s">"MIXPANEL_TOKEN"</span><span class="p">)</span>
<span class="kt">Mixpanel</span><span class="o">.</span><span class="nf">mainInstance</span><span class="p">()</span><span class="o">.</span><span class="nf">track</span><span class="p">(</span><span class="nv">event</span><span class="p">:</span> <span class="s">"Sign Up"</span><span class="p">,</span> <span class="nv">properties</span><span class="p">:</span> <span class="p">[</span>
<span class="s">"source"</span><span class="p">:</span> <span class="s">"Pat's affiliate site"</span><span class="p">,</span>
<span class="s">"Opted out of email"</span><span class="p">:</span> <span class="kc">true</span>
<span class="p">])</span>
<span class="o">...</span>
<span class="p">}</span>
</code></pre>
<h1 id='faq' class='heading'>FAQ</h1>
<p><strong>I want to stop tracking an event/event property in Mixpanel. Is that possible?</strong></p>
<p>Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel wont store any new data for the event or property you select to drop. <a href="https://help.mixpanel.com/hc/en-us/articles/360001307806#dropping-events-and-properties">See this article for more information</a>.</p>
<p><strong>I have a test user I would like to opt out of tracking. How do I do that?</strong></p>
<p>Mixpanels client-side tracking library contains the <a href="https://mixpanel.github.io/mixpanel-swift/Classes/MixpanelInstance.html#/s:8Mixpanel0A8InstanceC14optOutTrackingyyF">optOutTracking()</a> method, which will set the users local opt-out state to “true” and will prevent data from being sent from a users device. More detailed instructions can be found in the section, <a href="https://developer.mixpanel.com/docs/swift#opting-users-out-of-tracking">Opting users out of tracking</a>.</p>
<p><strong>Why aren&rsquo;t my events showing up?</strong></p>
<p>To preserve battery life and customer bandwidth, the Mixpanel library doesn&rsquo;t send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call <a href="https://mixpanel.github.io/mixpanel-swift/Classes/MixpanelInstance.html#/s:8Mixpanel0A8InstanceC5flush10completionyyycSg_tF">flush()</a> manually if you want to force a flush at a particular moment.</p>
<pre class="highlight swift"><code><span class="kt">Mixpanel</span><span class="o">.</span><span class="nf">mainInstance</span><span class="p">()</span><span class="o">.</span><span class="nf">flush</span><span class="p">()</span>
</code></pre>
<p>If your events are still not showing up after 60 seconds, check if you have opted out of tracking. You can also enable Mixpanel debugging and logging, it allows you to see the debug output from the Mixpanel library. To enable it, set <a href="https://mixpanel.github.io/mixpanel-swift/Classes/MixpanelInstance.html#/s:8Mixpanel0A8InstanceC14loggingEnabledSbvp">loggingEnabled</a> to true.</p>
<pre class="highlight swift"><code><span class="kt">Mixpanel</span><span class="o">.</span><span class="nf">mainInstance</span><span class="p">()</span><span class="o">.</span><span class="n">loggingEnabled</span> <span class="o">=</span> <span class="kc">true</span>
</code></pre>
<p><strong>Starting with iOS 14.5, do I need to request the users permission through the AppTrackingTransparency framework to use Mixpanel?</strong></p>
<p>No, Mixpanel does not use IDFA so it does not require user permission through the AppTrackingTransparency(ATT) framework.</p>
<p><strong>If I use Mixpanel, how do I answer app privacy questions for the App Store?</strong></p>
<p>Please refer to our <a href="https://mixpanel.com/legal/app-store-privacy-details/">Apple App Developer Privacy Guidance</a></p>
<h2 id='i-want-to-know-more' class='heading'>I want to know more!</h2>
<p>No worries, here are some links that you will find useful:</p>
<ul>
<li><strong><a href="https://developer.mixpanel.com/docs/swift">Advanced iOS - Swift Guide</a></strong></li>
<li><strong><a href="https://github.com/mixpanel/mixpanel-swift/tree/master/MixpanelDemo">Sample app</a></strong></li>
<li><strong><a href="https://mixpanel.github.io/mixpanel-swift">Full API Reference</a></strong></li>
</ul>
<p>Have any questions? Reach out to Mixpanel <a href="https://help.mixpanel.com/hc/en-us/requests/new">Support</a> to speak to someone smart, quickly.</p>
</section>
</section>
<section id="footer">
<p>&copy; 2022 <a class="link" href="http://mixpanel.com" target="_blank" rel="external">Mixpanel</a>. All rights reserved. (Last updated: 2022-02-03)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>