LogoLogo
  • Contributing to RudderStack
  • Destination_Name
  • LICENSE
  • RudderStack Docs
  • docs
    • FAQ
    • Identity Resolution
    • Home
    • cloud-extract-sources
      • ActiveCampaign Source
      • Bing Ads
      • Chargebee
      • Common Settings
      • Facebook Ads
      • Freshdesk
      • Google Ads Source
      • Google Analytics
      • Google Search Console
      • Google Sheets
      • Cloud Extract Sources
      • Intercom v2
      • Intercom
      • Mailchimp
      • Marketo
      • Mixpanel
      • NetSuite
      • Pipedrive
      • QuickBooks
      • Salesforce Pardot
      • Sendgrid Source
      • Stripe Source
      • Xero
      • Zendesk Chat
      • Zendesk
      • hubspot
        • HubSpot Data Model and Schema Information
        • HubSpot
      • salesforce
        • Salesforce
        • Schema Comparison: RudderStack vs. Segment
    • connections
      • Connection Modes: Cloud Mode vs. Device Mode
    • data-governance
      • Data Governance
      • RudderTyper
      • Data Governance API
      • RudderTyper
      • tracking-plans
        • Tracking Plans
        • Tracking Plan Spreadsheet
    • data-warehouse-integrations
      • Amazon Redshift
      • Azure Data Lake
      • Azure Synapse
      • ClickHouse
      • Databricks Delta Lake
      • Google Cloud Storage Data Lake
      • Google BigQuery
      • Identity Resolution
      • Warehouse Destinations
      • Microsoft SQL Server
      • PostgreSQL
      • Amazon S3 Data Lake
      • Snowflake
      • FAQ
      • Warehouse Schema
    • destinations
      • Destinations
      • Webhooks
      • advertising
        • Bing Ads
        • Criteo
        • DCM Floodlight
        • Facebook App Events
        • Facebook Custom Audience
        • Facebook Pixel
        • Google Ads (gtag.js)
        • Google AdWords Enhanced Conversions
        • Google Adwords Remarketing Lists (Customer Match)
        • Advertising
        • LinkedIn Insight Tag
        • Lotame
        • Pinterest Tag
        • Reddit Pixel
        • Snap Pixel
        • TikTok Ads
      • analytics
        • Amplitude
        • AWS Personalize
        • Chartbeat
        • Firebase
        • FullStory
        • Google Analytics 360
        • Google Analytics
        • Heap.io
        • Hotjar
        • Analytics
        • Indicative
        • Keen
        • Kissmetrics
        • Kubit
        • Lytics
        • Mixpanel
        • Pendo
        • PostHog
        • Quantum Metric
        • Singular
        • adobe-analytics
          • Adobe Analytics Heartbeat Measurement
          • Mobile Device Mode Settings
          • Web Device Mode Settings
          • E-commerce Events
          • Adobe Analytics
          • Setting Up Adobe Analytics in RudderStack
        • google-analytics-4
          • Cloud Mode
          • Device Mode
          • Google Analytics 4
          • Setting up Google Analytics 4
        • profitwell
          • ProfitWell
          • Cloud Mode
          • Device Mode
      • attribution
        • Adjust
        • AppsFlyer
        • Branch
        • Attribution
        • Kochava
        • TVSquared
      • business-messaging
        • Business Messaging
        • Intercom
        • Kustomer
        • Slack
        • Trengo
      • continuous-integration
        • Visual Studio App Center
        • Continuous Integration
      • crm
        • Delighted
        • HubSpot
        • CRM
        • Salesforce
        • Variance
        • Zendesk
      • customer-data-platform
        • Customer Data Platform
        • Segment
      • error-reporting
        • Bugsnag
        • Error Reporting
        • Sentry
      • marketing
        • ActiveCampaign
        • AdRoll
        • Airship
        • Appcues
        • Autopilot
        • Blueshift
        • Braze
        • CleverTap
        • Customer.io
        • Gainsight PX
        • Gainsight
        • Marketing
        • Iterable
        • Klaviyo
        • Leanplum
        • Mailchimp
        • Marketo Lead Import
        • Marketo
        • MoEngage
        • Ometria
        • Pardot
        • Post Affiliate Pro
        • Qualtrics
        • SendGrid
        • Salesforce Marketing Cloud
        • Userlist
        • drip
          • Cloud Mode
          • Device Mode
          • Drip
          • Setting Up Drip in RudderStack
      • productivity
        • Google Sheets
        • Productivity
      • storage-platforms
        • Amazon S3
        • DigitalOcean Spaces
        • Google Cloud Storage
        • Storage Platforms
        • Azure Blob Storage
        • MinIO
        • Redis
      • streaming-platforms
        • Amazon EventBridge
        • Amazon Kinesis Firehose
        • Amazon Kinesis
        • Azure Event Hubs
        • BigQuery Stream
        • Confluent Cloud
        • Google Pub/Sub
        • Streaming Platforms
        • Apache Kafka
      • tag-managers
        • Google Tag Manager
        • Tag Managers
      • testing-and-personalization
        • Algolia Insights
        • Candu
        • Google Optimize
        • A/B Testing & Personalization
        • LaunchDarkly
        • Monetate
        • Optimizely Full Stack
        • Optimizely Web
        • Split.io
        • Statsig
        • VWO (Visual Website Optimizer)
    • get-started
      • RudderStack Cloud vs. RudderStack Open Source
      • Glossary
      • Get Started
      • RudderStack Architecture
    • reverse-etl
      • Amazon Redshift
      • Amazon S3
      • ClickHouse
      • FAQ
      • Google BigQuery
      • Reverse ETL
      • PostgreSQL
      • Snowflake
      • common-settings
        • Importing Data using Models
        • Importing Data using Tables
        • Common Settings
        • Sync Modes
        • Sync Schedule
      • features
        • Airflow Provider
        • Features
        • Models
        • Visual Data Mapper
    • rudderstack-api
      • Data Regulation API
      • HTTP API
      • RudderStack API
      • Personal Access Tokens
      • Pixel API
      • Test API
      • api-specification
        • Application Lifecycle Events Specification
        • API Specification
        • Video Events Specification
        • rudderstack-ecommerce-events-specification
          • Browsing
          • Coupons
          • E-Commerce Events Specification
          • Ordering
          • Promotions
          • Reviewing
          • Sharing
          • Wishlist
        • rudderstack-spec
          • Alias
          • Common Fields
          • Group
          • Identify
          • RudderStack Event Specification
          • Page
          • Screen
          • Track
    • rudderstack-cloud
      • Audit Logs
      • Dashboard Overview
      • Destinations
      • RudderStack Cloud
      • Live Events
      • Connection Modes: Cloud Mode vs. Device Mode
      • Sources
      • Teammates (User Management)
      • connections
        • Adding a Destination
        • Connections
    • rudderstack-open-source
      • Control Plane Setup
      • RudderStack Open Source
      • installing-and-setting-up-rudderstack
        • Developer Machine Setup
        • Docker
        • Data Plane Setup
        • Kubernetes
        • Sending Test Events
    • stream-sources
      • App Center
      • AppsFlyer
      • Auth0
      • Braze
      • Customer.io
      • Extole
      • Event Stream Sources
      • Iterable
      • Looker
      • PostHog
      • Segment
      • Shopify
      • Webhook Source
      • rudderstack-sdk-integration-guides
        • Client-side Event Filtering
        • SDKs
        • AMP Analytics
        • Cordova
        • .NET
        • Go
        • Java
        • Node.js
        • PHP
        • Python
        • React Native
        • Ruby
        • Rust
        • Unity
        • SDK FAQs
        • rudderstack-android-sdk
          • Adding Application Class
          • Flushing Events Periodically
          • Android
        • rudderstack-flutter-sdk
          • Flutter SDK v1
          • Flutter v2
          • Flutter
        • rudderstack-ios-sdk
          • iOS
          • tvOS
          • watchOS
        • rudderstack-javascript-sdk
          • Data Storage in Cookies
          • Detecting Ad-blocked Pages
          • JavaScript
          • JavaScript SDK Enhancements
          • JavaScript SDK FAQs
          • Querystring API
          • Quick Start Guide
          • Version Migration Guide
          • consent-managers
            • Consent Managers
            • OneTrust
    • transformations
      • Access Token
      • FAQ
      • Transformations
      • Transformations API
    • user-guides
      • User Guides
      • administrators-guide
        • Troubleshooting Guide
        • Alerting Guide
        • Bucket Configuration Settings for Event Backups
        • Configuration Parameters
        • Event Replay
        • High Availability
        • Horizontal Scaling
        • Administrator's Guides
        • Infrastructure Provisioning
        • Monitoring and Metrics
        • Okta SSO Setup
        • OneLogin SSO Setup
        • RudderStack Grafana Dashboard
        • Software Releases
      • how-to-guides
        • How to Use Custom Domains
        • How to Develop Integrations for RudderStack
        • How to Configure a Destination via the Event Payload
        • How to Filter Events using Different Methods
        • How to Filter Selective Destinations
        • How to Submit a Pull Request for a New Integration
        • How-to Guides
        • How to Debug Live Destination Events
        • How to Use AWS Lambda Functions with RudderStack
        • create-a-new-destination-transformer-for-rudder
          • Best Practices for Coding Transformation Functions in JavaScript
          • How to Create a New Destination Transformation for RudderStack
        • implement-native-js-sdk-integration
          • How to Add a Device Mode SDK to RudderStack JavaScript SDK
          • How to Implement a Native JavaScript SDK Integration
        • rudderstack-jamstack-integration
          • How to Integrate RudderStack with Your JAMstack Site
          • How to Integrate Rudderstack with Your Angular App
          • How to Integrate Rudderstack with Your Astro Site
          • How to Integrate Rudderstack with Your Eleventy Site
          • How to Integrate Rudderstack with Your Ember.js App
          • How to Integrate Rudderstack with a Gatsby Website
          • How to Integrate Rudderstack with a Hugo Site
          • How to Integrate Rudderstack with Your Jekyll Site
          • How to Integrate Rudderstack with Your Next.js App
          • How to Integrate Rudderstack with Your Nuxt.js App
          • How to Integrate Rudderstack with Your Svelte App
          • How to Integrate Rudderstack with Your Vue App
      • migration-guides
        • Migrating from Blendo to RudderStack
        • Migrating Your Warehouse Destination from Segment to RudderStack
        • Migration Guides
        • Migrating from Segment to RudderStack
  • src
    • @rocketseat
      • gatsby-theme-docs
        • text
          • Home
