# Amplitude Device Mode Integration

<p>After you have successfully <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/" >set up Amplitude as a destination</a> in RudderStack, follow this guide to correctly send your events to Amplitude in <a href="https://www.rudderstack.com/docs/destinations/rudderstack-connection-modes/#device-mode" >device mode</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="add-device-mode-integration">Add device mode integration</h2><p>Follow these steps to add Amplitude to your project depending on your integration platform:</p>
<div class="rs-tabs">
	<div class="rs-tabs__list">
		<button type="button" class="rs-tabs__tab"
			id="tab-afcbed"
		
		>Flutter</button>
		<button type="button" class="rs-tabs__tab"
			id="tab-ebcdfa"
		
		>React Native</button>
		<button type="button" class="rs-tabs__tab"
			id="tab-dbacfe"
		
		>iOS (Obj-C) — Legacy</button>
		<button type="button" class="rs-tabs__tab"
			id="tab-adbfce"
		
		>iOS SDK v2 — Legacy</button>
		<button type="button" class="rs-tabs__tab"
			id="tab-fbcead"
		
		>Android (Java) — Legacy</button>
	</div>
	
<div class="rs-tabs__panel" id="panel-afcbed">

<p>Follow the below steps to add Amplitude to your Flutter Project:</p>
<ol>
<li>Add the following dependency to the <code>dependencies</code> section of your <code>pubspec.yaml</code> file.</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">rudder_integration_amplitude_flutter: ^1.0.1</code></pre></div>
</div>
<ol start="2">
<li>Run the below command to install the dependency added in the above step:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">groovy<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-groovy" data-lang="groovy">flutter pub get</code></pre></div>
</div>
<ol start="3">
<li>Import the <code>RudderIntegrationAmplitudeFlutter</code> in your application where you are initializing the SDK.</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">dart<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-dart" data-lang="dart">import &#39;package:rudder_integration_amplitude_flutter/rudder_integration_amplitude_flutter.dart&#39;;</code></pre></div>
</div>
<ol start="4">
<li>Finally, change the initialization of your <code>RudderClient</code> as shown:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">dart<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-dart" data-lang="dart">final RudderController rudderClient = RudderController.instance;
RudderConfigBuilder builder = RudderConfigBuilder();
builder.withFactory(RudderIntegrationAmplitudeFlutter());
rudderClient.initialize(&lt;write_key&gt;, config: builder.build(), options: null);</code></pre></div>
</div>
<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">For iOS platform, make sure that the minimum deployment target for your application&rsquo;s target is at least 10.</div>
  </div>
</blockquote>
</html>

</div>

<div class="rs-tabs__panel" id="panel-ebcdfa" hidden>

<p>To add Amplitude to your React Native project:</p>
<ol>
<li>Add the RudderStack-Amplitude module to your app using either of the following ways:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">npm install @rudderstack/rudder-integration-amplitude-react-native</code></pre></div>
</div>
<p>OR
<br/></p>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">yarn add @rudderstack/rudder-integration-amplitude-react-native</code></pre></div>
</div>
<ol start="2">
<li>Import the module added above and add it to your SDK initialization code as shown:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">typescript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-typescript" data-lang="typescript">import rudderClient from &#34;@rudderstack/rudder-sdk-react-native&#34;
import amplitude from &#34;@rudderstack/rudder-integration-amplitude-react-native&#34;
const config = {
  dataPlaneUrl: DATA_PLANE_URL,
  trackAppLifecycleEvents: true,
  withFactories: [amplitude],
}
rudderClient.setup(WRITE_KEY, config)</code></pre></div>
</div>

</div>

<div class="rs-tabs__panel" id="panel-dbacfe" hidden>

