aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

AWSPinpointProvider - updateEndPoint failed TypeError: undefined is not a function #8076

Closed b-tiwari closed 1 year ago

b-tiwari commented 3 years ago

Before opening, please confirm:

I have searched for duplicate or closed issues and discussions. I have read the guide for submitting bug reports. I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

JavaScript Framework

React Native

Amplify APIs

Authentication, Analytics, REST API, Push Notifications

Amplify Categories

No response

Environment information

``` # Put output below this line System: OS: macOS 11.0.1 CPU: (4) x64 Intel(R) Core(TM) i5-4260U CPU @ 1.40GHz Memory: 59.96 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 12.14.0 - ~/.nvm/versions/node/v12.14.0/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.13.4 - ~/.nvm/versions/node/v12.14.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Brave Browser: 89.1.22.67 Chrome: 89.0.4389.114 Chrome Canary: 92.0.4474.0 Safari: 14.0.1 npmGlobalPackages: @aws-amplify/cli: 4.46.1 npm: 6.13.4 serverless: 2.30.3 typescript: 3.7.4 ```

Describe the bug

Getting error AWSPinpointProvider - updateEndpoint failed [TypeError: undefined is not a function] when calling Analytics.updateEndpoint in my App.js useEffect

await Analytics.updateEndpoint({
        address: '17801234567',
        channelType: 'FCM',
        attributes: {
          serviceUsage: ['personal'],
        },
        userId: 'someUserId',
        userAttributes: {
          username: 'someUserName1'
        }
});

Expected behavior

should not get the error and the endpoint should get registered with AWSPinPoint

Reproduction steps

setup Amplify Pushnotification , Firebase, andriod code as documented in Amplify docs

amplify init
amplify add notifications
amplify push

Code Snippet

// Put your code below this line.
import React, { useEffect } from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Analytics } from 'aws-amplify';
import { ServiceConfigs, PushNotificationsUtils } from '../utils';
import ThemedApp from './ThemedApp';
...

ServiceConfigs.AmplifyConfig(); //  this configs Amplify as show in 'Configuration' section below
PushNotificationsUtils.setHandlers(); // callback handlers for PushNotification events

const App = () => {

  const updateEndpoint = async () => {
    try {
      const data = await Analytics.updateEndpoint({
        address: getUniqueId(),
        channelType: 'FCM',
        attributes: {
          plan: ['basic'],
        },
        userId: 'someUserId1',
        userAttributes: {
          username: 'someUserName1'
        }
      });
      console.log('------- Analytics.updateEndpoint return data=', data);
    } catch (err) {
      console.log('-------  ERROR at Analytics.updateEndpoint=', err);
      throw err;
    }
  }

  useEffect(() => {
    const awsPluggable = Analytics.getPluggable('AWSPinpoint');

    console.log('category = ', awsPluggable.getCategory());
    console.log('provider = ', awsPluggable.getProviderName());

    const setAnalyticsEndpoint = async () => {
      await updateEndpoint();
    }
    setAnalyticsEndpoint();

  }, []);

  // component's return JSX
  return (
    <SafeAreaProvider>
      ....
    </SafeAreaProvider>
  );
};

export default App;

Log output

``` // Put your logs below this line [Sun Apr 11 2021 09:11:02.909] LOG category = Analytics [Sun Apr 11 2021 09:11:02.909] LOG provider = AWSPinpoint [Sun Apr 11 2021 09:11:04.301] ERROR [ERROR] 41:03.184 AWSPinpointProvider - updateEndpoint failed [TypeError: undefined is not a function] [Sun Apr 11 2021 09:11:04.332] LOG ------- ERROR at Analytics.updateEndpoint= [TypeError: undefined is not a function] [Sun Apr 11 2021 09:11:04.496] WARN Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not a function TypeError: undefined is not a function at serializeAws_restJson1ListOf__string (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:177722:24) ```

aws-exports.js

aws-export.js
const awsmobile = {
    "aws_project_region": "us-east-1",
    "aws_cognito_identity_pool_id": "us-east-1:xxxxx",
    "aws_cognito_region": "us-east-1",
    "oauth": {},
    "aws_mobile_analytics_app_id": "xxxxxxx",
    "aws_mobile_analytics_app_region": "us-east-1"
};

Manual configuration

Configuring Amplify:
import Amplify from 'aws-amplify';
import awsExports from '../aws-exports';

Amplify.configure({
        ...awsExports,
        // tried adding below props, when simply using awsExports was giving the same error
        Auth: {
            identityPoolId: 'us-east-1:xxx-xxx-xxx-xxx-xxx',
            region: 'us-east-1',
            mandatorySignIn: false
        },
        PushNotification: {
            appId: 'xxxxx',
            requestIOSPermissions: false,
        },
        Analytics: {
            AWSPinpoint: {
                // Amazon Pinpoint App Client ID
                appId: 'xxxxx',
                // Amazon service region
                region: 'us-east-1',
                mandatorySignIn: false,
            }
        }
    });
};

Additional configuration

No response

Mobile Device

Honor View 10 BLN-L04

Mobile Operating System

Android version 9

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

1

No response

michaelgmcd commented 3 years ago

When in doubt, check versions. Downgrading analytics to v4 worked for me @b-tiwari

michaelgmcd commented 3 years ago

Related, @chrisbonifacio is there an upcoming v5 release for core and pushnotification?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

michaelgmcd commented 3 years ago

@chrisbonifacio any update? Would love to move to v5 of analytics, but this is blocking me (and supposedly others)

DeniferSantiago commented 2 years ago

The same problem happens to me. image

image

dwamianm commented 2 years ago

Any update on this. We are currently unable to save custom userAttributes

Samaritan1011001 commented 2 years ago

@b-tiwari @dwamianm @DeniferSantiago Thank you for the inputs. Can you please try giving an array to the username or any other attribute field you may have in the userAttributes block? It's documented in the API reference. Thank you!

const user = await Auth.currentAuthenticatedUser()

    const endpoint = {
      address: "token",
      channelType: 'GCM',
      optOut:'NONE',
      userId: 'someUserId1',
      userAttributes: {
        username: [user.attributes.name],
        sub: [user.attributes.sub]
      },
      demographic: {
        AppVersion: '0.2.0'
      }
    }

    const data = await Analytics.updateEndpoint(endpoint)
DeniferSantiago commented 2 years ago

In the end I was able to make it work. I added the user attributes in an array (you must make sure to send valid values, filter the [undefined, null]), country changed it to a 2-digit value (ISO 3166-1) and optOut I put it in uppercase.

Thanks @Samaritan1011001

tannerabread commented 1 year ago

Hi 👋 Closing this as resolved. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with additional information so we can re-open this issue and be better able to assist you.

Thank you!