Powered by GitBook
On this page
  • SDK setup requirements
  • Installing the Cordova SDK
  • Initializing the RudderStack client
  • Configuring the RudderStack client
  • Identify
  • Track
  • Group
  • Screen
  • Alias
  • Reset
  • Configuring the options object
  • Enabling/disabling user tracking via the optOut API (GDPR support)
  • Filtering events
  • Enabling/disabling events for specific destinations
  • Passing destinations during SDK initialization
  • Passing destinations during event calls
  • Anonymous ID
  • Setting the advertisement ID
  • Setting the device token
  • Debugging
  • FAQs
  • Where can I find the source write key?
  • Where can I find the data plane URL?
  • Contact us

Was this helpful?

  1. docs
  2. stream-sources
  3. rudderstack-sdk-integration-guides

Cordova

Detailed technical documentation on RudderStack’s Cordova SDK to send events from your Cordova apps to various destinations.

PreviousAMP AnalyticsNext.NET

Last updated 3 years ago

Was this helpful?

is an open-source, cross-platform application development framework.

The RudderStack Cordova SDK lets you track event data from your Cordova applications and send it to your specified destinations via RudderStack.

Check the and the to get a more hands-on understanding of the SDK.

SDK setup requirements

To set up the Cordova SDK, follow these steps:

  • You will need to set up a .

  • Once signed up, set up a Cordova source in the dashboard. For more information, follow . You should then see a Write Key for this source, as shown below:

  • You will also need a data plane URL. Follow for more information on the data plane URL and where to get it.

