I created an event impression promotion for google analytics, I have 2 events view_promotions
and also select_content
. In the report in GA for select_content
the data is correct, but for view_promotion
it is always 0. Is there something wrong with my code using push array like the code that I’ve made below?
const impressionBanner = [];
$(".banner-link").each(function(){
const data = $(this).data('banner');
impressionBanner.push({
"id": data.id,
"name": data.name
})
gtag('event', 'view_promotion', {
impressionBanner
});
})
$('.banner-link').each(function(){
$(this).on("click", function(e){
e.preventDefault()
const data = $(this).data('banner')
console.log(data)
gtag('event', 'select_content', {
"promotions": [
{
"id": data.id,
"name": data.name
}
]
});
})
})
.banner-link{
width: 100px;
height: 50px;
background-color:red;
margin:5px;
color:#fff;
text-align:center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="banner-link" data-banner='{"id" : "1" , "name" : "Banner 1"}'>
Banner 1
</div>
<div class="banner-link" data-banner='{"id" : "2" , "name" : "Banner 2"}'>
Banner 2
</div>
<div class="banner-link" data-banner='{"id" : "3" , "name" : "Banner 3"}'>
Banner 3
</div>