I am new to Magento..I have successfully created a popup using modal widget in customer_account_index.xml, but this popup works only when customer clicks on My account tab. I am looking for complete code that will show a popup with customerId. Once user clicks the popup, it should redirect to a specific url. Following code is not useful to me now as I need the popup only once right after the user logs in. I have researched about customer_login event, but none of the solutions worked for me.
My phtml file looks like this
<div id="modal-content"></div>
<script>
require(
[
'jquery',
'Magento_Ui/js/modal/modal'
],
function($, modal) {
let customerId = "<?php echo $id; ?>";
alert(customerId);
const ajaxUrl = customurl;
const redirectUrl = redirecturl;
const title = sometitle;
let options = {
type: 'popup',
responsive: true,
innerScroll: true,
title: title,
buttons: [{
text: $.mage.__('OK'),
class: 'modal-close',
textalign: 'center',
click: function (){
window.location.href = redirectUrl;
this.closeModal();
}
}]
};
modal(options, $('#modal-content'));
$( window ).load(function() {
$("#modal-content").modal("openModal");
});
}
}
});````