<pclass="header-right"><ahref="dash-feed://erivedDataPath%2C%2FUsers%2Fketan%2FDocuments%2FMixpanel-GitHub%2Fmixpanel-swift%2Fbuild"><imgsrc="img/dash.png"alt="Dash"/>Install in Dash</a></p>
<imgsrc="https://user-images.githubusercontent.com/71290498/231855731-2d3774c3-dc41-4595-abfb-9c49f5f84103.png"alt="Mixpanel Swift Library"height="150"/>
<p><ahref="http://isitmaintained.com/project/mixpanel/mixpanel-swift"title="Average time to resolve an issue"><imgsrc="http://isitmaintained.com/badge/resolution/mixpanel/mixpanel-swift.svg"alt="Average time to resolve an issue"></a>
<ahref="http://isitmaintained.com/project/mixpanel/mixpanel-swift"title="Percentage of issues still open"><imgsrc="http://isitmaintained.com/badge/open/mixpanel/mixpanel-swift.svg"alt="Percentage of issues still open"></a>
We’d also love for you to come and work with us! Check out <strong><ahref="https://mixpanel.com/jobs/#openings">Jobs</a></strong> for details.</p>
<p>If you are using Objective-C, we recommend using our <strong><ahref="https://github.com/mixpanel/mixpanel-iphone">Objective-C Library</a></strong>.</p>
<p>Check out our <ahref="https://developer.mixpanel.com/docs/swift">Advanced iOS Swift Guide</a> for additional advanced configurations and use cases, like setting up your project with European Union data storage.</p>
<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>
<p>You will need your project token for initializing your library. You can get your project token from <ahref="https://mixpanel.com/settings/project">project settings</a>.</p>
<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 'Mixpanel-swift'</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>
<p>The Mixpanel Swift SDK includes the following third-party dependencies:</p>
<ul>
<li><strong>json-logic-swift</strong> (v1.2.0+) - Used for evaluating property filters in first-time event targeting for Feature Flags.</li>
</ul>
<p>This dependency is automatically managed by your package manager (Swift Package Manager, CocoaPods, or Carthage) and does not require manual installation.</p>
<p>Let’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 <ahref="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 <ahref="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. <ahref="https://help.mixpanel.com/hc/en-us/articles/115004613766-Default-Properties-Collected-by-Mixpanel#iOS">learn more</a></p>
<p>In addition to event data, you can also send <ahref="https://developer.mixpanel.com/docs/swift#storing-user-profiles">user profile data</a>. We recommend this after completing the quickstart guide.</p>
<h2id='4-check-for-success'class='heading'>4. Check for Success</h2>
<p>Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel won’t store any new data for the event or property you select to drop. <ahref="https://help.mixpanel.com/hc/en-us/articles/360001307806#dropping-events-and-properties">See this article for more information</a>.</p>
<p>Mixpanel’s client-side tracking library contains the <ahref="https://mixpanel.github.io/mixpanel-swift/Classes/MixpanelInstance.html#/s:8Mixpanel0A8InstanceC14optOutTrackingyyF">optOutTracking()</a> method, which will set the user’s local opt-out state to “true” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section, <ahref="https://developer.mixpanel.com/docs/swift#opting-users-out-of-tracking">Opting users out of tracking</a>.</p>
<p>First, make sure your test device has internet access. To preserve battery life and customer bandwidth, the Mixpanel library doesn’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 <ahref="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>
<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 <ahref="https://mixpanel.github.io/mixpanel-swift/Classes/MixpanelInstance.html#/s:8Mixpanel0A8InstanceC14loggingEnabledSbvp">loggingEnabled</a> to true.</p>
<p><strong>Starting with iOS 14.5, do I need to request the user’s permission through the AppTrackingTransparency framework to use Mixpanel?</strong></p>
<p>Have any questions? Reach out to Mixpanel <ahref="https://help.mixpanel.com/hc/en-us/requests/new">Support</a> to speak to someone smart, quickly.</p>
<p>Generated by <aclass="link"href="https://github.com/realm/jazzy"target="_blank"rel="external noopener">jazzy ♪♫ v0.15.4</a>, a <aclass="link"href="https://realm.io"target="_blank"rel="external noopener">Realm</a> project.</p>