javascript - After ajax google analytics tag not working
Solution:
You shouldn't send transaction information with add to cart event. To measure the addition of a product to a shopping cart, send an add_to_cart event with the product information:
gtag('event', 'add_to_cart', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
]
});
Answer
Solution:
Finally i have found the solution after an ajax request must recall google analytics tags
$.getScript("https://www.googletagmanager.com/gtag/js?id=UA-171652858-1",function(){});
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('event', 'purchase', {
"transaction_id": response.SiparisNumarasi,
"affiliation": "Marketcimrisi",
"value":response.OdenenTutar,
"currency": "TRY",
"tax": 0,
"shipping": 0,
"items": JSON.stringify(response.Urunler)
});
Source