我需要在完成ajax
之后推送DataLayer,以便在执行某些用户操作后它可以动态保持。问题在于,即使将所有内容都从ajax中取出,在这种情况下,我需要的答案也没有得到解决,并使用dataLayer.push
事件,这种动态推送不会发生。我已经尝试过将ajax响应放入诸如button
,input
之类的元素中,甚至模拟对它们的单击,但没有任何反应。下面是ajax代码。
function dadosProdutoCarrinho(id_prod){
$j.ajax({
type: 'POST',
url : '/datalayer.php',
dataType: 'json',
data: {
id_produto: id_prod
},
success: function (retorno) {
console.log(retorno);
dataLayer.push({
retorno
});
}
});
}
在return(retorno)中,它向我返回以下内容:
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'EUR',
'add': {
'products': [{
'name': 'Product Test',
'id': '123',
'sku': '123',
'price': 27.02,
'brand': 'Test',
'category': '',
'quantity': 1
},
]
}
}
});