- Posted by kajyr on February 20th, 2009
- Tagged: analytics, tips, wordpress
Being the stat nerd that I am, I love to track visit to this blog (and other websites) with Google Analytics.
Problem is that I’ve noticed that also my visits couts, i don’t want this, at least, if i’m logged as an administrator i open the blog pages lots of times, to check the comments, to edit the layout of the pages and so on.
Edit: Marco from goanalytics.info suggested a smarter way to do that. See comment #1. ;-)
So after some researches, i’ve found the solution: you can filter Analytics pageviews basing on IP or cookies. The first one is useful when you don’t want a renge of users in a lan, but since I’m a freelance and work from home (but also from my parent’s home, and sometimes i open the blog at a friend house) the IP solution doesn’t work.
Cookies.
The Idea is to modify the wordpress template, so that can insert a cookie if you are logged in as the administrator. Wordpress already sets up some cookies for you, but using these will filter out every wordpress user, we just want to filter out ourselves.
To find if the user is an administrator, a good tip come from the Mark on Wordpress blog, you have to check user capabilities.
Next, reading GA Help tells you how to filter results based on a user defined keyword, you need to add a js function to the body onload event (assuming you don’t have any other, if it is the case, just add after the ;
Mixing the two things, something like this should came out:
<?php if ( current_user_can('manage_options') ) {
$onload = "onLoad='javascript:pageTracker._setVar(\"custom_keyword\");'";
} ?>
<body <?php echo $onload; ?> ></body>
This should replace your body tag, so should go in the header.php (in my template, at least); remember to replace custom keyword with something unique, a md5 of something should work.
Notice that this javascript uses a function from google, so you have to include the GA js library in the head. But Analytics tells you to include the code at the bottom.. You can choose. It will work fine if you just paste the GA code in the head, or else you can split it (in that code, there are 2 <script> blocks, the first loads the .js from Google, the seconds tracks the visits), so that the first script block goes into the head, and the latter at the bottom of the page.
Next you have to setup a filter in GA. Easy easy, goto Analytics Setting (the firse page after the login), find the Filter Manager link, add a new filter,with these options
Filter Type: Custom filter > Exclude
Filter Field: User Defined
Filter Pattern:custom_keyword
Case Sensitive: No
Enjoy. ;-)
References:
Mark on Wordpress: How to check if a WordPress user is an “administrator”
Google Analytics Help: How do I exclude my internal traffic from reports?, How do i create a custom filter
- Posted by kajyr on February 19th, 2009
- Tagged: ant, asdoc, documentation, eclipse, Flexbuilder, tips
Has anyone tryed to document ActionScript code using asdoc? I for myself hate to input shell commands in Windoze. I used to be a unix – bash hacker (in another life), and i find particularly annoying the windows shell (don’t even talk about the one in Vista..).
So i said to my good old friend Google: how can i use ant (which can be used in eclipse) to generate documentation with some clicks?
The answer lies around and need a few hacks, I post here my version for the sake of clarity.
I won’t tell you how to install ANT in Eclipse / Flex Builder using the Software Update tool, this may offend you.
Instead i’ll tell you that once setup is done, you need to upen the Ant view and you need an xml named build.xml with some rules in it, that tells which program to run, in which folder to save the output and so on. The xml is pretty self explaining, but in case just drop a line.
<?xml version="1.0" encoding="UTF-8"?>
<project name="asdoc" default="main" basedir=".">
<property name="Flex.dir" location="C:\Program Files\Adobe\Flex Builder 3"/>
<property name="FlexSDK.dir" location="${Flex.dir}\sdks\3.2.0"/>
<property name="AsDocs.dir" location="${FlexSDK.dir}\bin\asdoc.exe"/>
<property name="AppClasses.dir" location="${basedir}\..\src"/>
<property name="Output.dir" location="${basedir}\out" />
<target name="main" depends="clean,compile" description="full build of asdocs"/>
<target name="clean">
<delete dir="${Output.dir}" failOnError="false" includeEmptyDirs="true"/>
<mkdir dir="${Output.dir}"/>
</target>
<target name="compile">
<exec executable="${AsDocs.dir}" failonerror="true">
<arg line='+configname=air'/>
<arg line='-doc-sources ${AppClasses.dir}'/>
<arg line='-window-title "My Application"'/>
<arg line='-output ${Output.dir}'/>
</exec>
</target>
</project>
Note that the paths are relative to the position of the build.xml file.
(Also, i didn’t build the xml from scratch, there are many version of the same file on many blogs, so if the one who wrote it shows up, it will be an honor to credit him)
- Posted by kajyr on January 19th, 2009
- Tagged: actionscript, flex, recursion, tips
A good and easy example of a recursive function has come to my mind while replying to this question on stackoverflow.
The problem was how to know is a component (mx:UIComponent) was visible or not, just like Component.isShowing() works in Java. You canno’t rely on the visible property of the UIComponent, you have to check every parent to see if it too is visible.
First step in recursion is to block the basic level. If the component reference is null, it is not visible; if the component we are checking is an Application, it should be visible, according to his visible property (it doesn’t have a parent).
All the other cases should check the property, AND the parent’s property. (If a component isn’t on the DisplayList, his parent will be null, and it will not be visible, and so for all of his children).
public static
function isVisible
(c : UIComponent
) : Boolean {
if (c ==
null) return false;
if (c is Application
) return c.visible;
return c.visible &
;&
; isVisible
(c.parent);
}
- Posted by kajyr on January 9th, 2009
- Tagged: actionscript, api, tips
In Actionscript, the stage object is referenced by the DisplayObject.stage property. I use it alot, for example, to center elements on the screen, but as we read in the api reference,
If a display object is not added to the display list, its stage property is set to null.
this can be uncomfortable when you want to position something before attaching it, for any reason, or if you want a control object to operate on some stage property (fullscreen, for example).
So to avoid this, I usually add a static property to my Document Class, let’s call it staticStage:
public class FlashExample
extends MovieClip {
public static
var staticStage
:Stage;
public function FlashExample
():void {
staticStage =
stage;
[...]
Of course, the stage in FlashExample will not be null, since the DocumentClass is always added to the display list.
With this trick, you always have the stage at hand, by simply referencing FlashExample.staticStage anywhere on your code.
- Posted by kajyr on January 8th, 2009
- Tagged: actionscript, quickreference, tips, TweenLite
One class i really do like is TweenLite. I don’t really like the default tweening engine for a couple of reasons, but mainly because i have to save the tween object in a reference in my class, or the garbage collector could eat it (stopping the tweens in a unpredictable status).
TweenLite don’t require this (it exposes static functions, and keep internal references to the tweens) and permits me to specify functions to be called, not only handlers (which i know, may sound a little ActionScript 2.0, but in fact permits to call any funcion, and so avoiding one-line handlers).
One small example, (to be used inside a DisplayObjectContainer) is fading out a child, and detaching after. In one clear line:
TweenLite.to(mySprite, 1, {alpha:0, onComplete:removeChild, onCompleteParams:[mySprite], delay:0.5});
Let’s bring this a step further: we can easily apply this technique to all child of a given container:
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import gs
.TweenLite
;
public class mySprite
extends Sprite
{
public function mySprite
()
{
super();
}
public override
function removeChild(child:DisplayObject):DisplayObject {
TweenLite
.to
(mySprite
, 1
, {alpha:0
, onComplete
:super.removeChild, onCompleteParams
:[child], delay:0
.5
});
return child;
}
}
}
So now all the time removeChild is called from outside, the child gently fade away, and then quietly removes himself.