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
-
Do custom tracking codes affect indexing?
Hello, My company uses a tracking system that allows our employees to apply a short code snippet to the end of our URLs for marketing attribution. An example of such a code would be: https://www.schoolofmotion.com/?ref_id=moz-test However, in Google Analytics we are seeing duplicates of our content, where the pages with the individual tracking codes are counted separately from the pages without. From a reporting perspective, this is annoying and definitely worth a fix. However, I'm curious if this problem is affecting our search potential as well. Could this tracking system be splitting traffic in Google's eyes? From an SEO perspective, how should we approach this? Would canonical tags fix this duplication issue in Google Analytics? Is there something else that we should use? Thanks in advance. The Moz community is incredible.
Reporting & Analytics | | CalebWardSoM1 -
How to interpret search "clicks" in GA?
I am trying to make some sense of the data in the "Landing Pages" report under "Search Engine Optimization" in GA versus the data under the "Landing Pages" report in "Behavior | Site Content". For example, the SEO report says my page http://www.asiantraveltips.com/blog/bangkok-skytrain-bts-mrt-lines/ received 22,000 search impressions in the past 30 days and 900 "clicks" (12.42%). What are these "clicks" when the Content "Landing Pages" report says the same page only got 382 "sessions" in the same period??? What are these "clicks" if not clicks on the search results link that should be reflected in landing page sessions on the corresponding page?
Reporting & Analytics | | Gavin.Atkinson0 -
URL open with double domain names when click on visit URL link in Google Analytics
I have configured Advance Filter to track the sub-domains traffic as follow : Filter
Reporting & Analytics | | gamesecure
Type: Custom filter > Advanced Field A: Hostname Extract A: (.*) Field B: Request URI Extract B: (.*) Output To: Request URI Constructor: $A1$B1 After that, I am able to see sub-domains record and View Full Page URL In Reports. But when I check reports in All page (e.g. Behavior >> All Pages) or selecting Landing Page as a Primary Dimension. Further I click on Icon given next to displayed Full URL to visit to same domain page, in browser the page
opened but the double domain name comes so page not open successfully. For example : In landing page list following URL given : www.sitegeek.com/compareHosting/arvixe_vs_hostgator If I click on icon given next the displayed URL, in browser following URL will
open https://sitegeek.comwww.sitegeek.com/compareHosting/arvixe_vs_hostgator Is this First Domain with HTTPs, coming from Google Analytic 'View' where this is taken ? How Can I remove double domains? Thanks, Rajiv0 -
Tracking Google places (7 pack listing) traffic in google analytics
Is there a way to see Google Places traffic (traffic from users clicking through the 7 pack listings) segmented in Google analytics ? Normally is it just lumped together with the organic traffic ? Can you see the search phrases used to find your site, or do they also show up under 'not provided' when from Google Places. Im aware i can see some limited data in the Google Places analytics, but these seem to be 2 days behind when ever i view them.
Reporting & Analytics | | Sam-P0 -
Virtual Pageviews vs. Destination URL for Goal tracking
I am working on setting up goal tracking. Currently when we receive a new signup, the person gets sent to their dashboard homepage and this is not a valuable a goal tracking destination. My suggestion was to build a "Welcome" interstitial page to send a user to when they create an account. Our tech team suggested using a Virtual pageview instead as it is their thinking that a "Welcome" page adds little value. Is there any downside to using Virtual Pageviews with regards to goal tracking?
Reporting & Analytics | | Vacatia_SEO
Are interstitial page more reliable?
Can you still use funnel visualization with Virtual Pageviews?0 -
How to track affiliate ads on Google analytics
Hi Im new google analytics user, I would like to track affiliates ads (banner flow -javascript) on my website. How to set up goals to track affiliate ads? thanks.
Reporting & Analytics | | info_tipovanie-stavkovanie.com0 -
Adwords Clicks correlating to Analytics Paid Visits
Would appreciate if anyone could clarify for me the correlation between 'clicks' in Google Adwords and visits for paid search in Google Analytics. Currently i see several thousand clicks a day in Adwords, yet our analytics account will only report a few hundred visits so i do not know which data set to use as the most reliable source for analysis. e.g 16th May. Analytics > TrafficSources > Sources > Search > Paid = 208 visits Adwords > All Campaigns, Total Clicks = 1153 i have found a few other questions asking the same thing here and here but dont feel they answer my question. We know our Adwords account is linked to our Analytics account as we got in touch with our PPC account manager originally about this and on reiew they found an error in our setup. Since then we know this is working as search terms and source are showing up and we have auto tagging enabled. Thanks, Tom.
Reporting & Analytics | | Sarbs0 -
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