Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Add getters for anonymousID, attributionID and advertiserID #805

Merged
merged 2 commits into from Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,7 @@

import com.facebook.appevents.AppEventsConstants;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.internal.AttributionIdentifiers;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand Down Expand Up @@ -109,6 +110,7 @@ public class FBAppEventsLoggerModule extends ReactContextBaseJavaModule {
public static final String NAME = "FBAppEventsLogger";

private AppEventsLogger mAppEventLogger;
private AttributionIdentifiers mAttributionIdentifiers;
private ReactApplicationContext mReactContext;

public FBAppEventsLoggerModule(ReactApplicationContext reactContext) {
Expand All @@ -119,6 +121,7 @@ public FBAppEventsLoggerModule(ReactApplicationContext reactContext) {
@Override
public void initialize() {
mAppEventLogger = AppEventsLogger.newLogger(mReactContext);
mAttributionIdentifiers = AttributionIdentifiers.getAttributionIdentifiers(mReactContext);
}

@Override
Expand Down Expand Up @@ -216,6 +219,40 @@ public String getUserID() {
return mAppEventLogger.getUserID();
}

/**
* Each app/device pair gets an GUID that is sent back with App Events and persisted with this
* app/device pair.
*
* @return The GUID for this app/device pair.
*/
@ReactMethod(isBlockingSynchronousMethod = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make all the functions not blocking and use the promise API since they are async in JS anyway.

@Nullable
public String getAnonymousID() {
return mAppEventLogger.getAnonymousAppDeviceGUID(mReactContext);
}

/**
* Returns the advertiser id or null if not set
*
* @return The advertiser ID or null
*/
@ReactMethod(isBlockingSynchronousMethod = true)
@Nullable
public String getAdvertiserID() {
return mAttributionIdentifiers.getAndroidAdvertiserId();
}

/**
* Returns the attribution id or null if not set
*
* @return The attribution ID or null
*/
@ReactMethod(isBlockingSynchronousMethod = true)
@Nullable
public String getAttributionID() {
return mAttributionIdentifiers.getAttributionId();
}

/**
* Sends a request to update the properties for the current user, set by
* setUserID. You must call setUserID before making this call.
Expand Down
11 changes: 11 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKAppEvents.m
Expand Up @@ -21,6 +21,7 @@
#import <React/RCTUtils.h>

#import "RCTConvert+FBSDKAccessToken.h"
#import "FBSDKCoreKit/FBSDKAppEventsUtility.h"

@implementation RCTConvert (RCTFBSDKAppEvents)

Expand Down Expand Up @@ -81,6 +82,16 @@ - (dispatch_queue_t)methodQueue
return [FBSDKAppEvents userID];
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getAnonymousID)
{
return [FBSDKAppEvents anonymousID];
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getAdvertiserID)
{
return [FBSDKAppEventsUtility advertiserID];
}

RCT_EXPORT_METHOD(updateUserProperties:(NSDictionary *)parameters)
{
parameters = RCTDictionaryWithoutNullValues(parameters);
Expand Down
26 changes: 26 additions & 0 deletions src/FBAppEventsLogger.js
Expand Up @@ -23,6 +23,7 @@
'use strict';

const AppEventsLogger = require('react-native').NativeModules.FBAppEventsLogger;
const {Platform} = require('react-native');
/**
* Controls when an AppEventsLogger sends log events to the server
*/
Expand Down Expand Up @@ -126,6 +127,31 @@ module.exports = {
return await AppEventsLogger.getUserID();
},

/**
* Returns anonymous id or null if not set
*/
async getAnonymousID(): Promise<?string> {
return await AppEventsLogger.getAnonymousID();
},

/**
* Returns advertiser id or null if not set
*/
async getAdvertiserID(): Promise<?string> {
return await AppEventsLogger.getAdvertiserID();
},

/**
* Returns advertiser id or null if not set.
* @platform android
*/
async getAttributionID(): Promise<?string> {
if (Platform.OS === 'ios') {
return null;
}
return await AppEventsLogger.getAttributionID();
},

/**
* Sends a request to update the properties for the current user, set by
* setUserID. You must call setUserID before making this call.
Expand Down