<p>Follow these steps to add Amplitude to your iOS project:</p>
<ol>
<li>In your <code>Podfile</code>, add the <code>Rudder-Amplitude</code> extension:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">ruby<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-ruby" data-lang="ruby">pod &#39;Rudder-Amplitude&#39;
pod &#39;Amplitude&#39;, &#39;~&gt; 7.2.0&#39;</code></pre></div>
</div>
<ol start="2">
<li>After adding the dependency followed by <code>pod install</code> , you can add the imports to your <code>AppDelegate.m</code> file as shown:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">objectivec<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-objectivec" data-lang="objectivec">#import &lt;rudder&gt;
#import &#34;RudderAmplitudeFactory.h&#34;
// for using IDFA as device id, location listening only
#import &lt;amplitude&gt;</code></pre></div>
</div>
<ol start="3">
<li>Also add the initialization of your <code>RSClient</code> as shown:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">objectivec<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-objectivec" data-lang="objectivec">RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
[builder withDataPlaneUrl:DATA_PLANE_URL];
[builder withFactory:[RudderAmplitudeFactory instance]];
[RSClient getInstance:WRITE_KEY config:[builder build]];</code></pre></div>
</div>
<ol start="4">
<li>Add the below logic just after initializing <code>RudderClient</code> in <code>AppDelegate.m</code> if you would like to send <code>IDFA</code> of iOS device as <code>device id</code> to Amplitude</li>
</ol>
<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">Make sure to enable <strong>Use IDFA for device ID</strong> under the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ios" >iOS SDK settings</a> in the RudderStack dashboard.</div>
  </div>
</blockquote>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">// for using IDFA as device id only
[Amplitude instance].adSupportBlock = ^{
    return [[ASIdentifierManager sharedManager] advertisingIdentifier];
};</code></pre></div>
</div>
<ol start="5">
<li>Add the below logic to track location (latitude and longitude):</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">[Amplitude instance].locationInfoBlock = ^{
        return @{
                @&#34;lat&#34; : @37.7,
                @&#34;lng&#34; : @122.4
              };
};</code></pre></div>
</div>

</div>

<div class="rs-tabs__panel" id="panel-adbfce" hidden>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">This device mode integration is supported for Amplitude v8.8.0 and above.</div>
  </div>
</blockquote>
Follow these steps to add Amplitude to your iOS project:
<ol>
<li>Install <code>RudderAmplitude</code> (available through <a href="https://cocoapods.org" >CocoaPods</a>) by adding the following line to your <code>Podfile</code>:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">ruby<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-ruby" data-lang="ruby">pod &#39;RudderAmplitude&#39;, &#39;~&gt; 1.0.0&#39;</code></pre></div>
</div>
<ol start="2">
<li>Run the <code>pod install</code> command.</li>
<li>Then, import the SDK depending on your preferred platform:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">swift<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-swift" data-lang="swift">import RudderAmplitude</code></pre></div>
</div>
<br/>
<div class="rs-code">
  <div class="rs-code__head">objectivec<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-objectivec" data-lang="objectivec">@import RudderAmplitude;</code></pre></div>
</div>
<ol start="4">
<li>Next, add the imports to your <code>AppDelegate</code> file under the <code>didFinishLaunchingWithOptions</code> method:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">swift<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-swift" data-lang="swift">let config: RSConfig = RSConfig(writeKey: WRITE_KEY)
            .dataPlaneURL(DATA_PLANE_URL)

RSClient.sharedInstance().configure(with: config)
RSClient.sharedInstance().addDestination(RudderAmplitudeDestination())</code></pre></div>
</div>
<br/>
<div class="rs-code">
  <div class="rs-code__head">objectivec<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-objectivec" data-lang="objectivec">RSConfig *config = [[RSConfig alloc] initWithWriteKey:WRITE_KEY];
[config dataPlaneURL:DATA_PLANE_URL];

[[RSClient sharedInstance] configureWith:config];
[[RSClient sharedInstance] addDestination:[[RudderAmplitudeDestination alloc] init]];</code></pre></div>
</div>

</div>

<div class="rs-tabs__panel" id="panel-fbcead" hidden>

<p>To add Amplitude to your Android Project please follow these steps :</p>
<ol>
<li>Open your <code>app/build.gradle</code> (Module: app) file, and add the following under the <code>dependencies</code> section :</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">implementation &#39;com.rudderstack.android.sdk:core:1.+&#39;
implementation &#39;com.rudderstack.android.integration:amplitude:1.1.0&#39;</code></pre></div>
</div>
<ol start="2">
<li>Initialize the RudderStack SDK in the <code>onCreate()</code> method of the <code>Application</code> class as following:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">kotlin<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-kotlin" data-lang="kotlin">// initializing Rudder SDK
val rudderClient =
    RudderClient.getInstance(
        this,
        WRITE_KEY,
        RudderConfig.Builder()
            .withDataPlaneUrl(DATA_PLANE_URL)
            .withFactory(AmplitudeIntegrationFactory.FACTORY)
            .build()
    )</code></pre></div>
