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

InAppMessaging.onMessageReceived listener called twice and the message_displayed event was sent many times #11793

Closed KevinToala closed 1 year ago

KevinToala commented 1 year ago

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Analytics

Amplify Categories

analytics, notifications

Environment information

``` # Put output below this line System: OS: macOS 13.4.1 CPU: (10) arm64 Apple M1 Max Memory: 1.63 GB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm Browsers: Chrome: 115.0.5790.170 Safari: 16.5.2 npmPackages: @angular-devkit/build-angular: ^16.2.0 => 16.2.0 @angular/animations: ^16.2.0 => 16.2.0 @angular/cli: ~16.2.0 => 16.2.0 @angular/common: ^16.2.0 => 16.2.0 @angular/compiler: ^16.2.0 => 16.2.0 @angular/compiler-cli: ^16.2.0 => 16.2.0 @angular/core: ^16.2.0 => 16.2.0 @angular/forms: ^16.2.0 => 16.2.0 @angular/platform-browser: ^16.2.0 => 16.2.0 @angular/platform-browser-dynamic: ^16.2.0 => 16.2.0 @angular/router: ^16.2.0 => 16.2.0 @types/jasmine: ~4.3.0 => 4.3.5 aws-amplify: 5.3.6 => 5.3.6 jasmine-core: ~4.6.0 => 4.6.0 karma: ~6.4.0 => 6.4.2 karma-chrome-launcher: ~3.2.0 => 3.2.0 karma-coverage: ~2.2.0 => 2.2.1 karma-coverage-coffee-example: 1.0.0 karma-jasmine: ~5.1.0 => 5.1.0 karma-jasmine-html-reporter: ~2.1.0 => 2.1.0 rxjs: ~7.8.0 => 7.8.1 rxjs/ajax: undefined () rxjs/fetch: undefined () rxjs/operators: undefined () rxjs/testing: undefined () rxjs/webSocket: undefined () tslib: ^2.3.0 => 2.6.1 (1.14.1) typescript: ~5.1.3 => 5.1.6 zone-mix: undefined () zone-node: undefined () zone-testing: undefined () zone.js: ~0.13.0 => 0.13.1 zone.js/async-test: undefined () zone.js/async-test.min: undefined () zone.js/fake-async-test: undefined () zone.js/fake-async-test.min: undefined () zone.js/jasmine-patch: undefined () zone.js/jasmine-patch.min: undefined () zone.js/long-stack-trace-zone: undefined () zone.js/long-stack-trace-zone.min: undefined () zone.js/mocha-patch: undefined () zone.js/mocha-patch.min: undefined () zone.js/proxy: undefined () zone.js/proxy.min: undefined () zone.js/sync-test: undefined () zone.js/sync-test.min: undefined () zone.js/task-tracking: undefined () zone.js/task-tracking.min: undefined () zone.js/webapis-media-query: undefined () zone.js/webapis-media-query.min: undefined () zone.js/webapis-notification: undefined () zone.js/webapis-notification.min: undefined () zone.js/webapis-rtc-peer-connection: undefined () zone.js/webapis-rtc-peer-connection.min: undefined () zone.js/webapis-shadydom: undefined () zone.js/webapis-shadydom.min: undefined () zone.js/wtf: undefined () zone.js/wtf.min: undefined () zone.js/zone-bluebird: undefined () zone.js/zone-bluebird.min: undefined () zone.js/zone-error: undefined () zone.js/zone-error.min: undefined () zone.js/zone-legacy: undefined () zone.js/zone-legacy.min: undefined () zone.js/zone-patch-canvas: undefined () zone.js/zone-patch-canvas.min: undefined () zone.js/zone-patch-cordova: undefined () zone.js/zone-patch-cordova.min: undefined () zone.js/zone-patch-electron: undefined () zone.js/zone-patch-electron.min: undefined () zone.js/zone-patch-fetch: undefined () zone.js/zone-patch-fetch.min: undefined () zone.js/zone-patch-jsonp: undefined () zone.js/zone-patch-jsonp.min: undefined () zone.js/zone-patch-message-port: undefined () zone.js/zone-patch-message-port.min: undefined () zone.js/zone-patch-promise-test: undefined () zone.js/zone-patch-promise-test.min: undefined () zone.js/zone-patch-resize-observer: undefined () zone.js/zone-patch-resize-observer.min: undefined () zone.js/zone-patch-rxjs: undefined () zone.js/zone-patch-rxjs-fake-async: undefined () zone.js/zone-patch-rxjs-fake-async.min: undefined () zone.js/zone-patch-rxjs.min: undefined () zone.js/zone-patch-socket-io: undefined () zone.js/zone-patch-socket-io.min: undefined () zone.js/zone-patch-user-media: undefined () zone.js/zone-patch-user-media.min: undefined () npmGlobalPackages: @aws-amplify/cli: 12.2.3 @ionic/cli: 6.20.5 aws-cdk: 2.89.0 corepack: 0.12.1 npm: 8.15.0 ```

Describe the bug

In our project with Angular/Ionic/Capacitor we are presenting duplication in the metrics of our InApp message campaigns with aws pinpoint. Reviewing a little more, it seems that the InAppMessaging.onMessageReceived listener is being called twice and when sending the MESSAGE_DISPLAYED event, it is being sent several times to aws pinpoint.

Initially I thought it was some problem with the configurations of our project, for this reason I created a project from scratch with the minimum configurations and I see the same behavior, apparently this behavior is seen from versions equal to or greater than 5.3.6 of aws-amplify

Expected behavior

If I have a campaign created in AWS Pinpoint for an InApp message it should only receive it once in the InAppMessaging.notifyMessageInteraction listener, the MESSAGE_DISPLAYED event should only be sent once and the InApp campaign metrics should not be duplicated in aws Pinpoint.

If I change to version 5.3.5 this works very well and the calls to the listener and the events are not duplicated

Reproduction steps

response inapp sync in app displayed events duplicate call listener

Code Snippet

The project to reproduce the bug is here: https://github.com/KevinToala/aws-amplify-inapp-issue

You just have to run the commands:

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

{
  Auth: {
    region: 'us-east-1',
    userPoolId: 'us-east-1_????????',
    userPoolWebClientId: '?????????',
    identityPoolId: 'us-east-1:????????'
  },
  Analytics: {
    AWSPinpoint: {
      appId: '==============',
      region: 'us-east-1',
      mandatorySignIn: false,
    }
  },
  Notifications: {
    InAppMessaging: {
      AWSPinpoint: {
        appId: '==============',
        region: 'us-east-1',
      }
    }
  },
};

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

cwomack commented 1 year ago

@KevinToala, thank you for opening this issue. We're looking into this and reviewing the root cause of the duplicated calls and events. I'll update this issue as soon as we have additional information or progress!

stocaaro commented 1 year ago

@KevinToala,

We have reverted the change that introduced this issue and have done some verification on our side. Can you confirm that with the latest release your issue has been fixed?

KevinToala commented 1 year ago

Hi @stocaaro

I can confirm that with version 5.3.10 there are no duplicate events 👍

image

image

cwomack commented 1 year ago

@KevinToala, thank you for the confirmation! We'll close this issue then for now, but if you see it happen again let us know. Thanks!