capacitor-facebook
v1.1.1
Published
Facebook sdk plugin for capacitor
Downloads
34
Readme
capacitor-facebook
Facebook sdk plugin for capacitor.
Install
npm install capacitor-facebook
npx cap sync
Available methods:
- logEvent(name: string, params?: LogEventParams): Promise;
- setAdvertiserTracking(enabled: boolean): Promise;
- getAdvertiserTrackingStatus(): Promise;
- setAutoLogAppEvents(enabled: boolean): Promise;
- setAdvertiserIDCollection(enabled: boolean): Promise;
- setAudienceNetworkAdvertiserTracking(enabled: boolean): Promise;
- getAnonymousID(): Promise;
Usage example:
Setup your app on facebook developer console and follow the instructions here (except the step 1) https://developers.facebook.com/docs/ios/getting-started
In your module (e.g.
app.module.ts
)
...
import { Facebook } from 'capacitor-facebook'
@NgModule({
...
providers: [
...
Facebook,
],
})
export class AppModule {}
- In your component or service (e.g.
analytics.service.ts
)
import {
AppTrackingTransparency,
AppTrackingTransparencyStatus,
} from 'capacitor-app-tracking-transparency'
import { Facebook } from 'capacitor-facebook';
@Injectable()
export class AnalyticsService {
constructor(private facebook: Facebook, private att: AppTrackingTransparency) {}
async logEvent(name: string, params?: Object) {
let _params = {
...params
valueToSum: 20,
}
return this.facebook.logEvent(name, _params);
}
async requestAtt() {
const attStatus = await this.att.requestPermission()
const enabled = attStatus === AppTrackingTransparencyStatus.authorized
await this.facebook.setAdvertiserTracking(enabled);
await this.facebook.setAudienceNetworkAdvertiserTracking(enabled);
await this.facebook.setAutoLogAppEvents(enabled);
await this.facebook.setAdvertiserIDCollection(enabled);
}
async getAdvertiserTrackingStatus() {
return this.facebook.getAdvertiserTrackingStatus();
}
async init() {
const anonymousId = await this.facebook.getAnonymousID();
console.log('anonymousId', anonymousId);
}
}
BREAKING CHANGES in 1.x.x
- Add support for capacitor 5