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 syncInitialisation
import { Datafly } from '@datafly/capacitor';
Datafly.initialize({
pipelineKey: 'dk_live_abc123',
endpoint: 'https://data.example.com',
});Usage
import { Datafly } from '@datafly/capacitor';
// Track a screen view
await Datafly.screen({ name: 'Home' });
// Track a custom event
await Datafly.track({
event: 'add_to_cart',
properties: {
item_id: 'SKU-001',
item_name: 'Running Shoes',
price: 79.99,
currency: 'GBP',
},
});
// Identify a user
await Datafly.identify({
userId: 'user-123',
traits: { email: 'jane@example.com', name: 'Jane Doe' },
});
// Associate with a company
await Datafly.group({
groupId: 'company-456',
traits: { name: 'Acme Corp' },
});
// Set consent
await Datafly.setConsent({
categories: { analytics: true, marketing: false },
});
// Handle deep link
await Datafly.handleDeepLink({ url: 'https://example.com?gclid=abc123' });
// Force flush
await Datafly.flush();
// Logout
await Datafly.reset();
// Get anonymous ID
const { anonymousId } = await Datafly.getAnonymousId();Ionic Angular integration
import { Component } from '@angular/core';
import { Datafly } 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) {
Datafly.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.