Search our site
Forum Search
Google Site Search
|
EllenD
Advanced Member
United Kingdom
434 Posts Pre-sales questions only (More Details...)
|
Posted - 11/01/2023 : 11:33:48
Hi, I've added Google Analytics as per the instructions here https://www.ecommercetemplates.com/phphelp/ecommplus/parameters.asp
I'm not using incectstyle.php so have put the code in an include file in <head> section (have replaced tags with my own, XXX just for this post)
[code] <!-- Google Tag Manager --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); </script> <!-- Google tag (gtag.js) --> [/code]
Purchases are not being tracked, and when I look at 'view source' on proddetail.php and thanks.php, I just see the same code as above. Not any additional stuff with gtag event, price parameters etc.
It is a UK store running PHP v7.7.2
Any tips please?
Thank you Ellen
|
dbdave
ECT Moderator
USA
10396 Posts |
Posted - 11/01/2023 : 12:51:41
|
EllenD
Advanced Member
United Kingdom
434 Posts Pre-sales questions only (More Details...)
|
Posted - 11/02/2023 : 02:55:39
Hi David,
Thank you for your reply. I have reviewed the link and didn't see anything missing. I'm a bit 'caught in the middle' as the GA4 was set up by a marketing company, and I don't know much about analytics myself. The marketing company have sent me this code example (below) and said "this code will need to be inserted where a purchase is made, all the parameters don't need to be specified, just the ones that you would like to see in google analytics".
Does ECT generate this somehow? Since details of the product, price etc are here I assume it must come from the cart. I looked at source code on my proddetail, cart & thanks pages but all I see is the smaller snippet of code which I put in my first post. So I think this is what is missing, but I'm unsure how to get it! I also looked at code on the demo store and some of the featured live ECT stores, but no luck.
[code] <script>
gtag("event", "purchase", {
transaction_id: "T_12345_1", value: 25.42, tax: 4.90, shipping: 5.99, currency: "USD", coupon: "SUMMER_SALE", items: [ // If someone purchases more than one item, // you can add those items to the items array
{
item_id: "SKU_12345", item_name: "Stan and Friends Tee", affiliation: "Google Merchandise Store", coupon: "SUMMER_FUN", discount: 2.22, index: 0, item_brand: "Google", item_category: "Apparel", item_category2: "Adult", item_category3: "Shirts", item_category4: "Crew", item_category5: "Short sleeve", item_list_id: "related_products", item_list_name: "Related Products", item_variant: "green", location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", price: 9.99, quantity: 1
}]
});
</script> [/code]
Edited by - EllenD on 11/02/2023 14:06:44
|
Vince
Administrator
42715 Posts |
Posted - 11/02/2023 : 04:35:30
|
dbdave
ECT Moderator
USA
10396 Posts |
Posted - 11/02/2023 : 06:54:44
Hi Ellen, in addition to what Vince wrote, I wanted to add that the output for the purchase will be down lower in the source code. Perhaps it's there, but you are just missing it. You might try using "find" in your browser (on the thanks page (source)) and search for a few of the words expected in the output, such as "transaction_id" or something like that.
Thanks, David
|
EllenD
Advanced Member
United Kingdom
434 Posts Pre-sales questions only (More Details...)
|
Posted - 11/02/2023 : 14:06:27
Hi Vince & David,
Thank you both for your replies. Still no luck, although I've not changed anything since my previous post. I did a test purchase and 'view source' of thanks.php does not have the code we're looking for with price etc. A search of the code for 'gtag' reveals only the smaller code snippet at the top. Nothing for transaction_id either.
There is a test product with zero cost if you could try it please? https://finneyswoodfinishes.co.uk/Test_Product
Another avenue I'm exploring is whether something is missing for purchases in the GA4 account. I didn't set it up and don't know much about it, does anyone know if you have to specifically set up the 'purchase' event within GA4? I'm thinking it's unlikely to be an ECT issue really since presumably others are tracking purchases successfully.
Thank you for the help Ellen
|
dbdave
ECT Moderator
USA
10396 Posts |
Posted - 11/02/2023 : 16:32:07
Hi Ellen, I checked the console on your cart page after adding that item to the cart, and I stopped short of completing checkout because I saw quite a few errors that seemed related to your google analytics. After viewing source, I see all of this in the head of the page. quote: <!-- Google Tag Manager --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxx"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-xxxxxxxxx'); </script> <!-- Google tag (gtag.js) -->
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-xxxxxxxx');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) --> <noscript><iframe src=https://www.googletagmanager.com/ns.html?id=GTM-xxxxxxx height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->
Really it should just be this small bit of code there. <script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxx"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-xxxxxxxxx'); </script> Can you remove the extra code there and give it a try? Thanks, David
Edited by - dbdave on 11/02/2023 16:34:20
|
Vince
Administrator
42715 Posts |
Posted - 11/03/2023 : 04:16:19
|
EllenD
Advanced Member
United Kingdom
434 Posts Pre-sales questions only (More Details...)
|
Posted - 11/03/2023 : 04:53:14
Hi Vince,
I removed the extra code - it wasn't there initially but the marketing company advised me to add it! Anyway, I think you hit the nail on the head with the GA4 ID in the dashboard. It wasn't there, because I'd (wrongly) interpreted the instructions as being either dashboard & incstyle.php method, or manually put in code snippet. So I had done the snippet but not put GA4 ID into Main Settings page.
I have now added to the dashboard main settings and am hopeful that will allow the purchases to be tracked.
Many thanks for the help :)
Ellen
|
EllenD
Advanced Member
United Kingdom
434 Posts Pre-sales questions only (More Details...)
|
Posted - 11/06/2023 : 02:58:11
Can confirm all now working, thanks. So the missing thing was I'd not put the GA ID in dashboard, doh
|
|
|
Shopping Cart Software Forum for Ecommerce Templates |
© 2002-2022 ecommercetemplates.com |
|
|
|