Hi @user2679 
Thank you for waiting!
Here is the solution from our devs. This code should be added to this website:
<script>
const GA_ID = 'G-ID';
const WIDGET_SHARELINKS = [
'https://424fced7eaf54610b78443b39532b611.elf.site',
'https://www-denataylor-info.filesusr.com/html/51c037_d173a444fbfca888cc23f05a88993d52.html',
'https://7def5e9211194222ba8f6b0ce9bd2425.elf.site',
'https://www-denataylor-info.filesusr.com/html/51c037_e16bf0dbde7d9ff521c66abf09aff7e9.html',
]
const gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = `https://www.googletagmanager.com/gtag/js?id=${GA_ID}`;
document.head.appendChild(gtagScript);
const inlineScript = document.createElement('script');
inlineScript.textContent = `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_ID}', { debug_mode: true });
`;
document.head.appendChild(inlineScript);
window.addEventListener('message', function(event) {
const eventOrigin = new URL(event.origin)?.origin;
const allowedOrigins = WIDGET_SHARELINKS.map(link => {
try {
return new URL(link).origin;
} catch (e) {
return null;
}
}).filter(Boolean);
if (!allowedOrigins.includes(eventOrigin)) {
return;
};
const data = event.data;
if (!data || data.type !== 'ga-event') {
return;
};
const { action, category, label } = data.payload || {};
if (typeof ga !== 'undefined') {
ga('send', 'event', {
eventAction: action,
eventCategory: category,
eventLabel: label
});
}
if (typeof gtag !== 'undefined') {
gtag('event', action, {
'event_category': category,
'event_label': label
});
}
}, false);
</script>
This code should be added to this page:
<script>
const GA_ID = 'G-ID';
const WIDGET_SHARELINKS = [
'https://b190bd437ebc476c8c6fc456112c2261.elf.site',
'https://www-denataylor-info.filesusr.com/html/51c037_aa10e1fcddcd5968db85c080f7eb1652.html'
]
const gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = `https://www.googletagmanager.com/gtag/js?id=${GA_ID}`;
document.head.appendChild(gtagScript);
const inlineScript = document.createElement('script');
inlineScript.textContent = `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_ID}', { debug_mode: true });
`;
document.head.appendChild(inlineScript);
window.addEventListener('message', function(event) {
const eventOrigin = new URL(event.origin)?.origin;
const allowedOrigins = WIDGET_SHARELINKS.map(link => {
try {
return new URL(link).origin;
} catch (e) {
return null;
}
}).filter(Boolean);
if (!allowedOrigins.includes(eventOrigin)) {
return;
};
const data = event.data;
if (!data || data.type !== 'ga-event') {
return;
};
const { action, category, label } = data.payload || {};
if (typeof ga !== 'undefined') {
ga('send', 'event', {
eventAction: action,
eventCategory: category,
eventLabel: label
});
}
if (typeof gtag !== 'undefined') {
gtag('event', action, {
'event_category': category,
'event_label': label
});
}
}, false);
</script>
In both codes, you should replace G-ID on the 2nd line with your actual website ID for Google Analytics. This article will help you find your ID - Find your Google tag ID.
Finally, this script should be added to the Custom JS field on the Style tab of your widgets’ settings:
function sendGtagEventFromIframe(config) {
parent.postMessage({
type: 'ga-event',
payload: {
action: config.action,
category: config.category,
label: config.label,
}
}, '*');
}
function getTrackTitle(event) {
let el = event.target;
const trackContainer = el.closest('[class*="PlaylistItem__PlaylistItemComponent-sc"]');
if (!trackContainer) return;
const trackTitle = trackContainer.querySelector('[class*="PlaylistItem__Title-sc"]')?.textContent;
const trackArtist = trackContainer.querySelector('[class*="PlaylistItem__Author-sc"]')?.textContent;
return [trackTitle || '', trackArtist || ''].filter(Boolean).join(' - ');
}
document.addEventListener('click', function (event) {
const trackTitle = getTrackTitle(event);
const container = event.target.closest('[id*="eapps-audio-player-"]');
if (!container || !trackTitle) return;
const fullId = container.getAttribute('id');
const playerId = fullId.replace('eapps-audio-player-', '');
sendGtagEventFromIframe({
action: 'click',
category: `Elfsight Player (${playerId})`,
label: `Track clicked: (${trackTitle})`
});
}, true);
Please try it out and let me know if it helped 