Skip to content

Instantly share code, notes, and snippets.

@tureki
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tureki/9303954 to your computer and use it in GitHub Desktop.
Save tureki/9303954 to your computer and use it in GitHub Desktop.
Google Analytics dynamic track page view testing.
<html>
<head>
<title>Ga Testing</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="https://raw.github.com/twbs/bootstrap/master/dist/css/bootstrap.min.css">
</head>
<body style="width:800;margin:20 auto;">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-xs-8">
<img track="/index/img-panel/large/img" width="500" height="500" src="http://www.google.com/analytics/images/misc/product-icon.png">
</div>
<div class="col-xs-4">
<img track="/index/img-panel/small/img" width="150" height="150" src="http://www.google.com/analytics/images/misc/product-icon.png">
<img track="/index/img-panel/small/img" width="150" height="150" src="http://www.google.com/analytics/images/misc/product-icon.png">
<img track="/index/img-panel/small/img" width="150" height="150" src="http://www.google.com/analytics/images/misc/product-icon.png">
</div>
</div>
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-1', 'YOURDOMAIN');
ga('send', 'pageview');
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
var ga_ui_track = ga.create('UA-XXXXX-01', 'auto', {'name': 'UA-XXXXXX-02'});
jQuery('body').on('click', '[track]', function(e) {
var _str_track = jQuery(this).attr("track");
ga_ui_track.send('pageview',{page:_str_track});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment