Skip to main content

Request flow

Installation

Add the dependency to your pubspec.yaml:
dependencies:
  reelevant_analytics:
    git:
      url: https://github.com/reelevant-tech/reelevant-sdk-flutter.git
      ref: main
Then run:
flutter pub get

Initialization

import 'package:reelevant_analytics/reelevant_analytics.dart';

final rlvt = ReelevantAnalytics(
  companyId: 'your-company-id',
  datasourceId: 'your-datasource-id',
  // Optional personalization config
  runnerUrl: 'https://reelevant.run',          // default
  runnerTimeout: Duration(seconds: 5),          // default
  fallback: FallbackStrategy.empty,             // default
);

// Set user identity (shared between analytics and personalization)
await rlvt.setUser('user@example.com');

Analytics (event tracking)

// Page view
await rlvt.send(rlvt.pageView(labels: {'lang': 'en'}));

// Product page
await rlvt.send(rlvt.productPage('product-123', labels: {'category': 'shoes'}));

// Purchase
await rlvt.send(rlvt.purchase(
  ids: ['p1', 'p2'],
  totalAmount: 99.99,
  labels: {},
  transId: 'order-456',
));

// Add to cart
await rlvt.send(rlvt.addCart(ids: ['p1'], labels: {}));

Personalization

Single workflow run

final result = await rlvt.run(RunOptions(
  workflowId: 'wf-hero',
  entrypoint: '43a490a0',
));

if (result.body is JsonRunContent) {
  final data = (result.body as JsonRunContent).content;
  renderCard(data);
} else if (result.body is HtmlRunContent) {
  final html = (result.body as HtmlRunContent).content;
  renderWebView(html);
} else if (result.body is ImageRunContent) {
  final bytes = (result.body as ImageRunContent).content;
  renderImage(bytes);
} else {
  showDefault();
}

Multiple workflows in parallel

final results = await rlvt.runAll([
  RunOptions(workflowId: 'wf-hero', entrypoint: 'entry1'),
  RunOptions(workflowId: 'wf-reco', entrypoint: 'entry2'),
]);
// results[0] corresponds to wf-hero, results[1] to wf-reco

Click tracking

// Fire-and-forget — registers the click without following redirects
await result.trackClick();

RunOptions

ParameterTypeRequiredDescription
workflowIdStringYesWorkflow ID from the platform
entrypointStringYesEntrypoint ID within the workflow
userIdString?NoOverride identity (default: auto-resolved from setUser() / device ID)
paramsMap<String, String>?NoAdditional URL parameters forwarded to the runner
localeString?NoLocale for content resolution
timeoutDuration?NoPer-call timeout override

RunResult

FieldTypeDescription
statusintHTTP status code (0 for fallback)
sourceRunSource.runner or .fallback
bodyRunContentDiscriminated content: JsonRunContent, HtmlRunContent, ImageRunContent, or EmptyRunContent
metadataMap<String, dynamic>Metadata from x-rlvt-output-node-metadata header
propertiesMap<String, dynamic>Properties from x-rlvt-output-properties header
runIdString?Workflow run ID for tracking correlation
executionPathList<String>Branch IDs taken during execution
redirectionUrlStringPre-built click-through URL

Fallback strategies

// Return empty result on error (default)
FallbackStrategy.empty

// Re-throw the error
FallbackStrategy.error

// Custom handler
ReelevantAnalytics(
  // ...
  fallbackHandler: (options, error) async {
    return RunResult(/* your fallback result */);
  },
);