在GA中可以利用event接口,来统计Maps API中的功能调用次数。
GA event的调用接口为:
ga('send', 'event', 'category', 'action', 'label', value);
当用户触发切换地图类型时,用下列语句来统计地图类型切换次数,
ga('send', 'event', 'Layer', 'On', 'User turned on '+ layerName +' layer');
注意,使用GA,别忘了加
<!-- Google Analytics --> <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-XXXX-Y'); // Replace with your property tracking ID. ga('send', 'pageview');
</script> <!-- End Google Analytics →
在切换功能中添加:
<input type='checkbox' name='Layer 1' value='layer_0001' onChange='handleLayerToggle(this);' />
function handleLayerToggle(elem) { layerKey = elem.value; layerName = elem.name;
if (elem.checked){ mapsEngineLayer = new google.maps.visualization.MapsEngineLayer({ mapId: mapId+'-4', layerKey:layerKey, accessToken: '' }); } }
添加了ga event代码后:
function handleLayerToggle(elem) { layerKey = elem.value; layerName = elem.name;
if (elem.checked){ ga('send', 'event', 'Layer', 'On', 'User turned on '+ layerName +' layer'); mapsEngineLayer = new google.maps.visualization.MapsEngineLayer({ mapId: mapId+'-4', layerKey: layerKey, }); } }
最后,打开GA web 页面,就可以看到实时的追踪效果了
|