1, or $a['goal'] = array( "id"=>1, "revenue"=>"49.99" ); goal can be included in all requests with clicky_log, not just for type=goal - custom To attach custom data to a session, send in an array of key/value pairs. e.g. $a['custom'] = array( "username" => "hot2trot", "email" => "hot@trot.com" ); custom can be included in all requests with clicky_log, not just for type=custom ##### LOGGING AN ACTION To log an action, the only required parameter is "href". But you probably want to add "title" to make it more interesting, and you'll need to declare the type if you want it to be download, outbound, or click (otherwise, it defaults to pageview). Examples: (note that parameters can be in any order) - clicky_log( array( "title" => "Some page", "href" => "/some/path?some=query" )); - clicky_log( array( "href" => "/some/download.zip", "type" => "download", "title" => "Some download" )); - $a = array( "type" => "outbound", "href" => "http://somesite.com/some/path?some=query", "title" => "Some site" ); clicky_log( $a ); - $a = array(); $a['type'] = "outbound"; $a['href'] = "http://somesite.com/"; clicky_log( $a ); ##### LOGGING CUSTOM DATA Specify type=custom to add custom data to a session, without having to log an action in the process. We recommend using session_id to ensure the data gets attached to the right session, even if it's expired. Examples: - clicky_log( array( "type" => "custom", "session_id" => "123", "custom" => array( "username" => "Someone", "email" => "some@one.com" ))); - $a = array(); $a['type'] = "custom"; $a['session_id'] = "123"; $a['custom']['username'] = "Someone"; $a['custom']['email'] = "some@one.com"; clicky_log( $a ); ##### LOGGING GOALS Specify type=goal to declare a goal completion and/or revenue, without having to a log an action in the process. The onclick goal function available in our tracking code uses the exact same parameters to log its data. If the goal has already been flagged as completed for this visitor but you want to add revenue, that will work. You still need to declare the goal ID, but the revenue will be added on. Note: if there is already revenue attached to this visitor, and the revenue you're trying to add on is exactly the same value, the new revenue will be ignored. This is because it is likely a user repeating a behavior by mistake, such as clicking "back", or clicking an item that results in clicky.goal being called from our tracking code more than once. Examples: - clicky_log( array( "type" => "goal", "session_id" => "123", "goal" => 5 )); - clicky_log( array( "type" => "goal", "session_id" => "123", "goal" => array( "id" => 5 ))); - clicky_log( array( "type" => "goal", "session_id" => "123", "goal" => array( "id" => 5, "revenue" => "49.99" ))); - $a = array(); $a['type'] = "goal"; $a['session_id'] = "123"; $a['goal']['id'] = 5; $a['goal']['revenue'] = "49.99"; clicky_log( $a ); */ function clicky_log( $a ) { # ATTENTION! you need to change the following 2 values for the site you are going to use this with! # these are all available on the main preferences page for any web site! $site_id = "123"; $sitekey_admin = "123"; $type = $a['type']; if( !in_array( $type, array( "pageview", "download", "outbound", "click", "custom", "goal" ))) $type = "pageview"; $file = "http://in.getclicky.com/in.php?site_id=".$site_id."&sitekey_admin=".$sitekey_admin."&type=".$type; # referrer and user agent - will only be logged if this is the very first action of this session if( $a['ref'] ) $file .= "&ref=".urlencode( $a['ref'] ); if( $a['ua'] ) $file .= "&ua=". urlencode( $a['ua'] ); # we need either a session_id or an ip_address... if( is_numeric( $a['session_id'] )) { $file .= "&session_id=".$a['session_id']; } else { if( !$a['ip_address'] ) $a['ip_address'] = $_SERVER['REMOTE_ADDR']; # automatically grab IP that PHP gives us. if( !preg_match( "#^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$#", $a['ip_address'] )) return false; $file .= "&ip_address=".$a['ip_address']; } # goals can come in as integer or array, for convenience if( $a['goal'] ) { if( is_array( $a['goal'] )) { foreach( $a['goal'] as $key => $value ) $file .= "&goal[".urlencode( $key )."]=".urlencode( $value ); } else { $file .= "&goal[id]=".$a['goal']; } } # custom data, must come in as array of key=>values foreach( $a['custom'] as $key => $value ) $file .= "&custom[".urlencode( $key )."]=".urlencode( $value ); if( $type == "goal" || $type == "custom" ) { # dont do anything, data has already been cat'd } else { if( $type == "outbound" ) { if( !preg_match( "#^(https?|telnet|ftp)#", $a['href'] )) return false; } else { # all other action types must start with either a / or a # if( !preg_match( "#^(/|\#)#", $a['href'] )) $a['href'] = "/" . $a['href']; } $file .= "&href=".urlencode( $a['href'] ); if( $a['title'] ) $file .= "&title=".urlencode( $a['title'] ); } return file( $file ) ? true:false; } ?>