-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lazysizes doesn't work with native Google Tag Manager/Analytics video tracking #810
Comments
@WidgetsBurritos
However having the possibility to configure this is a good idea. How would call this option? It would also make sense to change this option on an element basis using attribute modification. Beside changing the Note: You can already now fully modify what lazysizes does without changing the source itself: // example 1: use `data-iframe-src` instead of `data-src`
window.addEventListener('lazybeforeunveil', ({target}) => {
if(target.dataset.iframeSrc) {
target.src = target.dataset.iframeSrc;
}
});
// or example 2: reimplement the wanted behavior and stop lazysizes from doing it
window.addEventListener('lazybeforeunveil', (e) => {
let src;
const target = {e};
if (target.matches('iframe') && (src = target.dataset.src)) {
e.preventDefault();
target.src = src;
target.classList.add('lazyloaded');
target.classList.remove('lazyload');
}
}); Another way would be to use the video plugin. |
Thanks for the heads up on the event listeners. I'll evaluate those methods. Those seems a bit more desirable than what I'm doing now. If you still are interested in making that feature configurable, I think maybe you could do something like
|
This was a useful change - thanks! |
Hi, |
Describe the bug
The lazysizes library doesn't work with native Google Tag Manager/Analytics youtube video tracking.
See https://www.analyticsmania.com/post/youtube-tracking-google-tag-manager-solved/ for some more information about some of the requirements.
The issue essentially comes down to this:
The reason it doesnt work is due to this code:
https://github.com/aFarkas/lazysizes/blob/gh-pages/lazysizes.js#L443-L449
Whenever the
try
succeeds, which happens in most modern browsers, it changes thehistorydestination of the iframe, but doesn't actually set the src attribute.To Reproduce
I don't presently have a URL where you can preview the behavior, as it's a combination of lazysizes/GA/GTM.
Steps to reproduce the behavior:
<script src="https://www.youtube.com/iframe_api">
What is the expected behavior
Google Analytics should be able to track videos through the default Google Tag Manager tags.
What happened instead
The tag never triggered because the
src
attribute was missing`.In what environment (browser/device etc.) does this bug happen/not happen:
Any browser that uses
elem.contentWindow.location.replace(src);
as described above.Specifically, I've seen it on Chrome 83 on MacOS.
I fixed it on my end by modifying
changeIframeSrc
to always useelem.src
. However, this doesn't feel like the best long-term solution (especially since I'm essentially opting out of future library updates this way).In my mind, it seems like it'd be helpful to let people opt-out of using
elem.contentWindow.location.replace
via some sort of configuration setting.s/history/destination/
)The text was updated successfully, but these errors were encountered: