diegodfsd
4/24/2017 - 2:18 PM

gistfile1.txt

import { Component, OnInit } from '@angular/core';

import { SessionService } from '../shared/session.service';

@Component({
  selector: 'user-engage',
  templateUrl: './user-engage.component.html',
  styleUrls: ['./user-engage.component.scss']
})
export class UserEngageComponent implements OnInit {

  private apiKey: string = 'user-engage-key';

  constructor(private userSession: SessionService) { }

  ngOnInit() {
    this.userSession.currentUser.subscribe(profile => {
      const w: any = window;
      w.UE.resetAuth(this.getAuth(profile));
    });
  }

  private getAuth(profile: any): any {
    if (!profile) {
      return {
        apiKey: this.apiKey,
        name: "",
        email: ""
      };
    }
    return {
      apiKey: this.apiKey,
      name: profile.fullname,
      email: profile.email
    };
  }

}
  <script data-cfasync="false">
    window.civchat = {
      apiKey: "RnPwwO6i9FjR2jfUUZ25ojfvXBWZiYDdC0dzy2XNrj1MQIk8gjTRozQiXlRHcm30",
      name: "",
      email: ""
     };
   </script>
  <script data-cfasync="false" src="https://widget.userengage.io/widget.js"></script>