</div>
<ol start="3">
<li>To send <code>Google Advertising Id</code> of the device as <code>device id</code> to the Amplitude,  add the below code in the <code>AndroidManifest.xml</code> of your app under <code>&lt;application&gt;</code> tag:</li>
</ol>
<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">Make sure to enable <strong>Use Advertising ID for device ID</strong> under the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#android" >Android SDK settings</a> in the RudderStack dashboard.</div>
  </div>
</blockquote>
</html>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">&lt;meta-data android:name=&#34;com.google.android.gms.ads.AD_MANAGER_APP&#34; android:value=&#34;true&#34;&gt;&lt;/meta-data&gt;</code></pre></div>
</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="amplitude-browser-sdk-version">Amplitude Browser SDK version</h2><p>RudderStack lets you select the <a href="https://amplitude.com/docs/sdks/analytics/browser/browser-sdk-2" >Amplitude Browser SDK version</a> that the JavaScript SDK loads in device mode. You can configure this using the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#javascript" ><strong>SDK Version</strong></a> setting during destination setup.</p>
<p>With Browser SDK version <strong>2</strong>, you can also add optional Amplitude products such as Guides &amp; Surveys and Experiment alongside the device-mode integration. See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/other-features/" >Other Amplitude Features</a> for setup details.</p>
<p>The JavaScript SDK loads the following Amplitude Browser SDK lines for each option:</p>
<table>
  <thead>
      <tr>
          <th>SDK Version setting</th>
          <th>Amplitude Browser SDK</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>2</strong> (default)</td>
          <td>Amplitude Browser SDK 2.x</td>
      </tr>
      <tr>
          <td><strong>1</strong></td>
          <td>Amplitude Browser SDK 1.x</td>
      </tr>
  </tbody>
</table>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p><strong>New destinations default to Amplitude Browser SDK version 2.</strong></p>
<p>Any existing integrations continue to use Amplitude Browser SDK version <strong>1</strong> unless you explicitly opt in to version <strong>2</strong>.</p>
</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="requirements-for-v2">Browser SDK version 2 requirements</h3><p>Note that Amplitude Browser SDK version <strong>2</strong> requires a corresponding minimum supported version of the RudderStack JavaScript SDK:</p>
<ul>
<li>If you load the SDK from the RudderStack CDN, you always get latest version and thus it supports Amplitude SDK version <strong>2</strong>.</li>
<li>If you install it from NPM, upgrade to the latest version of the JavaScript SDK before selecting version <strong>2</strong>.</li>
</ul>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">In older SDK versions the setting is ignored and Amplitude continues to load with v1.</div>
  </div>
</blockquote>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="behavior-changes-in-version-2">Behavior changes in version 2</h3><p>When you switch a destination from version <strong>1</strong> to <strong>2</strong>, your saved settings (such as attribution and page tracking) carry over unchanged.</p>
<p>However, two behaviors change in Amplitude&rsquo;s version <strong>2</strong> SDK that you should be aware of before upgrading:</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="1-attribution-now-tracks-new-campaigns">1. Attribution now tracks new campaigns</h4><ul>
<li>In version <strong>1</strong>, attribution and new-campaign tracking were controlled separately, which let you enable attribution while ignoring new campaigns within a session.</li>
<li>In version <strong>2</strong>, this is no longer a separate option. When attribution is enabled, that is, when <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#javascript" ><strong>Disable attribution</strong></a> setting is turned off, Amplitude automatically tracks all new campaigns. As a result, your event volume may increase, and campaign attribution data may appear differently in Amplitude.</li>
</ul>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p>Attribution is still controlled by the existing <strong>Disable attribution</strong> in the same place as before — only the new-campaign behavior changes.</p>
<p>The <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#javascript" ><strong>Save referrer, URL params, GCLID only once per session</strong></a> setting does not apply to version <strong>2</strong>.</p>
</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="2-re-identifying-a-user-no-longer-resets-the-session">2. Re-identifying a user no longer resets the session</h4><ul>
<li>Invoking <code>rudderanalytics.identify()</code> to re-identify a new user results in the Amplitude SDK version <strong>1</strong> starting a new session.</li>
<li>However, Amplitude SDK version <strong>2</strong> does not reset the active session in this case. If your reporting relies on a new session beginning when a user logs in or is re-identified, review those reports after upgrading.</li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="enhanced-tracking">Enhanced tracking</h3><p>In version <strong>2</strong>, the Amplitude Web SDK can automatically capture additional page, interaction, and performance signals. You can enable each of these from the Amplitude destination settings.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">These features are available only when the destination uses Amplitude Browser SDK version <strong>2</strong>. Note that they are all toggled off by default, so upgrading to version <strong>2</strong> does not change what is captured until you enable them.</div>
  </div>
