I want to track product click so how to create project object or how to pass project object ?
-
Hey,
I am reading this post - https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicksIn this there is function like given below - function(productObj) { dataLayer.push({ 'event': 'productClick', 'ecommerce': {.....................................................................................................................Now my developer asking how to create object? or how to pass product object? Like on page we have more than 50 products listed, so if any one clicks on any product from list then how will we know which product has been clicked?Hope you understand what i want to say? Regards,Mitesh
-
Hi Mitesh, the product object needs to be a javascript object with the following properties expected:
'name': productObj.name, // Name or ID is required. 'id': productObj.id, 'price': productObj.price, 'brand': productObj.brand, 'category': productObj.cat, 'variant': productObj.variant
Creating such an object and passing it to the analytics could be done with a simple function like the following.You say you have a list of products. Let's assume for the purposes of a demonstration that the list item is formatted like so:
Example product
An Example product
You could listen for clicks on the basket add (which you are probably doing already, so your developer should be able to hook the new functionality into the same event handler, but for the purposes of a demonstration I've included an example of the event listener too). Then find the product related to the current "add to basket" link. I've included 2 very simple functions using pure Javascript to demonstrate how this can be done.
var basketLink = document.querySelectorAll('.addtobasket');
for (var i = 0; i < basketLink.length; i++) {
basketLink[i].addEventListener('click', function(event) {
console.log('Basket link clicked');
event.preventDefault();
product = getSchemaOrgProductData(this.parentNode);
console.log( product.name );
console.log( product.brand );
});
}
function getProductData(context) {
var product = {};
product.name = context.querySelector('.product-name').textContent;
product.brand = context.querySelector('.product-brand').textContent;
return product;
}
function getSchemaOrgProductData(context) {
var product = {};
product.name = context.querySelector('[itemprop="name"]').textContent
product.brand = context.querySelector('[itemprop="brand"]').textContent;
return product;
}That should be enough for your developer to understand how to create a product object that can be passed to the analytics function. I haven't implemented methods for fetching and setting all relevant properties but the developer can copy the example.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
How to do Conversion Tracking for Homepage banners?
Hello All, I want to do banner conversion tracking for my ecommerce site. That is at my homepage I display 4 banners with special offers on 4 different products. Now that 4 products are already falls in relevant categories. I did event tracking for banners from where I can know how many clicks I am getting from each banner but My Query is how to know conversion of all 4 banner products because once I create goal that is funnel like 1) home page 2) product page 3) checkout step 4) Thank you page. But problem comes here is if anyone purchase these product from categories that also comes in goal so how to differentiate conversion of products from homepage and category pages? Is there any implementation via enhance ecommerce? Hope you understand my query? If any confusion do let me know. Thanks!
Reporting & Analytics | | micey1230 -
Last click conversions (Assisted conversions report vs. Channels report)
Hi Mozzers, Does anyone know why the last click / direct conversions (by channel) in the 'assisted conversion report in Google Analytics do not match the conversions in the Channels report. I thought conversion data in the channels report was last click / direct conversions? Thanks for your help!
Reporting & Analytics | | A_Q0 -
Someone mentioned us on facebook and brought 10k clicks to homepage.. how do I find the content?
So this morning our website started to go crazy with hits all coming from Facebook, and I am trying to figure out how I can see who was talking about us? All the traffic landed on one page specifically. When I look in analytics it just shows social, and then I can drill down to see they are coming from facebook, but that's it.
Reporting & Analytics | | DemiGR0 -
I want to upgrade to Universal Analytics but already using GTM and I have few queries...
Hello Experts, I want to migrate from classical to universal analytics and i am already using GTM for my ecommerce site. I have small 6 queries :- After login to google analytics from admin section i have to transfer property to universal analytics ? right? I have to wait either 24 hours or 48 hours before retagging or doing any changes in UA. So how can i know my property transferred sucessfully? After property transferred to universal analytics, i have to configure the session timeout and campaign timeout periods via the Google Analytics Admin page. ( By default,
Reporting & Analytics | | jackinmathis1
sessions end after 30 minutes and campaigns end after 6 months ) is it okay if i don't change this settings? As of now in my analytic i have configured google adwords, google webmaster and google merchant. In analytic i have also set custom alerts, goals, funnels, enchance link attribution, eCommerce etc but google analytics code i have already added in google tag manager, so i have to some manual changes for all such things? or all the things i.e goals, funnel, alerts etc will be transferred automatically at time of transferring the property? In Google tag manager i have already configured following things :- Tags :- Name - Google adwords Conversion Tracking b) Type - Adwords Conversion Tracking c) Rules - order sucessful page Name - Google Analytic Page view Tracking b) Type - Classic Google Analytics c) Rules - All pages Name - Google Analytic Conversion Tracking b) Type - Classic Google Analytics c) Rules - order sucessful page Name - Twitter Conversion Tracking b) Type - Custom HTML tag c) Rules - order sucessful page So at time of transferring property all this will be transferred automatically? Also at thank you page of my website I have scripts for goal setting, Affiliator, so there is no relation of this with migration right? Kind co-operation in the matter of highly be appreciated. So please help me! Regards,
Jackin!0 -
Google analytics is not tracking well
Hey, There is something not working in our GA account, its shows too many visits per day, when look where this traffic comes from, the majority comes from (not set). Please find attached. Really appreciate help! Thank you! BvmAKtO
Reporting & Analytics | | Comunicare0 -
Tracking Social Media Logged In Users Help
Hi, I recently read Tom Anthony's post on "Monitor Which Social Networks Your Visitors are Logged Into With Google Analytics". I have looked and re-looked at the code implemented and after two days I am still not getting any results tracking. Could somebody please take a look at my site and tell me if they see any conflicts or errors I may have made when installing the code. Thanks for any help!
Reporting & Analytics | | BryanCasson0 -
Is there any web analytics tool that let us track number of outgoing clicks (and visits) ?
I just wonder if we can measure outgoing visits from a specific URL with an online tool or not?
Reporting & Analytics | | merkal20050 -
Custom GA tracking and link value
Hi I'm working on a real estate agents web site which has a lots of links coming from paid listings in real estate linstings sites (this in France so I'm not sure examples will mean anything but basically the agents have 900 house listings in each site and each listing has a backlink) In analytics these are classified as referals and that's fine for the moment But because sites provide different types of links, we are considering tagging all paid links with analytics utm codes. Mainly to learn which ads are actually providing qualified traffic (providing contacts). I'm guessing that currently these links, there are thousands, bring seo value to my client's web site and are not considered as paid links. Will adding the analytics codes to these links cause a loss of their value by clearly indicating to Google that we paid for them? What's the current thinking on this? I'm tempted not to be worried about being honest about the origin of these links but I'm worried that there is a real danger of loosing current ranking Any arguments FOR tagging paid links ? Thanks for you help Neil
Reporting & Analytics | | NeilInFrance0