Installing the Cordova SDK

To add the Cordova SDK as a dependency, navigate to the root folder of your application and run the following command:

cordova plugin add rudder-sdk-cordova

The Cordova SDK supports the device mode starting from version 1.3.0.

Initializing the RudderStack client

After adding the SDK as a dependency, you need to set up the SDK.

Add the following code in the onDeviceReady() function of your home page to initialize the SDK.

A sample Cordova SDK initialization is as shown:

RudderClient.initialize(WRITE_KEY , {
  dataPlaneUrl: DATA_PLANE_URL,
  loglevel: RudderClient.LogLevel.VERBOSE,
})

Make sure you use the await keyword with the initialize call.

The setup method has the following signature:

Name
Data Type
Presence
Description

writeKey

string

Required

Your Cordova source writeKey from the dashboard.

configuration

JSON Object

Optional

Contains the RudderStack client configuration.

options

JSON Object

Optional

Extra options to be pass along with the event.

Configuring the RudderStack client

You can configure your RudderStack client by passing the following parameters in the configuration object of your RudderClient.initialize() call:

Parameter
Type
Description
Default Value

logLevel

RudderClient.LogLevel

Controls how much of the log you want to see from the Cordova SDK.

RudderClient.LogLevel.None

dataPlaneUrl

String

