{"id":437,"date":"2009-11-09T10:56:12","date_gmt":"2009-11-09T17:56:12","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2383"},"modified":"2009-11-09T10:56:12","modified_gmt":"2009-11-09T17:56:12","slug":"google-analytics-utility","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=437","title":{"rendered":"Google Analytics Utility"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\npackage com.hapticdata.utils\r\n{\r\n\timport flash.external.ExternalInterface;\r\n\t\/**\r\n\t * Simplifies posting to Google&#039;s Analytics Tracker, allows easily disabling for development phase\r\n\t * and uses ExternalInterface rather than navigateToURL\r\n\t * @class Urchin \r\n\t * @author Kyle Phillips - &lt;a href=&quot;http:\/\/www.haptic-data.com&quot;&gt;http:\/\/www.haptic-data.com&lt;\/a&gt;\r\n\t * @created October 28, 2008\r\n\t * @example Analytics.post(&quot;section&quot;);\r\n\t *\/\r\n\t\r\n\t\r\n\tpublic class Analytics\r\n\t{\r\n\t\t\r\n\t\tpublic static var enabled:Boolean = true;\r\n\t\t\/\/appended as a directory to all trackings\r\n\t\tpublic static var swfID:String=&quot;\/flashevent\/&quot;;\r\n\t\t\/\/correct for default snippet. Change this if you have a custom-wrapped analytics method\r\n\t\tpublic static var functionToCall:String = &quot;pageTracker._trackPageview&quot;;\r\n\t\t\r\n\t\t\/**\r\n\t\t * Will invoke the set javascript function\r\n\t\t * @param location:String - a string identifying where the user is in the site\r\n\t\t *\/\r\n\t\tpublic static function post(location:String):void\r\n\t\t{\r\n\t\t\tif(enabled &amp;&amp; ExternalInterface.available)\r\n\t\t\t{\r\n\t\t\t\tExternalInterface.call(functionToCall,swfID+location);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>This contest entry by <a href=\"http:\/\/www.haptic-data.com\">Kyle Phillips<\/a> is a utility class for dealing with <a href=\"http:\/\/www.google.com\/analytics\/\" target=\"blank\">google analytics<\/a>. If you haven&#8217;t messed with google analytics I suggest you give it a try. <\/p>\n<p>Kyle Phillips links:<br \/>\n>> <a href=\"http:\/\/workofkylephillips.com\">http:\/\/workofkylephillips.com<\/a><br \/>\n>><a href=\"http:\/\/labs.hapticdata.com\"> http:\/\/labs.hapticdata.com<br \/>\n<\/a><br \/>\nI usually find myself adding google analytics code in a very hacky way&#8230; usually because the client asks for it at the 11th hour. Using a class like Kyle&#8217;s would enable you to simply add the tracking code from the start and then if the client doesn&#8217;t ask for it&#8230; you can just keep the class disabled&#8230; or charge more when you offer google analytics tracking for &#8220;phase 2&#8221; of the project \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>package com.hapticdata.utils { import flash.external.ExternalInterface; \/** * Simplifies posting to Google&#039;s Analytics Tracker, allows easily disabling for development phase * and uses ExternalInterface rather than navigateToURL * @class Urchin * @author Kyle Phillips &#8211; &lt;a href=&quot;http:\/\/www.haptic-data.com&quot;&gt;http:\/\/www.haptic-data.com&lt;\/a&gt; * @created October 28, 2008 * @example Analytics.post(&quot;section&quot;); *\/ public class Analytics { public static var enabled:Boolean = true; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,94],"tags":[3,14,141,4,142],"class_list":["post-437","post","type-post","status-publish","format-standard","hentry","category-external-data","category-misc","tag-actionscript","tag-as3","tag-ascontest","tag-flash","tag-google-analytics"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}