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
-
Tracking PDF downloads from SERP clicks
For the longest time, our company policy has always been to put PDFs in a secure folder (hence they are not indexed and do not appear in search results). After evaluating this strategy, there has been clamor in recent months to allow Google to index our whitepapers. My question: Once PDFs start appearing in search results, what is the best way to start tracking clicks due to these "downloads"?
Reporting & Analytics | | marshdigitalmarketing0 -
Do Lot of Tracking via Tag manager Increase Bounce Rate?
Hello Expert, I am doing lots of tracking for my ecommerce site but I am not sure reason for increase in bounce rate as my traffic also increase but I want to make sure that my tracking not affecting my bounce rate. I do tracking via page views, events, custom html, etc so for all the applicable tags Non-Interaction Hit - I set "True" so I am right here? Thanks!
Reporting & Analytics | | dsouzac0 -
Does Lightbox Gallery Clicks Count Positively Toward Page Rank?
When a user clicks through a lightbox gallery, are these counted as a click through for page rank? I am using WonderPlugin Grid Gallery on multiple pages with multiple galleries. I do not want these clicks to be wasted. Please advise. Regards, Clever Name SEO www.clevernameseo.com
Reporting & Analytics | | cindymariesilva0 -
Tracking Social Interactions with GA and WordPress
Hi, One of the things I'm looking to do is to track clicks on my social follow buttons. I know I can try to add GA events for each button and go from there. But in order to simplify the process, I'm looking for a WP plugin that can help. Currently I've only come across AddThis and Share This as viable options, though Add This has very mixed reviews, and Share This isn't updated for WP 3.6.1. For my social shares at the end of blog posts I'm wondering the same thing about tracking shares. I've used AddThis in the past with success in tracking shares, but I wanted to see what other are doing or if there's a newer technique. The bottom line is that I want to try to see as much of the "social" as I can in GA. Thank you in advance!!
Reporting & Analytics | | Titan5520 -
Subdomain GA Tracking??
Hi Mozzers I am tracking a web property www.example.com and we are launching a subdomain.example.com. Should the subdomain tracked on GA by creating a new profile or should it be on its own with a new GA property ID? Thanks for explaining how to do that setup 🙂 Ty
Reporting & Analytics | | Ideas-Money-Art0 -
Set up Google Analytics by product category
Does anyone know if it's possible to set up Google Analytics data by product category? We sell roughly twenty product categories on our ecommerce site. We can look at our analytics performance for the site overall and drill down to specific pages, but what we really want to see is our performance by product category. Our product categories can include up to 5000 products. Any pointers on how to do this?
Reporting & Analytics | | ironpac0 -
Is there any way to see how one my keywords ranked historically before I started tracking it?
Hello there! I'm in need of some historical data on some keywords as they relate to my site. Basically, I'd like to track which events have had the most impact on moving me through the rankings, but I wasn't using Moz at the time I had made some changes to my website... Is there any way to see how I ranked for a particular keyword at a given point in time? Thanks! Gene
Reporting & Analytics | | BGroup0 -
Tracking pdf downloads
hello, I have a site with 100's of pdf's for download and I would like to track how many people are downloading these, does anyone have a simple solution for this? Is there anyway I can do this in Google Analytics using one piece of code, thanks...
Reporting & Analytics | | Socialdude0