</blockquote>

</html>
<table>
  <thead>
      <tr>
          <th>Setting</th>
          <th>Description</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Auto-capture page views</td>
          <td>Let Amplitude&rsquo;s Web SDK automatically detect browser navigation and send its own page view events.</td>
      </tr>
      <tr>
          <td>Page URL Enrichment</td>
          <td>Enrich autocaptured events with page URL properties such as domain, path, URL, and title.</td>
      </tr>
      <tr>
          <td>Track session events</td>
          <td>Send Amplitude session start and session end events.</td>
      </tr>
      <tr>
          <td>Web Vitals</td>
          <td>Capture Core Web Vitals such as LCP, FCP, and TTFB as Amplitude events.</td>
      </tr>
      <tr>
          <td>File Downloads</td>
          <td>Automatically capture file download interactions.</td>
      </tr>
      <tr>
          <td>Frustration Interactions</td>
          <td>Capture frustration signals such as rage clicks and dead clicks.</td>
      </tr>
      <tr>
          <td>Network Tracking</td>
          <td>Capture failed (5xx) network requests as events.</td>
      </tr>
      <tr>
          <td>Element Interactions</td>
          <td>Automatically capture clicks and interactions on page elements.</td>
      </tr>
      <tr>
          <td>Form Interactions</td>
          <td>Automatically capture form start and form submit interactions.</td>
      </tr>
  </tbody>
</table>
<p>Note that <strong>Auto-capture page views</strong> is independent of the <strong>Track all pages</strong>, <strong>Track categorized pages</strong>, and <strong>Track named pages</strong> settings — these settings translate your instrumented <code>page()</code> calls into Amplitude events, whereas <strong>Auto-capture page views</strong> lets Amplitude&rsquo;s SDK detect navigation on its own.</p>
<p>If you enable <strong>Auto-capture page views</strong> while your app also instruments <code>page()</code> calls, Amplitude receives duplicate page events — one Amplitude-native page view and one from the RudderStack <code>page</code> event.</p>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><p>The <strong>Network Tracking</strong>, <strong>Element Interactions</strong>, and <strong>Form Interactions</strong> settings capture data based on user activity on the page. Depending on your application, they may:</p>
<ul>
<li>Capture personally identifiable information (PII), for example, values present in element attributes, form fields, or request and response URLs.</li>
<li>Significantly increase your event volume, which can affect your Amplitude billing and event quotas.</li>
</ul>
<p>Enable these settings only after reviewing what would be captured on your pages.</p>
</div>
  </div>
</blockquote>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="identify">Identify</h2><p>You can use the <a href="https://www.rudderstack.com/docs/event-spec/standard-events/identify/" ><code>identify</code></a> call to associate a user with their actions and capture all relevant traits about them. This includes a unique <code>userId</code> and other optional information like name, email address, etc.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">In device mode, RudderStack automatically captures and sends the device-specific identifiers like <code>deviceId</code> to Amplitude. These identifiers are used by Amplitude to track unique devices and sessions.</div>
  </div>
</blockquote>

</html>
<p>A sample <code>identify</code> call looks like the following:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.identify(
  &#34;userId&#34;, {
    email: &#34;name@surname.com&#34;,
    name: &#34;John Doe&#34;,
    profession: &#34;Student&#34;,
  })</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="opt-out-of-identify-calls">Opt out of identify calls</h3>
<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">This feature is available only for the mobile platforms.</div>
  </div>
</blockquote>
<p>You can opt out of an <code>identify</code> call in a current session by passing a <code>optOutOfSession</code> trait and setting it to <code>true</code>. If there is no active session, passing <code>optOutOfSession: true</code> does not start a new session.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="unset-user-properties">Unset user properties</h3><p>To unset the user traits in device mode, specify them in the <code>integrations.Amplitude.fieldsToUnset</code> object.</p>
<p>When you unset fields using <code>fieldsToUnset</code>, RudderStack notifies Amplitude to delete the fields along with their schema (if they exist).</p>
<p>See the <a href="https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A" >Amplitude documentation</a> for more information on this feature.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="example">Example</h4><p>To unset <code>firstName</code> and <code>lastName</code> in the following <code>identify</code> event:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.identify(&#34;userId&#34;, {
  &#34;firstName&#34;: &#34;Alex&#34;,
  &#34;outerObject&#34;: {
    &#34;innerObject&#34;: {
      &#34;lastName&#34;: &#34;Keener&#34;
    }
  }
});</code></pre></div>
</div>
<p>Set the <code>integrations</code> object in your <code>identify</code> event as shown:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.identify(&#34;userId&#34;, {}, {
  integrations: {
    Amplitude: {
      &#34;fieldsToUnset&#34;: [&#34;firstName&#34;, &#34;outerObject.innerObject.lastName&#34;]
    }
  }
})</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="page">Page</h2><p>The <a href="https://www.rudderstack.com/docs/event-spec/standard-events/page/" ><code>page</code></a> call allows you to record your website&rsquo;s page views, with the additional relevant information about the viewed page. RudderStack recommends calling this method at least once per page load.</p>
<p>In device mode, page views are automatically tracked as events in Amplitude with the event type as <code>[RudderStack] Page</code>.</p>
<p>A sample <code>page</code> call looks like the following:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.page({
  category: &#34;Category&#34;,
  name: &#34;Sample&#34;,
})</code></pre></div>
</div>
<p>In the above example, RudderStack captures information related to the page being viewed such as the category of the page (<code>Category</code>) and the page name (<code>Sample</code>).</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="screen">Screen</h2><p>The <a href="https://www.rudderstack.com/docs/event-spec/standard-events/screen/" ><code>screen</code></a> call lets you record screen views with any additional information about the viewed screen.</p>
<p>In device mode, screen views are automatically tracked as events in Amplitude with the event type as <code>[RudderStack] Screen</code>.</p>
<p>A sample <code>screen</code> call looks like the following code snippet:</p>
<div class="rs-code">
  <div class="rs-code__head">objectivec<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-objectivec" data-lang="objectivec">[[RSClient sharedInstance] screen:@&#34;Main&#34;
                properties:@{@&#34;prop_key&#34; : @&#34;prop_value&#34;}];</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="group">Group</h2><p>You can use the <a href="https://www.rudderstack.com/docs/event-spec/standard-events/group/" ><code>group</code></a> event to link an identified user with a group, like a company, organization, or an account.</p>
<p>Note that RudderStack does not support associating a user to more than one group per <code>group</code> call sent to Amplitude.</p>
<p>To send more than one group per user, you must call the <code>group</code> API multiple times with the relevant group information specified in the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#group-trait-settings" >group settings</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="use-amplitude-groups">Use Amplitude Groups</h3>
<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p>Note the following:</p>
<ul>
<li>This feature is only available for web (JavaScript) device mode.</li>
<li><a href="https://developers.amplitude.com/docs/group-identify-api" >Groups</a> are an enterprise-only feature in Amplitude. You need to purchase the <a href="https://help.amplitude.com/hc/en-us/articles/115001765532" >Accounts</a> add-on to use this feature.</li>
</ul></div>
  </div>
</blockquote>

</html>
<p>To use the Amplitude Groups feature with RudderStack:</p>
<ol>
<li>Configure the <strong>Group name trait</strong> and <strong>Group value trait</strong> fields in the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#group-trait-settings" ><strong>Group trait settings</strong></a>.</li>
<li>In device mode, RudderStack triggers a <code>group</code> call for a <code>groupId</code> by mentioning <code>groupType</code> as <code>'[RudderStack] Group'</code> and <code>value</code> as <code>groupId</code>.</li>
</ol>
<p>Even if you don&rsquo;t have an enterprise account or the Groups add-on, RudderStack adds <code>groups</code> as a user property in the user&rsquo;s profile with <strong>Group Name Trait</strong> as its type and <strong>Group Value Trait</strong> as its value.</p>
<p>For example, if you define the <strong>Group Name Trait</strong> as <code>RS</code> and <strong>Group Value Trait</strong> as <code>RudderStack</code> and make the <code>group</code> call, the user would then be associated with the group name as <code>RS</code> and the group value as <code>RudderStack</code>.</p>
<p>Note that in device mode:</p>
<ul>
<li>Group properties are limited to scalar values and arrays.</li>
<li>Nested objects in group properties are not supported.</li>
<li>Group property values cannot exceed 1000 characters.</li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="track">Track</h2><p>The <a href="https://www.rudderstack.com/docs/event-spec/standard-events/track/" ><code>track</code></a> call lets you record the user&rsquo;s actions along with any properties associated with them.</p>
<p>In device mode, events are processed and sent immediately to Amplitude. The SDK also supports offline event caching and automatic retries when the device is back online.</p>
<p>A sample <code>track</code> call looks like the following:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;Track me&#34;)</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="opt-out-of-track-calls">Opt out of track calls</h3>
<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">This feature is available only for the mobile platforms.</div>
  </div>
</blockquote>
<p>If you set a property with the name <code>optOutOfSession</code> with value set to <code>true</code>, then this <code>track</code> call will be opted out of the current session if it exists. If there is no active session, passing <code>optOutOfSession: true</code> does not start a new session.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="track-revenue-events">Track revenue events</h3>
<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p>Revenue events are available only in web device mode.</p>
<p>To track revenue events, RudderStack uses Amplitude&rsquo;s <code>logRevenueV2()</code> API which expects <code>revenue</code> as a top level attribute.</p>
</div>
  </div>
</blockquote>

</html>
<p>To track a revenue event, you must include a <code>revenue</code> key in the event, as shown:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;Item Purchased&#34;, {
  revenue: 30,
  revenue_type: &#34;add-on purchase&#34;,
})</code></pre></div>
</div>
<p>RudderStack processes revenue events in the following ways:</p>
<ul>
<li>If you include <code>price</code> and <code>quantity</code> fields in your event, then RudderStack calculates the revenue as <code>price * quantity</code>.</li>
<li>If the <code>revenue</code> field is present in your event but <code>price</code> is not, then RudderStack uses <code>revenue</code> as the <code>price</code> with <code>quantity</code> set to 1.</li>
</ul>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">The <code>revenue</code> field <strong>does not override</strong> the <code>price * quantity</code> calculation, if both are present.</div>
  </div>
</blockquote>

</html>
<p>Note that:</p>
<ul>
<li>Each product must have either <code>price</code> or <code>revenue</code> fields for tracking.</li>
<li>The <code>logRevenueV2</code> API uses both <code>price</code> and <code>quantity</code> to calculate revenue.</li>
<li>If <code>quantity</code> is not specified, it defaults to <code>1</code>.</li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="track-revenue-at-event-or-product-level">Track revenue at event or product level</h4><p>For events with a <code>products</code> array, you can track revenue at event level or product level based on your dashboard configuration:</p>
<table>
  <thead>
      <tr>
          <th>Dashboard setting</th>
          <th>Action</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ecommerce-settings" >Track revenue per product</a> is enabled</td>
          <td>Revenue is tracked separately for each product.</td>
      </tr>
      <tr>
          <td><a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ecommerce-settings" >Track revenue per product</a> is disabled</td>
          <td>Revenue is tracked as an aggregate at the event level.</td>
      </tr>
  </tbody>
</table>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="track-completed-orders">Track completed orders</h3>
<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">This feature is available only in web device mode.</div>
  </div>
</blockquote>

</html>
<p>In device mode, revenue tracking for orders is handled by the Amplitude SDK&rsquo;s <code>logRevenueV2</code> API, which ensures accurate revenue attribution even in offline scenarios.</p>
<p>While tracking completed orders with multiple products, RudderStack generates events as follows:</p>
<p><strong>When <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ecommerce-settings" >Track products as a single event</a> setting is toggled off</strong>:</p>
<ul>
<li>One main <code>Order Completed</code> event with the overall order details</li>
<li>Separate <code>Product Purchased</code> events for each product in the <code>products</code> array</li>
<li>Revenue tracking based on your <a href="#track-revenue-at-event-or-product-level" >revenue tracking configuration</a></li>
</ul>
<p><strong>When <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ecommerce-settings" >Track products as a single event</a> setting is toggled on</strong>:</p>
<ul>
<li>
<p>One single event with the original event name (<code>Order Completed</code>)</p>
</li>
<li>
<p>All products are included as properties in this single event</p>
</li>
<li>
<p>Revenue tracking based on your <a href="#track-revenue-at-event-or-product-level" >revenue tracking configuration</a>:</p>
<ul>
<li>If <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ecommerce-settings" >Track revenue per product</a> setting is enabled: Each product is tracked individually with its own revenue calculation, regardless of the total order revenue.</li>
<li>If <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#ecommerce-settings" >Track revenue per product</a> setting is disabled: The total revenue specified at the order level is used.</li>
</ul>
</li>
</ul>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">In both the cases, any discrepancy between the sum of product revenues and the order-level revenue is ignored.</div>
  </div>
