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
-
Email traffic tracking in Google Analytics
Hello! I have a question about how to assure email traffic is properly tracked in GA > Acquisition > All Traffic > Channels. **First, some background... ** Our company (Wisconsin's largest group dental practice) is about to revamp the way we try to re-capture patients who don't have a future appointment set with us. Part of that process will include emails. Those emails will point back to our website to request an appointment. Now to the question... Is there anything special we should do to assure that links coming to the website and the resulting appointment request goal conversions track appropriately and appear under "Email" in the Default Channel Group of Analytics > Acquisition > All Traffic > Channels area of GA? For example, should we use Campaign URL Builder to establish UTM links? Thanks in advance for any feedback. Erik
Reporting & Analytics | | SmileMoreSEO0 -
Query on Product List Position After doing filters
Hi All, I have implemented enhance ecommerce with tag manager now I am implementing Product List Position so I have query that if visitor do filter or do sorting via highest or lowest price at that time do we have to show List position too? If yes then how and if No then why?
Reporting & Analytics | | Arnold3
Thanks!Mitesh0 -
I am tracking my domain e.g www.xyz.com to an existing google analytics account . I want to track www.xyz.com/blog separately in the google analytics account. How can I do that?
I am tracking my domain e.g www.xyz.com to an existing google analytics account . I want to track www.xyz.com/blog separately in the google analytics account. How can I do that?
Reporting & Analytics | | Windlass0 -
Is my tracking code incorrect?
I inherited a website that has a host of issues. I set up Goal Conversions for lead generation and am getting this URL listed as a Goal Completion Location /l/24672/2014-07-31/b4dg5 I can tell it is a date but have no other insight into what or where this page is. Does anyone have experience with this and can offer a fix? A related question is how can I find the URL that triggers the Goal Conversion. I tried editing the goal but it doesn't show the URL anywhere. And the Goal Completion Location is sort of a misnomer because it lists the URL prior to the completion. Thanks!
Reporting & Analytics | | Nobody15969167212220 -
Creating Goals in GA
Hi I don't know if the below can be done, and I can't seem to find an answer anywhere. Ideally I want to capture the event of registering for an account. Ultimately I want to know which products, pages etc drive customer registrations but which do not lead to a purchase (Registered Not Bought). Does anyone know if this is possible? Thanks Andy
Reporting & Analytics | | Andy-Halliday0 -
Identifying conversion rate for product
Hi, I need to identify the conversion rate for a product, lets call it a spanner. I have 100s of spanner product urls and I ensured that the url protocols must include the product name e.g /red_spanner so its easy for me to work out the conversion rate in analytics for all my spanner pages as I just add 'spanner' to the landing page filter, hit the ecommerce tab and bingo. What I cant figure out is how to work out the conversion rate for all spanner sales which includes alot of sales which didnt originate on spanner pages e.g. home page > search result > checkout. Theres 1000s of variations of this e.g. email > home > search > product page > checkout. How can I work out the total conversion rate for spanners which needs to include: people landing on a spanner page and people who didnt arrive at a spanner page and did a search with eventually got them to the spanner pages. Hopefully its not as complicated as I think! Thanks in Advance!
Reporting & Analytics | | AndyMacLean0 -
Google Shopping & Keyword Tracking
When tracking Google Shopping using the URL builder is it possible to pull through the Keyword used or will analytic do this automatically?
Reporting & Analytics | | TPSUK1