Your RudderStack Data Plane URL.

flushQueueSize

Integer

The number of events included in a batch request to the server.

30

dbThresholdCount

Integer

The number of events to be saved in the SQLite database. Once the limit is reached, older events are deleted from the database.

10000

sleepTimeout

Integer

Minimum waiting time to flush the events to the server.

10 seconds

configRefreshInterval

Integer

RudderStack fetches the config after this time interval.

2

autoCollectAdvertId

Boolean

Determines if the SDK will collect the advertisement ID.

false

trackLifecycleEvents

Boolean

Determines if the SDK should capture the application lifecycle events automatically.

true

Identify

The identify call lets you identify a visiting user and associate them with their actions. It also lets you record the traits about them like their name, email address, etc.

As a best practice, we recommend calling identify at the start of every session or page load for logged-in users. This will ensure all their latest traits are captured in all the subsequent events.

A sample identify call is as shown below:

RudderClient.identify("userId", {
  address: {
    city: "LA",
    country: "USA",
    state: "CA",
  },
  birthday: "1984/07/17",
  company: {
    name: "RudderStack",
    id: "RS",
    industry: "IT",
  },
  email: "john@rudderstack.com",
  firstName: "john",
});

The identify method has the following signatures:

Name
Data Type
Presence
Description

userId

string

Required

User identifier in your database.

traits

JSON Object

Optional

Information related to the user traits.

options

JSON Object

Optional

Extra options for the identify event.

Track

The track call lets you record the user actions along with their associated properties. Each user action is called an event.

A sample track event called Order Completed using the Cordova SDK is shown below:

RudderClient.track('Order Completed', {
  checkout_id: '18310159091413-2',
  order_id: '1153390412189-01',
  affiliation: 'Google Play Store',
  total: 68.00,
  subtotal: 60.00,
  revenue: 70.00,
  shipping: 5,
  tax: 3,
  discount: 10,
  coupon: 'NEWUSER',
  currency: 'USD',
  products: [{
      product_id: '853913-410121910',
      sku: 'FF-21',
      name: 'Varsity Graphic T-Shirt',
      price: 25,
      quantity: 1,
      category: 'Clothing',
      url: 'https://www.myntra.com/tshirts/huetrap/huetrap-men-beige/111/buy',
    },
    {
      product_id: '113413-190158920',
      sku: 'GF-67',
      name: 'Printed Round Neck T-Shirt',
      price: 15,
      quantity: 3,
      category: 'Clothing'
    }
  ]
})

The track method has the following signature:

Name
Data Type
Presence
Description

name

String

Required

Contains the name of the event that you want to track.

properties

JSON Object

Optional

