Mobile SDKsCapacitor (Ionic)

Capacitor SDK (Ionic)

The Datafly Signal Capacitor plugin wraps the native iOS and Android SDKs for Ionic and Capacitor applications.

Requirements

  • Capacitor 5+
  • iOS 15+ / Android API 21+

Installation

npm install @datafly/capacitor
npx cap sync

Initialisation

import { DataflySignal } from '@datafly/capacitor';
 
DataflySignal.initialize({
  pipelineKey: 'dk_live_abc123',
  endpoint: 'https://data.example.com',
});

Usage

import { DataflySignal } from '@datafly/capacitor';
 
// Track a screen view
await DataflySignal.screen({ name: 'Home' });
 
// Track a custom event
await DataflySignal.track({
  event: 'add_to_cart',
  properties: {
    item_id: 'SKU-001',
    item_name: 'Running Shoes',
    price: 79.99,
    currency: 'GBP',
  },
});
 
// Identify a user
await DataflySignal.identify({
  userId: 'user-123',
  traits: { email: '[email protected]', name: 'Jane Doe' },
});
 
// Associate with a company
await DataflySignal.group({
  groupId: 'company-456',
  traits: { name: 'Acme Corp' },
});
 
// Set consent
await DataflySignal.setConsent({
  categories: { analytics: true, marketing: false },
});
 
// Handle deep link
await DataflySignal.handleDeepLink({ url: 'https://example.com?gclid=abc123' });
 
// Force flush
await DataflySignal.flush();
 
// Logout
await DataflySignal.reset();
 
// Get anonymous ID
const { anonymousId } = await DataflySignal.getAnonymousId();

Ionic Angular integration

import { Component } from '@angular/core';
import { DataflySignal } from '@datafly/capacitor';
import { Router, NavigationEnd } from '@angular/router';
 
@Component({ selector: 'app-root', templateUrl: 'app.component.html' })
export class AppComponent {
  constructor(private router: Router) {
    this.router.events.subscribe(event => {
      if (event instanceof NavigationEnd) {
        DataflySignal.screen({ name: event.urlAfterRedirects });
      }
    });
  }
}

The Capacitor plugin bridges to the native Datafly SDKs via CAPPlugin (iOS) and Capacitor’s Android plugin API. All event processing runs natively. A web fallback stub is included for browser testing during development.

Configuration

See Configuration for all available options.