Skip to main content

Hi all, 

 

We're using the out-of-the-box Google Analytics (GA4) integration in our Experience Cloud site. Does anyone know how to send custom salesforce fields to GA4? We want to track more information about our members including the name of the Salesforce profile. This will allow us to get a breakdown of logins by user type. Thanks!

 

Best,

Kevin

 

#Experience Cloud

5 respuestas
  1. 5 mar 2024, 9:16

    @Kevin Dyer

    If I understood correctly, you need to pass user data to GA4. And data payload should be populated dynamically containing current user info. I believe you can do that with component JS. 

    import { LightningElement } from 'lwc';

    import { getRecord } from 'lightning/uiRecordApi';

    import Id from '@salesforce/user/Id';

    import isGuest from '@salesforce/user/isGuest';

    import UserNameFIELD from '@salesforce/schema/User.Name';

    import userEmailFIELD from '@salesforce/schema/User.Email';

    import userIsActiveFIELD from '@salesforce/schema/User.IsActive';

    import userAliasFIELD from '@salesforce/schema/User.Alias';

    export default class AnalyticsSupport extends LightningElement {

    error;

    @track payload = {}

    @track error;

    @wire(getRecord, { recordId: Id, fields: [UserNameFIELD, userEmailFIELD, userIsActiveFIELD, userAliasFIELD ]})

    currentUserInfo({error, data}) {

    if (data) {

    this.payload = {

    detail:

    {

    'user_id': Id,

    'user_properties': {

    'user_id': Id,

    'user_type': (isGuest) ? 'Unauthenticated' : 'Authenticated',

    'user_name': data.fields.Name.value,

    'user_email': data.fields.Email.value,

    'user_isActive': data.fields.IsActive.value,

    'user_alias': data.fields.Alias.value

    }

    }

    } else if (error) {

    this.error = error ;

    }

    }

    }

    connectedCallback()

    {

    //publish custom event for the listener in the head markup to handle

    document.dispatchEvent(new CustomEvent('analyticsSupport', payload));

    }

    }

0/9000