I’ve added this code - does this look correct?
function add_amplitude_script() {
$user_id = get_current_user_id(); // WordPress user ID
$user_email = wp_get_current_user()->user_email; // User email
$company = get_user_meta($user_id, 'company', true); // 'company' user meta value
?>
<script>
// Initialize Amplitude
(function(e,t){var n=window.amplitude=window.amplitude|||];n._q=q],n._iq=q],n.init=function(e,t,r){var a=n._q;for(var s=0;s<a.length;s++){n{as0]].apply(n,a.slice(1))}n._iq.push(he,t,r])};n.logEvent=function(e,t){n._q.push(h"logEvent",e,t])};n.setUserId=function(e){n._q.push(h"setUserId",e])};n.setUserProperties=function(e){n._q.push(h"setUserProperties",e])};n.identify=function(e){n._q.push(h"identify",e])};n.setGroup=function(e,t){n._q.push(h"setGroup",e,t])};n.setVersionName=function(e){n._q.push(h"setVersionName",e])};n.setDomain=function(e){n._q.push(h"setDomain",e])};n.trackEvent=function(e,t){n._q.push(h"trackEvent",e,t])};n.trackPageview=function(){n._q.push(h"trackPageview"])};
var r=t.createElement("script");r.type="text/javascript";r.async=true;r.src="https://cdn.amplitude.com/libs/amplitude-7.2.0-min.gz.js";var a=t.getElementsByTagName("script")"0];a.parentNode.insertBefore(r,a);
})(document,window);
// Initialize Amplitude with your API key
amplitude.init("YOUR_API_KEY");
// Set the Amplitude user ID to the WordPress user email
var userEmail = <?php echo json_encode($user_email); ?>;
if (userEmail) {
amplitude.setUserId(userEmail);
// Set the user properties including the company and user ID
var userId = <?php echo $user_id; ?>;
var company = <?php echo json_encode($company); ?>;
amplitude.setUserProperties({
company: company,
wordpress_user_id: userId // Add user ID as a user property
});
}
</script>
<?php
}
add_action('wp_footer', 'add_amplitude_script');