How do I pass variable strings to a const object

91 Views Asked by At

I am integrating Trustpilot invitations into my receipt page using the following code provided by Trustpilot

<script> 
document.addEventListener('DOMContentLoaded', function() {
    const trustpilot_invitation = {
        recipientEmail: '[email protected]',
        recipientName: 'John',
        referenceId: 'Order_123',
        source: 'InvitationScript',
    };
    tp('createInvitation', trustpilot_invitation);
});

The email and name strings I will use contain spurious characters which I need to cleanse, using something like

var email = '<Actinic:Variable Name="InvoiceEmail"/>';    
email = email.replace('Email&#58;&nbsp;','');

How do I pass the cleansed strings back to the Trustpilot script?

1

There are 1 best solutions below

1
On BEST ANSWER

The '[email protected]' string in your above snippet can be replaced with whatever you want, be it a function call that returns a string, or just a string variable.

eg:

var badEmail = '<Actinic:Variable Name="InvoiceEmail"/>'

document.addEventListener('DOMContentLoaded', function() {
    const trustpilot_invitation = {
        recipientEmail: badEmail.replace('Email&#58;&nbsp;',''),
        recipientName: 'John',
        referenceId: 'Order_123',
        source: 'InvitationScript',
    };
    tp('createInvitation', trustpilot_invitation);
});