Google Analytics Event Tracking using html5 data attributes

Developer
Size
2,560 Kb
Views
38,456

How do I make an google analytics event tracking using html5 data attributes?

What is a google analytics event tracking using html5 data attributes? How do you make a google analytics event tracking using html5 data attributes? This script and codes were developed by Martin Boyce on 20 September 2022, Tuesday.

Google Analytics Event Tracking using html5 data attributes Previews

Google Analytics Event Tracking using html5 data attributes - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Google Analytics Event Tracking using html5 data attributes</title> <link rel='stylesheet prefetch' href='https://www.sutherlandshire.nsw.gov.au//files/templates/00000000-0000-0000-0000-000000000000/bd538bed-1f9c-43d7-b9f0-2c3cb29b7d41/style.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="row-fluid"> <div class="span4 offset4 thumbnail"> <ul class="more"><li> <span class="headline"><a class="js-ga-tracking" data-ga-category="homepage-spotlight" data-ga-action="click" data-ga-label="Zinio Digital Magazines">Zinio Digital Magazines</a></span>
</li><li> <span class="headline"><a class="js-ga-tracking" data-ga-category="homepage-spotlight" data-ga-action="click" data-ga-label="Picture Sutherland Shire">Picture Sutherland Shire</a></span>
</li><li> <span class="headline"><a class="js-ga-tracking" data-ga-category="homepage-spotlight" data-ga-action="click" data-ga-label="Freegal Music Downloads">Freegal Music Downloads</a></span>
</li><li> <span class="headline"><a class="js-ga-tracking" data-ga-category="homepage-spotlight" data-ga-action="click" data-ga-label="Overdrive eBooks and Audiobooks">Overdrive eBooks &amp; Audiobooks</a></span>
</li><li> <span class="headline"><a class="js-ga-tracking" data-ga-category="homepage-spotlight" data-ga-action="click" data-ga-label="New Titles Lists">New Titles Lists</a></span>
</li><li> <span class="headline"><a class="js-ga-tracking" data-ga-category="homepage-spotlight" data-ga-action="click" data-ga-label="Renew Your Loans">Renew Your Loans</a></span>
</li>
</ul>
</div>
</div>
<div class="span7 offset4">
<table class="table table-bordered"> <tbody> <tr> <th>Category</th> <th>Action</th> <th>Label</th> </tr> </tbody>
</table>
</div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Google Analytics Event Tracking using html5 data attributes - Script Codes CSS Codes

* { box-sizing: border-box;
}
.row-fluid { margin: 1rem;
}
.table { width: 100%;
}
th { width: calc(100%/3);
}

Google Analytics Event Tracking using html5 data attributes - Script Codes JS Codes

$('.js-ga-tracking').on('click', function() { var category = $(this).data('ga-category'); var action = $(this).data('ga-action'); var label = $(this).data('ga-label'); var value = $(this).data('ga-value'); var addRow = '<tr><td>'+ category + '</td><td>' + action + '</td><td>' + label + '</td></tr>';	//alert(category + ", " + action + ", " + label); $(addRow).appendTo('table'); //check that analytics is installed and then send event	if (typeof ga !== 'undefined') {	ga('send', 'event', category, action, label, value ); } else if (typeof _gaq.push !== 'undefined') { _gaq.push([ '_trackEvent', category, action, label, value ]); } else { alert("no google analytics here bro!"); }
});
Google Analytics Event Tracking using html5 data attributes - Script Codes
Google Analytics Event Tracking using html5 data attributes - Script Codes
Home Page Home
Developer Martin Boyce
Username boycetrus
Uploaded September 20, 2022
Rating 3
Size 2,560 Kb
Views 38,456
Do you need developer help for Google Analytics Event Tracking using html5 data attributes?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Martin Boyce (boycetrus) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!