Попробуйте это, вам нужно будет использовать querySelectorAll, который вернет список.
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
<!-- ONE -->
<ins class='adsbygoogle' style='display:block' data-ad-client='ca-pub-XXXXXXXXXXXXXXX' data-ad-format='auto'
data-full-width-responsive='true'></ins>
<!-- TWO -->
<ins class='adsbygoogle' style='display:block' data-ad-client='ca-pub-XXXXXXXXXXXXXXX' data-ad-format='auto'
data-full-width-responsive='true'></ins>
<script>
window.addEventListener('load', (event) => {
var x = 123456789;
var elems = document.querySelectorAll('.adsbygoogle');
elems.forEach((elem) => {
elem.dataset.adSlot = x;
console.log(elem);
});
});
</script>
</body>
</html>
Вывод:
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-XXXXXXXXXXXXXXX" data-ad-format="auto" data-full-width-responsive="true" data-ad-slot="123456789"></ins>
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-XXXXXXXXXXXXXXX" data-ad-format="auto" data-full-width-responsive="true" data-ad-slot="123456789"></ins>