I have an e-commerce website with no dataLayer and I need to setup GTM from scratch. I'm kinda new to the topic and don't know how to extract data without one. Project has no developer, they want to see the main e-commerce metrics on analytics and certain advertising platforms (Google Ads, Meta etc.). I thought about using custom javascript variables and setup tags accordingly, but I don't if I need to write parameter values manually. This is my first project so apologies if this is a basic thing. I don't know how to scrape certain values.
I used AI to write a sample variable function below:
function() { return { 'item_id': '12345', 'item_name': 'Sample Product', 'item_category': 'Electronics', 'item_variant': 'Black', 'item_brand': 'Example Brand', 'price': 199.99, 'currency': 'USD' }; }
Do I need to create this function for every item manually? I can see product info on elements but couldn't scrape it with document.querySelectorAll.
First, for e-commerce you need to have three variables - currency, value, items. But their content depends on the e-commerce event in which they are used. You still need to have a way to get data about a product (or several products). You can cheat this problem on simple events such as view_item a product (for example, under the condition of the current URL, substitute product data). But with regard to the events of add_to_cart or cart_view the or purchase, you will not be able to get away with it. Therefore, this task is very difficult and must be solved by interfering with the code of the store platform.