Contains the extra properties to be sent along with the event.

options

JSON Object

Optional

Contains the extra event options.

RudderStack automatically tracks the following optional events:

  • Application Installed

  • Application Opened

You can disable these events by sending the property trackLifecycleEvents as false within the configuration object while initializing the RudderStack client. However, we highly recommend keeping them enabled.

Group

The group call lets you associate an identified user to a group - either a company, project, or a team, and record any custom traits or properties associated with that group.

A sample group call is as shown:

RudderClient.group("group1", {
  groupname: "RS",
  groupwork: "Mobile dev"
})

The group method has the following signatures:

Name
Data Type
Presence
Description

groupId

string

Required

The organization ID with which you want to associate the user.

groupTraits

JSON Object

Optional

Any other property of the organization that you want to pass along with the call.

options

JSON Object

Optional

Extra options for the group event.

Screen

The screen call lets you record whenever your user views their mobile screen with any additional relevant information about the viewed screen.

A sample screen call is shown below:

RudderClient.screen("Home Screen", {
  mobile: "pixel"
})

The screen method has the following signature:

Name
Data Type
Presence
Description

screenName

string

Required

Name of the viewed screen.

property

JSON Object

Optional

Extra properties that you want to pass along with the screen call.

options

JSON Object

Optional

Extra options to be passed along with screen event.

Alias

The alias call lets you merge different identities of a known user.

alias is an advanced method that lets you change the tracked user's ID explicitly. This method is useful when managing identities for some of the downstream destinations.

A sample alias call is shown below:

RudderClient.alias("userId")

The alias method has the following signature:

Name
Data Type
Presence
Description

newId

String

Required

The new userId that you want to assign to the user.

options

JSON Object

Optional

Event level options.

Reset

You can use the reset method to clear the persisted traits from the identify call. We recommend calling it during the Logout operation.

A sample reset call is as shown:

RudderClient.reset()

Configuring the options object

The options object can be sent along with all the above-mentioned API calls. It has the following signature:

Name
Data Type
Presence
Description

externalIds

JSON Object

Optional

Each key within externalIds object should define the type of external ID, and its value should be a String or Integer.

integrations

JSON Object

Optional

A sample options object for an identify event is as shown:

RudderClient.identify("1hKOmRA4el9Ztm", {
  "address": {
    "city": "New Orleans",
    "country": "USA",
    "state": "Louisiana",
  },
  "birthday": "01/24/1984",
  "company": {
    "name": "Apple Inc.",
    "id": "1hKOmRA4el9Ztm",
    "industry": "IT"
  },
  "email": "alex@example.com",
  "firstName": "Alex",
}, {
  "externalIds": {
    "brazeExternalId": "externalId1"
  },
  "integrations": {
    "MixPanel": false,
    "Amplitude": true
  }
})

In the above snippet, the options object is as follows:

{
  "externalIds": {
    "brazeExternalId": "externalId1"
  },
  "integrations": {
    "MixPanel": false,
    "Amplitude": true
  }
}

Enabling/disabling user tracking via the optOut API (GDPR support)

RudderStack gives the users (e.g., an EU user) the ability to opt out of tracking any user activity until the user gives their consent. You can do this by leveraging RudderStack's optOut API.

The optOut API takes true or false as a Boolean value to enable or disable tracking user activities. This flag persists across the device reboots.

The following snippet highlights the use of the optOut API to disable user tracking:

RudderClient.optOut(true);

Once the user grants their consent, you can enable user tracking once again by using the optOut API with false as a parameter sent to it, as shown:

RudderClient.optOut(false);

The optOut API is available in the Cordova SDK starting from version 1.0.1.

Filtering events

Enabling/disabling events for specific destinations

RudderStack lets you send your event data only to the explicitly specified destinations and filtering out the rest. You can do this in one of the following two ways:

  • While initializing the Cordova SDK

  • While making the event calls

Passing destinations during SDK initialization

This approach is useful when you want to send the events to specific destinations across all the event calls made using the SDK.

A sample SDK initialization is shown below:

