Trying to implement ecommerce events on our website using GTM has been a bit challenging for me. I have attempted to create a custom value with custom JavaScript, but unfortunately, it keeps showing as undefined
.
In the initial stages, I came across a data script embedded in our website:
<script id="__NEXT_DATA__" type="application/json">
Subsequently, I proceeded to write a custom JavaScript code snippet as follows:
function() {
var productInfo = [{
'id':window.__NEXT_DATA__.props.pageProps.program.products[0].id,
'name':window.__NEXT_DATA__.props.pageProps.program.products[0].name,
'price':window.__NEXT_DATA__.props.pageProps.program.products[0].price,
'category':'exhibition'
}];
return productInfo;
}
Given that our website is built with next.js, I am beginning to wonder if utilizing script data in custom JavaScript is even feasible?