setSegment('achievementPoints'); $segment->setCategory('General_Visit'); $segment->setName('ExampleTracker_DimensionName'); $segment->setAcceptedValues('Here you should explain which values are accepted/useful: Any number, for instance 1, 2, 3 , 99'); $this->addSegment($segment); } /** * The onNewVisit method is triggered when a new visitor is detected. This means here you can define an initial * value for this user. By returning boolean false no value will be saved. Once the user makes another action the * event "onExistingVisit" is executed. That means for each visitor this method is executed once. If you do not want * to perform any action on a new visit you can just remove this method. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed|false */ public function onNewVisit(Request $request, Visitor $visitor, $action) { if (empty($action)) { return 0; } return 1; // you could also easily save any custom tracking url parameters // return Common::getRequestVar('myCustomTrackingParam', 'default', 'string', $request->getParams()); // return Common::getRequestVar('linuxversion', false, 'string', $request->getParams()); } /** * The onExistingVisit method is triggered when a visitor was recognized meaning it is not a new visitor. * If you want you can overwrite any previous value set by the event onNewVisit. By returning boolean false no value * will be updated. If you do not want to perform any action on a new visit you can just remove this method. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * * @return mixed|false */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { if (empty($action)) { return false; // Do not change an already persisted value } return $visitor->getVisitorColumn($this->columnName) + 1; } /** * This event is executed shortly after "onNewVisit" or "onExistingVisit" in case the visitor converted a goal. * In this example we give the user 5 extra points for this achievement. Usually this event is not needed and you * can simply remove this method therefore. An example would be for instance to persist the last converted * action url. Return boolean false if you do not want to change the current value. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * * @return mixed|false */ public function onConvertedVisit(Request $request, Visitor $visitor, $action) { return $visitor->getVisitorColumn($this->columnName) + 5; // give this visitor 5 extra achievement points } /** * By implementing this event you can persist a value to the log_conversion table in case a conversion happens. * The persisted value will be logged along the conversion and will not be changed afterwards. * This allows you to generate reports that shows for instance which url was called how often for a specific * conversion. Once you implement this event and a $columnType is defined a column in the log_conversion MySQL table * will be created automatically. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * * @return mixed public function onAnyGoalConversion(Request $request, Visitor $visitor, $action) { return $visitor->getVisitorColumn($this->columnName); } */ /** * Sometimes you may want to make sure another dimension is executed before your dimension so you can persist * a value depending on the value of other dimensions. You can do this by defining an array of dimension names. * If you access any value of any other column within your events, you should require them here. Otherwise those * values may not be available. * @return array public function getRequiredVisitFields() { return array('idsite', 'server_time'); } */ }