<commit_before>/**
 * Project: ANE-Google-Analytics
 *
 * Author:  <NAME>
 * Website: http://alessandrobianco.eu
 * Twitter: @alebianco
 * Created: 21/12/12 18.55
 *
 * Copyright © 2013 <NAME>
 */
package eu.alebianco.air.extensions.analytics {

import eu.alebianco.air.extensions.analytics.api.Hit;
import eu.alebianco.air.extensions.analytics.api.IEventBuilder;
import eu.alebianco.air.extensions.analytics.api.IExceptionBuilder;
import eu.alebianco.air.extensions.analytics.api.ISocialBuilder;
import eu.alebianco.air.extensions.analytics.api.ITimingBuilder;
import eu.alebianco.air.extensions.analytics.api.ITracker;
import eu.alebianco.air.extensions.analytics.api.ITransactionBuilder;
import eu.alebianco.air.extensions.analytics.api.IViewBuilder;

import flash.desktop.NativeApplication;
import flash.events.TimerEvent;
import flash.external.ExtensionContext;
import flash.utils.Timer;

internal class Tracker implements ITracker {

	private var context:ExtensionContext;

	private var id:String;

	private var timeout:uint = 30;
	private var timer:Timer;

	private var _appName:String;
	private var _appVersion:String;
	private var _lockAppData:Boolean = false;

	public function Tracker(id:String, context:ExtensionContext) {
		this.id = id;
		this.context = context;
		parseAppDescriptor();
		measureCampaign();
		createTimer();
	}

	public function get appName():String {
		return _appName;
	}
	public function set appName(value:String):void {
		if (_lockAppData) return;
		_appName = value;
		handleResultFromExtension(context.call("setAppName", id, _appName));
	}
	public function get appVersion():String {
		return _appVersion;
	}
	public function set appVersion(value:String):void {
		if (_lockAppData) return;
		_appVersion = value;
		handleResultFromExtension(context.call("setAppVersion", id, _appVersion));
	}
	public function get trackingID():String {
		return id;
	}
	public function get sessionTimeout():uint {
		return timeout;
	}
	public function set sessionTimeout(value:uint):void {
		timeout = value;
		disposeTimer();
		createTimer();
	}
	public function get appID():String {
		return handleResultFromExtension(context.call("getAppID", id), String) as String;
	}
	public function set appID(value:String):void {
		handleResultFromExtension(context.call("setAppID", id, value));
	}
	public function get anonymous():Boolean {
		return handleResultFromExtension(context.call("getAnonymous", id), Boolean) as Boolean;
	}
	public function set anonymous(value:Boolean):void {
		handleResultFromExtension(context.call("setAnonymous", id, value));
	}
	public function get secure():Boolean {
		return handleResultFromExtension(context.call("getSecure", id), Boolean) as Boolean;
	}
	public function set secure(value:Boolean):void {
		handleResultFromExtension(context.call("setSecure", id, value));
	}
	public function get sampleRate():Number {
		return handleResultFromExtension(context.call("getSampleRate", id), Number) as Number;
	}
	public function set sampleRate(value:Number):void {
		handleResultFromExtension(context.call("setSampleRate", id, Math.max(0, Math.min(100, value))));
	}
	public function startNewSession():void {
		handleResultFromExtension(context.call("startNewSession", id));
	}
	public function setCustomMetric(index:uint, value:int):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("setCustomMetric", id, index, value));
	}
	public function setCustomDimension(index:uint, value:String):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("setCustomDimension", id, index, value));
	}
	public function clearCustomDimension(index:uint):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("clearCustomDimension", id, index));
	}
	public function clearCustomMetric(index:uint):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("clearCustomDimension", id, index));
	}

	public function hasCampaignData():Boolean {
		return handleResultFromExtension(context.call("hasCampaignData"), Boolean) as Boolean;
	}
	public function hasReferrer():Boolean {
		return handleResultFromExtension(context.call("hasReferrer"), Boolean) as Boolean;
	}
	public function getCampaignData():String {
		return handleResultFromExtension(context.call("getCampaignData"), String) as String;
	}
	public function getReferrer():String {
		return handleResultFromExtension(context.call("getReferrer"), String) as String;
	}
	public function setCampaignData(data:String):void {
		handleResultFromExtension(context.call("setCampaignData"));
	}
	public function setReferrer(uri:String):void {
		handleResultFromExtension(context.call("setReferrer"));
	}

	public function send(data:Hit):void {
		_lockAppData = true;
		handleResultFromExtension(context.call("trackData", id, data.type.name, data));
	}
	public function buildView(screenName:String):IViewBuilder {
		return new ViewBuilder(this, screenName);
	}
	public function buildEvent(category:String, action:String):IEventBuilder {
		return new EventBuilder(this, category, action);
	}
	public function buildException(fatal:Boolean):IExceptionBuilder {
		return new ExceptionBuilder(this, fatal);
	}
	public function buildTiming(category:String, interval:uint):ITimingBuilder {
		return new TimingBuilder(this, category, interval);
	}
	public function buildSocial(network:String, action:String):ISocialBuilder {<commit_msg>simplified implementation to check campaign existence to reduce native implementations<commit_after>/**
 * Project: ANE-Google-Analytics
 *
 * Author:  <NAME>
 * Website: http://alessandrobianco.eu
 * Twitter: @alebianco
 * Created: 21/12/12 18.55
 *
 * Copyright © 2013 <NAME>
 */
package eu.alebianco.air.extensions.analytics {

import eu.alebianco.air.extensions.analytics.api.Hit;
import eu.alebianco.air.extensions.analytics.api.IEventBuilder;
import eu.alebianco.air.extensions.analytics.api.IExceptionBuilder;
import eu.alebianco.air.extensions.analytics.api.ISocialBuilder;
import eu.alebianco.air.extensions.analytics.api.ITimingBuilder;
import eu.alebianco.air.extensions.analytics.api.ITracker;
import eu.alebianco.air.extensions.analytics.api.ITransactionBuilder;
import eu.alebianco.air.extensions.analytics.api.IViewBuilder;

import flash.desktop.NativeApplication;
import flash.events.TimerEvent;
import flash.external.ExtensionContext;
import flash.utils.Timer;

internal class Tracker implements ITracker {

	private var context:ExtensionContext;

	private var id:String;

	private var timeout:uint = 30;
	private var timer:Timer;

	private var _appName:String;
	private var _appVersion:String;
	private var _lockAppData:Boolean = false;

	public function Tracker(id:String, context:ExtensionContext) {
		this.id = id;
		this.context = context;
		parseAppDescriptor();
		measureCampaign();
		createTimer();
	}

	public function get appName():String {
		return _appName;
	}
	public function set appName(value:String):void {
		if (_lockAppData) return;
		_appName = value;
		handleResultFromExtension(context.call("setAppName", id, _appName));
	}
	public function get appVersion():String {
		return _appVersion;
	}
	public function set appVersion(value:String):void {
		if (_lockAppData) return;
		_appVersion = value;
		handleResultFromExtension(context.call("setAppVersion", id, _appVersion));
	}
	public function get trackingID():String {
		return id;
	}
	public function get sessionTimeout():uint {
		return timeout;
	}
	public function set sessionTimeout(value:uint):void {
		timeout = value;
		disposeTimer();
		createTimer();
	}
	public function get appID():String {
		return handleResultFromExtension(context.call("getAppID", id), String) as String;
	}
	public function set appID(value:String):void {
		handleResultFromExtension(context.call("setAppID", id, value));
	}
	public function get anonymous():Boolean {
		return handleResultFromExtension(context.call("getAnonymous", id), Boolean) as Boolean;
	}
	public function set anonymous(value:Boolean):void {
		handleResultFromExtension(context.call("setAnonymous", id, value));
	}
	public function get secure():Boolean {
		return handleResultFromExtension(context.call("getSecure", id), Boolean) as Boolean;
	}
	public function set secure(value:Boolean):void {
		handleResultFromExtension(context.call("setSecure", id, value));
	}
	public function get sampleRate():Number {
		return handleResultFromExtension(context.call("getSampleRate", id), Number) as Number;
	}
	public function set sampleRate(value:Number):void {
		handleResultFromExtension(context.call("setSampleRate", id, Math.max(0, Math.min(100, value))));
	}
	public function startNewSession():void {
		handleResultFromExtension(context.call("startNewSession", id));
	}
	public function setCustomMetric(index:uint, value:int):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("setCustomMetric", id, index, value));
	}
	public function setCustomDimension(index:uint, value:String):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("setCustomDimension", id, index, value));
	}
	public function clearCustomDimension(index:uint):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("clearCustomDimension", id, index));
	}
	public function clearCustomMetric(index:uint):void {
		if (index == 0)
			throw new ArgumentError("Metrics and Dimensions indexes are 1-based.");

		handleResultFromExtension(context.call("clearCustomDimension", id, index));
	}

	public function hasCampaignData():Boolean {
		return (handleResultFromExtension(context.call("getCampaignData"), String) as String) != null;
	}
	public function hasReferrer():Boolean {
		return (handleResultFromExtension(context.call("getReferrer"), String) as String) != null;
	}
	public function getCampaignData():String {
		return handleResultFromExtension(context.call("getCampaignData"), String) as String;
	}
	public function getReferrer():String {
		return handleResultFromExtension(context.call("getReferrer"), String) as String;
	}
	public function setCampaignData(data:String):void {
		handleResultFromExtension(context.call("setCampaignData"));
	}
	public function setReferrer(uri:String):void {
		handleResultFromExtension(context.call("setReferrer"));
	}

	public function send(data:Hit):void {
		_lockAppData = true;
		handleResultFromExtension(context.call("trackData", id, data.type.name, data));
	}
	public function buildView(screenName:String):IViewBuilder {
		return new ViewBuilder(this, screenName);
	}
	public function buildEvent(category:String, action:String):IEventBuilder {
		return new EventBuilder(this, category, action);
	}
	public function buildException(fatal:Boolean):IExceptionBuilder {
		return new ExceptionBuilder(this, fatal);
	}
	public function buildTiming(category:String, interval:uint):ITimingBuilder {
		return new TimingBuilder(this, category, interval);
	}
	public function buildSocial(network:String, action:String):ISocialBuilder {
{'fraction_non_alphanumeric': 0.11418533157663592, 'fraction_numerical': 0.004918752744839701, 'mean_word_length': 6.374352331606218, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6990946', 'n_tokens_mistral': 3505, 'n_tokens_neox': 3310, 'n_words': 749}