@heymike/ads-core
v0.1.1
Published
Platform-agnostic core for the heymike-ads cross-marketing SDK.
Readme
@heymike/ads-core
Platform-agnostic core for the heymike-ads
cross-marketing SDK. Most apps use @heymike/ads-web or
@heymike/ads-react-native instead — this package holds the shared
client, types, and helpers they build on.
npm install @heymike/ads-coreUsage
import { createAdClient, BannerType } from '@heymike/ads-core';
const client = createAdClient({
app: 'com.example.myapp', // this app's bundle id or domain
// baseUrl defaults to https://ads.heymike.io — pass baseUrl to point elsewhere.
});
const ad = await client.fetchAd({ bannerType: BannerType.SQUARE });
if (ad) {
// render ad.imageUrl, then on tap open the tracked link:
// window.open(ad.clickUrl) / Linking.openURL(ad.clickUrl)
// and record the view:
await client.trackImpression(ad);
}The client automatically:
- generates and persists an anonymous
adUserId(via a pluggableStorageAdapter); - detects platform (
web) and device language; - sends
app,bannerType,platform,language, andadUserIdto the server, which addscountryfrom the request IP.
API
| Export | Description |
| -------------------------------------------------------- | ---------------------------------------------------------------------- |
| createAdClient(config) | Create an AdClient. |
| client.fetchAd({ bannerType }) | Fetch one ad, or null. |
| client.fetchAds({ bannerType, count }) | Fetch several ads. |
| client.trackImpression(ad) | Record an impression (native beacon). |
| client.getClickUrl(ad) | The tracked redirect URL to open on tap. |
| BannerType | SQUARE, MEDIUM_RECTANGLE, BANNER, LEADERBOARD, INTERSTITIAL. |
| StorageAdapter, memoryStorage, localStorageAdapter | Persistence helpers. |
License
MIT
