smartlinks_ad 1.3.1
smartlinks_ad: ^1.3.1 copied to clipboard
A Flutter package for Linklytics SmartLinks Ads.
smartlinks_ad #
A Flutter package for integrating Linklytics SmartLinks Ads into your mobile applications. This package provides easy-to-use widgets for displaying Banner, Interstitial, and Native ads powered by the Linklytics ad network.
Features #
- Banner Ads: Configurable banner widgets linked to SmartLinks.
- Interstitial Ads: Full-screen ads with frequency capping.
- Native Ads: Builder-pattern widgets for completely custom UI.
- Smart Logic: Frequency capping and scheduling support.
- Analytics: Built-in tracking for impressions and clicks.
- Offline Reliability: Batch analytics events securely locally when offline, and sync to backend when network connectivity is restored.
Installation #
Add smartlinks_ad to your pubspec.yaml:
dependencies:
smartlinks_ad:
git:
url: https://gitlab.com/elmansoryanas/smartlinks_ad.git
ref: main
Usage #
1. Initialize the SDK #
Initialize the service with your API Key in your main.dart or before using any ad widgets.
import 'package:smartlinks_ad/smartlinks_ad.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// (Optional) Initialize Firebase BEFORE smartlinks_ad if you want Push Notifications
// await Firebase.initializeApp();
// Initialize the ad service
final adService = SmartLinksAd();
await adService.initialize('YOUR_API_KEY');
// Initialize Push Handler (requires Firebase to be initialized)
await SmartLinksPushHandler.initialize(apiKey: 'YOUR_API_KEY');
runApp(MyApp());
}
Note: You can obtain the API Key from the Linklytics Dashboard (Profile Settings -> API Keys).
2. Banner Ad #
Display a banner ad anywhere in your widget tree.
SmartLinkBannerAd(
adService: adService,
height: 100, // Optional: override default height for the selected banner size
fit: BoxFit.cover, // Optional: default is BoxFit.cover
)
3. Interstitial Ad #
Interstitial ads are full-screen ads that cover the interface of their host app.
// Create an instance
final interstitial = SmartLinkInterstitialAd(adService: adService);
// Load the ad
await interstitial.load();
// Check if loaded and show
if (interstitial.isLoaded) {
interstitial.show(context, onDismissed: () {
print('Ad dismissed');
});
}
4. Native Ad #
Native ads allow you to customize the look and feel of the ads to match your app's design.
SmartLinkNativeAd(
adService: adService,
builder: (context, ad) {
return Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [BoxShadow(blurRadius: 4, color: Colors.black12)],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(ad.name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
SizedBox(height: 8),
if (ad.config['image_url'] != null)
ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Image.network(ad.config['image_url'], height: 150, width: double.infinity, fit: BoxFit.cover),
),
SizedBox(height: 8),
Text(ad.config['description'] ?? '', style: TextStyle(fontSize: 14)),
SizedBox(height: 8),
ElevatedButton(
onPressed: () => ad.handleClick(context), // Handle click tracking and navigation
child: Text(ad.config['cta_text'] ?? 'Learn More'),
),
],
),
);
},
)
Requirements #
- Flutter >=3.3.0
- Dart >=3.0.0
License #
MIT