How can I record an aws pinpoint event from angular 8

369 views Asked by At

I'm trying to record an event, from angular to AWS, when the AuthComponent is loaded in the browser. It's printed to the console as undefined. And this console.log is the one in the (then) AnalyticsService file. The browser doesn't show an error and I can't see the log in AWS PP, am I missing any settings?

These would be my environment.ts and environment.test.ts

amplify: {
    ...
    Analytics: {
      disabled: false,
      autoSessionRecord: true,
      AWSPinpoint: {
        appId: 'lorem',
        region: 'ipsum',
        mandatorySignIn: false,
        autoSessionRecord: true,
        endpointId: null
      }
    }
  },

this is where I try to have the event recorded auth.component.ts

export class AuthComponent implements OnInit {

  constructor(private analyticsService: AnalyticsService) { }

  ngOnInit() {
    this.analyticsService.logevent('CUSTOMER_FIRST_EVENT', {});
  }

}

and analytics.service.ts

export class AnalyticsService {
  constructor() {}

  logevent(eventname: string, data: any) {
      let record = {
        name: eventname,
        attributes: data
      };
      console.log({logevent: record});
      Analytics.record(record)
        .then(e => {
          console.log(e);
        })
        .catch(err => {
          console.log(err);
        });
  }
}
1

There are 1 answers

0
Odisleysi Martínez Furones On

In the roles associated with the cognito pool for anonymous and authenticated users, add to the policy, the "mobiletargeting: UpdateEndpoint" permission, also check that the environments, that you want to be record, have disabled:false and autoSessionRecord:true inside the Analytics object.