</blockquote>

</html>
<p>A sample <code>Order Completed</code> event is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;Order Completed&#34;, {
  checkoutId: &#34;ABCD1234&#34;,
  orderId: &#34;order1234&#34;,
  revenue: 50,
  products: [
    {
      productId: &#34;product1&#34;,
      sku: &#34;45790-32&#34;,
      name: &#34;Monopoly: 3rd Edition&#34;,
      price: 20,
      quantity: 1,
      category: &#34;Games&#34;,
    },
    {
      productId: &#34;product2&#34;,
      sku: &#34;46493-32&#34;,
      name: &#34;Uno Card Game&#34;,
      price: 15,
      quantity: 2,
      category: &#34;Games&#34;,
    },
  ],
})</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="advanced-features">Advanced features</h2><p>This section covers some advanced features that you can use to enhance your Amplitude device mode integration with RudderStack.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="reset">Reset</h3>
<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">This feature is currently available only for the mobile platforms.</div>
  </div>
</blockquote>

</html>
<p>You can use the <code>reset</code> method to reset the previously identified user and related information. This is particularly useful in scenarios like user logout.</p>
<div class="rs-tabs">
	<div class="rs-tabs__list">
		<button type="button" class="rs-tabs__tab"
			id="tab-dbcafe"
		
		>iOS (Obj-C) — Legacy</button>
		<button type="button" class="rs-tabs__tab"
			id="tab-cbfeda"
		
		>Android (Java) — Legacy</button>
	</div>
	
<div class="rs-tabs__panel" id="panel-dbcafe">

<div class="rs-code">
  <div class="rs-code__head">objectivec<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-objectivec" data-lang="objectivec">[[RSClient sharedInstance] reset];</code></pre></div>
</div>

</div>

<div class="rs-tabs__panel" id="panel-cbfeda" hidden>

<div class="rs-code">
  <div class="rs-code__head">kotlin<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-kotlin" data-lang="kotlin">rudderClient.reset()</code></pre></div>
</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="send-event_id">Send <code>event_id</code></h3><p>RudderStack supports sending <code>event_id</code> to Amplitude in device mode. You can include it under the <code>integrations</code> object and it is supported for all API calls (<code>identify</code>, <code>track</code>, <code>page</code>, <code>screen</code>, and <code>group</code>).</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">If you don&rsquo;t specify an <code>event_id</code>, the SDK automatically generates one to ensure event uniqueness.</div>
  </div>
</blockquote>

</html>
<p>A sample <code>identify</code> call with <code>event_id</code> is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.identify(
  &#34;1hKOmRA4GRlm&#34;, {
    name: &#34;Alex Keener&#34;
  }, {
    integrations: {
      Amplitude: {
        event_id: 1234
      }
    }
  }
);</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="skip-user-properties-sync">Skip user properties sync</h3><p>When you send an event to Amplitude via RudderStack, Amplitude updates the existing user properties and appends any new ones. You can change this behavior by setting the <code>skip_user_properties_sync</code> property to <code>true</code> in the <code>integrations</code> object.</p>
<p>This ensures that the event in Amplitude:</p>
<ul>
<li>Includes only the user properties sent with it</li>
<li>Does not modify the user properties table</li>
<li>Does not include any pre-existing user properties</li>
</ul>
<p>See <a href="https://www.docs.developers.amplitude.com/analytics/data-backfill-guide/#skip-user-properties-sync" >Amplitude documentation</a> for more information on this feature.</p>
<p>A sample <code>integrations</code> object with the <code>skip_user_properties_sync</code> property is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">&#34;integrations&#34;: {
        ...
        ...
        &#34;Amplitude&#34;: {
            &#34;skipUserPropertiesSync&#34;: true
        }
        ...
        ...
    }</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="faq">FAQ</h2><!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="can-i-send-more-than-one-group-per-user-to-amplitude">Can I send more than one group per user to Amplitude?</h4><p>RudderStack does not support associating a user to more than one group per <code>group</code> call sent to Amplitude. To send more than one group per user, you need to call the <code>group</code> API multiple times with the relevant group information specified in the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/amplitude/setup-guide/#group-trait-settings" >group settings</a>.</p>
<br />