RudderClient.initialize("1n0JdVPZTRUIkLXYccrWzZwdGSx", {
  dataPlaneUrl: "https://0ff6-175-101-36-4.ngrok.io",
  flushQueueSize: 30,
  dbCountThreshold: 10000,
  configRefreshInterval: 2,
  logLevel: 0,
  sleepTimeOut: 10,
  trackLifecycleEvents: true,
  recordScreenViews: true,
}, {
  integrations: {
    MixPanel: true,
    Amplitude: true
  }
})

Passing destinations during event calls

This approach is useful when you want to send particular events to specific destinations, or if you want to override the destinations specified during the SDK initialization for a particular event.

An example is shown below:

RudderClient.screen("Home Screen", {
  mobile: "pixel"
}, {
  integrations: {
    All: false,
    Salesforce: true
  }
})

In the above example, the values of the screen call are passed only to the Salesforce destination.

Anonymous ID

RudderStack uses the deviceId as anonymousId by default. You can use the putAnonymousId method to override the default anonymousId, as shown:

RudderClient.putAnonymousId("CustomAnonymousId");

Setting the advertisement ID

RudderClient.initialize(WRITE_KEY , {
  dataPlaneUrl: DATA_PLANE_URL,
  loglevel: RudderClient.LogLevel.VERBOSE,
  autoCollectAdvertId: true,
})

To set the advertisement ID yourself, you can use the putAdvertisingId method as shown:

RudderClient.putAdvertisingId("SampleAdvertisingId")

In iOS, you need to call the putAdvertisingId method before calling initialize.

Setting the device token

You can pass your device-token for push notifications to be passed to the destinations which support the Push Notifications feature. RudderStack sets the token under context.device.token.

An example of setting the device-token is as shown:

RudderClient.putDeviceToken("sampleDeviceToken");

Debugging

If you face any unexpected behavior while using the SDK, you can turn on the VERBOSE or DEBUG logging feature to determine out the issue.

You configure logging behavior of your SDK by sending the value of the logLevel property of the configuration object and pass it over to the initialize call as shown below:

RudderClient.initialize( WRITE_KEY , {
  dataPlaneUrl: DATA_PLANE_URL ,
  logLevel: RudderClient.LogLevel.VERBOSE,
  trackLifecycleEvents: true
})

FAQs

Where can I find the source write key?

Where can I find the data plane URL?

Contact us

Check the section below for detailed information on the parameters you can send in the configuration object.

Check the section below for detailed information on the parameters you can send in the options object.

Check the section below for detailed information on the parameters you can send in the options object.

Check the section below for detailed information on the parameters you can send in the options object.

Check the section below for detailed information on the parameters you can send in the options object.

Check the section below for detailed information on the parameters you can send in the options object.

Check the section below for detailed information on the parameters you can send in the options object.

For a detailed explanation of the alias call, refer to the guide.

Each key within the integrations object should hold the display name of your desired destination. Its value should be a boolean indicating whether you want to send that event or not. For more details check the section below.

When sending events to a destination via the , you can explicitly specify which events should be discarded or allowed to flow through - by whitelisting or blacklisting them.

Refer to the guide for more information on this feature.

RudderStack collects the advertisement ID only if autoCollectAdvertId is set to true during the , as shown:

Once you set up a Cordova source in the , you will be able to view the source Write Key, under the Overview section, as shown:

Refer to this for more information on the data plane and how to get it.

For queries on any of the sections covered in this guide, you can or start a conversation in our community.

If you come across any issues while using the Cordova SDK, you can open a new issue on our .

Configuring the options object
Configuring the options object
Configuring the options object
Configuring the options object
Configuring the options object
RudderStack API Specification
device mode
Client-side Event Filtering
RudderStack dashboard
section
contact us
Slack
GitHub Issues page
Configuring the RudderStack Client
Configuring the options object
SDK initialization
https://hosted.rudderlabs.com
Enabling/disabling events for specific destinations
Apache Cordova
GitHub codebase
sample implementation
RudderStack account
this guide
this section
Github Badge
Cordova source write key
Cordova source write key