예제 #1
0
        public void Screen(RudderMessage message)
        {
            RudderLogger.LogDebug("Screen Event: " + message.eventName);
            if (_integrationManager != null)
            {
                _integrationManager.MakeIntegrationDump(message);
            }
#if UNITY_ANDROID
            if (Application.platform == RuntimePlatform.Android)
            {
                androidClientClass.CallStatic(
                    "_logEvent",
                    "screen",
                    message.eventName,
                    message.getEventPropertiesJson(),
                    message.getUserPropertiesJson(),
                    message.getOptionsJson()
                    );
            }
#endif
#if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                _logEvent(
                    "screen",
                    message.eventName,
                    message.getEventPropertiesJson(),
                    message.getUserPropertiesJson(),
                    message.getOptionsJson()
                    );
            }
#endif
        }
예제 #2
0
        public RudderConfig(
            string dataPlaneUrl,
            string controlPlaneUrl,
            int flushQueueSize,
            int dbCountThreshold,
            int sleepTimeOut,
            int logLevel,
            int configRefreshInterval,
            bool trackLifecycleEvents,
            bool recordScreenViews,
            List <RudderIntegrationFactory> factories
            )
        {
            this.dataPlaneUrl          = dataPlaneUrl;
            this.controlPlaneUrl       = controlPlaneUrl;
            this.flushQueueSize        = flushQueueSize;
            this.dbCountThreshold      = dbCountThreshold;
            this.sleepTimeOut          = sleepTimeOut;
            this.factories             = factories;
            this.logLevel              = logLevel;
            this.configRefreshInterval = configRefreshInterval;
            this.trackLifecycleEvents  = trackLifecycleEvents;
            this.recordScreenViews     = recordScreenViews;

            RudderLogger.Init(logLevel);
        }
예제 #3
0
        public override void Dump(RudderMessage message)
        {
            RudderLogger.LogDebug("Adjust integration dump event: " + message.eventName);
            if (message.eventName != null && this.eventTokenMap.ContainsKey(message.eventName))
            {
                string eventToken = this.eventTokenMap[message.eventName];
                RudderLogger.LogDebug("Adjust integration dump: eventToken: " + eventToken);
                if (eventToken != null && !eventToken.Equals(""))
                {
                    this.AddSessionParameter(RudderCache.GetAnonymousId());

                    RudderLogger.LogDebug("Creating Adjust event");
                    AdjustEvent adjustEvent = new AdjustEvent(eventToken);

                    RudderLogger.LogDebug("Adding Event Properties");
                    Dictionary <string, object> eventProperties = message.eventProperties;
                    if (eventProperties != null)
                    {
                        foreach (string key in eventProperties.Keys)
                        {
                            adjustEvent.addCallbackParameter(key, eventProperties[key].ToString());
                        }
                    }

                    RudderLogger.LogDebug("Adding User Properties");
                    Dictionary <string, object> userProperties = message.userProperties;
                    if (userProperties != null)
                    {
                        foreach (string key in userProperties.Keys)
                        {
                            adjustEvent.addCallbackParameter(key, userProperties[key].ToString());
                        }
                    }

                    RudderLogger.LogDebug("Tracking revenue through Adjust SDK");
                    if (message.eventProperties.ContainsKey("revenue"))
                    {
                        double amount   = (double)message.eventProperties["revenue"];
                        string currency = "";
                        if (message.eventProperties.ContainsKey("currency"))
                        {
                            currency = message.eventProperties["currency"] as string;
                        }
                        adjustEvent.setRevenue(amount, currency);
                    }

                    RudderLogger.LogDebug("Tracking event");
                    Adjust.trackEvent(adjustEvent);
                }
                else
                {
                    RudderLogger.LogDebug("Incorrect event token for Adjust");
                }
            }
            else
            {
                RudderLogger.LogDebug("RudderAdjustIntegration: Event is not tracked through Adjust");
            }
        }
 public static RudderAdjustIntegrationFactory GetFactory()
 {
     if (instance == null)
     {
         RudderLogger.LogDebug("Instantiating RudderAdjustIntegrationFactory");
         instance = new RudderAdjustIntegrationFactory();
     }
     return(instance);
 }
예제 #5
0
        public static void SerializeSqlite()
        {
#if UNITY_IPHONE
            RudderLogger.LogDebug("SQLite Serialized");
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                _serializeSqlite();
            }
#endif
        }
 public void Reset()
 {
     if (!this._isFactoryPrepared)
     {
         RudderLogger.LogDebug("Factories are not prepared yet");
     }
     // make native integration calls
     else
     {
         foreach (string key in _integrationOpsMap.Keys)
         {
             RudderLogger.LogDebug("Resetting native SDK " + key);
             _integrationOpsMap[key].Reset();
         }
     }
 }
        void DownloadConfig(object obj)
        {
            bool isDone       = false;
            int  retryCount   = 0;
            int  retryTimeOut = 10;

            while (!isDone && retryCount <= 3)
            {
                try
                {
                    string configEndpointUrl = _config.controlPlaneUrl + "/sourceConfig";
                    RudderLogger.LogDebug("configEndpontUrl: " + configEndpointUrl);
                    // create http request object
                    var http = (HttpWebRequest)WebRequest.Create(new Uri(configEndpointUrl));
                    http.Method = "GET";
                    var    authKeyBytes = System.Text.Encoding.UTF8.GetBytes(_writeKey + ":");
                    string authHeader   = System.Convert.ToBase64String(authKeyBytes);
                    http.Headers.Add("Authorization", "Basic " + authHeader);
                    // get the response
                    var response = http.GetResponse();
                    var stream   = response.GetResponseStream();
                    var sr       = new StreamReader(stream);
                    // return the response as a string
                    string responseJson = sr.ReadToEnd();
                    RudderLogger.LogDebug("Config Server Response: " + responseJson);
                    if (responseJson != null)
                    {
                        lock (this._lockingObj)
                        {
                            this._serverConfigJson = responseJson;
                        }
                        isDone = true;
                    }
                    else
                    {
                        retryCount += 1;
                        Thread.Sleep(1000 * retryCount * retryTimeOut);
                    }
                }
                catch (Exception ex)
                {
                    // RudderLogger.LogError(ex.Message);
                    retryCount += 1;
                    Thread.Sleep(1000 * retryCount * retryTimeOut);
                }
            }
        }
 private Dictionary <string, object> ParseServerConfig(string configJson)
 {
     if (configJson == null || configJson.Equals(""))
     {
         RudderLogger.LogDebug("parseServerConfig: configJson is null");
         return(null);
     }
     try
     {
         return(MiniJSON.Json.Deserialize(configJson) as Dictionary <string, object>);
     }
     catch (Exception ex)
     {
         RudderLogger.LogError(ex.Message);
     }
     return(null);
 }
 public void MakeIntegrationDump(RudderMessage message)
 {
     // if factories are not prepared dump those in the queue
     if (!this._isFactoryPrepared || this._rudderServerConfig == null)
     {
         lock (this._lockingObj)
         {
             _factoryDumpQueue.Add(message);
         }
     }
     // make native integration calls
     else
     {
         foreach (string key in _integrationOpsMap.Keys)
         {
             RudderLogger.LogDebug("Dumping " + message.eventName + " to " + key + " native SDK");
             _integrationOpsMap[key].Dump(message);
         }
     }
 }
 public void MakeIntegrationIdentify(string userId, RudderTraits traits)
 {
     if (!this._isFactoryPrepared || this._rudderServerConfig == null)
     {
         lock (this._lockingObj)
         {
             this._persistedUserId = userId;
             this._persistedTraits = traits;
         }
         RudderLogger.LogDebug("Factories are not prepared yet");
     }
     // make native integration calls
     else
     {
         foreach (string key in _integrationOpsMap.Keys)
         {
             RudderLogger.LogDebug("Identify to " + key + " native SDK");
             _integrationOpsMap[key].Identify(userId, traits);
         }
     }
 }
예제 #11
0
        public static RudderClient GetInstance(
            string writeKey,
            RudderConfig config
            )
        {
            if (_instance == null)
            {
                // initialize the cache
                RudderCache.Init();

                RudderLogger.LogDebug("Instantiating RudderClient SDK");
                // initialize the instance
                _instance = new RudderClient(
                    writeKey,
                    config.dataPlaneUrl,
                    config.controlPlaneUrl,
                    config.flushQueueSize,
                    config.dbCountThreshold,
                    config.sleepTimeOut,
                    config.configRefreshInterval,
                    config.trackLifecycleEvents,
                    config.recordScreenViews,
                    config.logLevel
                    );

                RudderLogger.LogDebug("Instantiating RudderIntegrationManager");
                _integrationManager = new RudderIntegrationManager(
                    writeKey,
                    config
                    );
            }
            else
            {
                RudderLogger.LogDebug("RudderClient SDK is already initiated");
            }

            return(_instance);
        }
예제 #12
0
        public void Identify(string userId, RudderTraits traits, RudderMessage message)
        {
            RudderLogger.LogDebug("Identify Event: " + message.eventName);
            RudderCache.SetUserId(userId);
            if (_integrationManager != null)
            {
                _integrationManager.MakeIntegrationIdentify(userId, traits);
            }

            // put supplied userId under traits as well if it is not set
            if (traits.getId() == null)
            {
                traits.PutId(userId);
            }
            string traitsJson = Json.Serialize(traits.traitsDict);

#if UNITY_ANDROID
            if (Application.platform == RuntimePlatform.Android)
            {
                androidClientClass.CallStatic(
                    "_identify",
                    userId,
                    traitsJson,
                    message.getOptionsJson()
                    );
            }
#endif
#if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                _identify(
                    userId,
                    traitsJson,
                    message.getOptionsJson()
                    );
            }
#endif
        }
예제 #13
0
        public override void Dump(RudderMessage message)
        {
            string eventName = message.eventName;

            RudderLogger.LogDebug(eventName + " is sent to Firebase");
            List <Firebase.Analytics.Parameter> parameters = new List <Firebase.Analytics.Parameter>();

            if (message.eventProperties != null)
            {
                foreach (string key in message.eventProperties.Keys)
                {
                    parameters.Add(new Firebase.Analytics.Parameter(
                                       key,
                                       Json.Serialize(message.eventProperties[key])
                                       ));
                }
            }

            Firebase.Analytics.FirebaseAnalytics.LogEvent(
                eventName,
                parameters.ToArray()
                );
        }
        private void DownloadIntegrations()
        {
            try
            {
                lock (this._lockingObj)
                {
                    this._lastUpdatedTimestamp = long.Parse(PlayerPrefs.GetString("rl_server_update_time", "0"));
                    RudderLogger.LogDebug("RudderIntegrationManager: downloadIntegrations: lastUpdatedTimeStamp: " + _lastUpdatedTimestamp);
                    this._serverConfigJson = PlayerPrefs.GetString("rl_server_config", null);
                    RudderLogger.LogDebug("RudderIntegrationManager: downloadIntegrations: serverConfigJson: " + this._serverConfigJson);
                }

                if (this._serverConfigJson == null || this._serverConfigJson.Equals("") || IsServerConfigOutdated())
                {
                    Thread t = new Thread(DownloadConfig);
                    t.Start();
                }
            }
            catch (Exception ex)
            {
                RudderLogger.LogError("CreateConnection ERROR: downloadConfig error");
            }
        }
예제 #15
0
        public void Reset()
        {
            RudderLogger.LogDebug("SDK reset");
            if (_integrationManager != null)
            {
                _integrationManager.Reset();
            }
            RudderCache.Reset();
#if UNITY_ANDROID
            if (Application.platform == RuntimePlatform.Android)
            {
                androidClientClass.CallStatic(
                    "_reset"
                    );
            }
#endif
#if UNITY_IPHONE
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                _reset();
            }
#endif
        }
        public void Update()
        {
            if (!this._isFactoryPrepared)
            {
                lock (this._lockingObj)
                {
                    if (this._serverConfigJson != null && !this._serverConfigJson.Equals(""))
                    {
                        RudderLogger.LogDebug("RudderIntegrationManager Update: serverConfigJson: " + this._serverConfigJson);
                        if (IsServerConfigOutdated())
                        {
#if !UNITY_EDITOR
                            PlayerPrefs.SetString("rl_server_update_time", Stopwatch.GetTimestamp().ToString());
                            PlayerPrefs.SetString("rl_server_config", this._serverConfigJson);
                            PlayerPrefs.Save();
#endif
                        }

                        this._rudderServerConfig = ParseServerConfig(this._serverConfigJson);
                        this.PrepareFactories();
                    }
                }
            }
        }
 public override RudderIntegration Create(Dictionary <string, object> config, RudderClient client, RudderConfig rudderConfig)
 {
     RudderLogger.LogDebug("Creating RudderAdjustIntegrationFactory");
     return(new RudderAdjustIntegration(config, client, rudderConfig));
 }
        private void PrepareFactories()
        {
            try
            {
                if (this._rudderServerConfig == null)
                {
                    RudderLogger.LogInfo("No integrations: rudderServerConfig is null");
                }
                else if (this._config.factories == null)
                {
                    RudderLogger.LogInfo("No integrations: config.factories is null");
                }
                else if (this._config.factories.Count == 0)
                {
                    // no factory to initialize
                    RudderLogger.LogInfo("No integrations: config.factories.Count is 0");
                }
                else
                {
                    RudderClient client = RudderClient.GetInstance();
                    Dictionary <string, object> source = this._rudderServerConfig["source"] as Dictionary <string, object>;
                    List <object> destinations         = source["destinations"] as List <object>;

                    if (destinations.Count > 0)
                    {
                        Dictionary <string, object> destinationMap = new Dictionary <string, object>();
                        RudderLogger.LogDebug("Native SDKs enabled in Dashboard");
                        foreach (var destinationObj in destinations)
                        {
                            Dictionary <string, object> destination           = destinationObj as Dictionary <string, object>;
                            Dictionary <string, object> destinationDefinition = destination["destinationDefinition"] as Dictionary <string, object>;
                            string destinationName = destinationDefinition["displayName"] as string;
                            RudderLogger.LogDebug("Extracted Native Destination information: " + destinationName);

                            destinationMap[destinationName] = destination;
                        }

                        foreach (RudderIntegrationFactory factory in this._config.factories)
                        {
                            string factoryKey = factory.Key();
                            RudderLogger.LogDebug("Initiating native destination factory: " + factoryKey);
                            if (destinationMap.ContainsKey(factoryKey))
                            {
                                Dictionary <string, object> serverDestination = destinationMap[factoryKey] as Dictionary <string, object>;
                                if (serverDestination != null)
                                {
                                    bool?isDestinationEnabled = serverDestination["enabled"] as bool?;
                                    if (isDestinationEnabled != null && isDestinationEnabled == true)
                                    {
                                        Dictionary <string, object> destinationConfig = serverDestination["config"] as Dictionary <string, object>;
                                        RudderIntegration           integrationOp     = factory.Create(destinationConfig, client, this._config);
                                        RudderLogger.LogDebug("Native integration initiated for " + factoryKey);
                                        this._integrationOpsMap[factoryKey] = integrationOp;
                                    }
                                }
                            }
                        }
                    }
                }
                this._isFactoryPrepared = true;

                lock (this._lockingObj)
                {
                    if (this._factoryDumpQueue.Count > 0)
                    {
                        for (int index = 0; index < this._factoryDumpQueue.Count; index++)
                        {
                            this.MakeIntegrationDump(this._factoryDumpQueue[index]);
                        }
                        this._factoryDumpQueue.Clear();
                    }
                    if (_persistedTraits != null && _persistedUserId != null)
                    {
                        this.MakeIntegrationIdentify(_persistedUserId, _persistedTraits);
                        this._persistedTraits = null;
                        this._persistedUserId = null;
                    }
                }
            }
            catch (Exception ex)
            {
                RudderLogger.LogError(ex.Message);
            }
        }
예제 #19
0
 public RudderFirebaseIntegration(Dictionary <string, object> config, RudderClient client, RudderConfig rudderConfig)
 {
     RudderLogger.LogDebug("Instantiating RudderFirebaseIntegration");
     RudderLogger.LogDebug("Starting Firebase native SDK");
 }
예제 #20
0
        /*
         * private constructor to prevent instantiating
         */
        private RudderClient(
            string _writeKey,
            string _dataPlaneUrl,
            string _controlPlaneUrl,
            int _flushQueueSize,
            int _dbCountThreshold,
            int _sleepTimeout,
            int _configRefreshInterval,
            bool _trackLifecycleEvents,
            bool _recordScreenViews,
            int _logLevel
            )
        {
            // initialize android
#if UNITY_ANDROID
            RudderLogger.LogDebug("Initializing Android Core SDK");
            if (Application.platform == RuntimePlatform.Android)
            {
                AndroidJavaClass  unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject activity    = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
                AndroidJavaObject context     = activity.Call <AndroidJavaObject>("getApplicationContext");
                androidClientClass = new AndroidJavaClass(androidClientName);
                androidClientClass.CallStatic(
                    "_initiateInstance",
                    context,
                    RudderCache.GetAnonymousId(),
                    _writeKey,
                    _dataPlaneUrl,
                    _controlPlaneUrl,
                    _flushQueueSize,
                    _dbCountThreshold,
                    _sleepTimeout,
                    _configRefreshInterval,
                    _trackLifecycleEvents,
                    _recordScreenViews,
                    _logLevel
                    );
                RudderLogger.LogDebug("Android Core SDK initiated");
            }
#endif

// initialize iOS
#if UNITY_IPHONE
            RudderLogger.LogDebug("Initializing iOS Core SDK");
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                _initiateInstance(
                    RudderCache.GetAnonymousId(),
                    _writeKey,
                    _dataPlaneUrl,
                    _controlPlaneUrl,
                    _flushQueueSize,
                    _dbCountThreshold,
                    _sleepTimeout,
                    _configRefreshInterval,
                    _trackLifecycleEvents,
                    _recordScreenViews,
                    _logLevel
                    );
                RudderLogger.LogDebug("iOS Core SDK initiated");
            }
#endif
        }
예제 #21
0
        public RudderAdjustIntegration(Dictionary <string, object> config, RudderClient client, RudderConfig rudderConfig)
        {
            RudderLogger.LogDebug("Instantiating RudderAdjustIntegration");
            string appToken = null;

            if (config.ContainsKey("appToken"))
            {
                appToken = config["appToken"] as string;
                RudderLogger.LogDebug("Adjust: appToken: " + appToken);
            }

            List <object> eventTokens = new List <object>();

            if (config.ContainsKey("customMappings"))
            {
                eventTokens = config["customMappings"] as List <object>;
                foreach (var eventConfig in eventTokens)
                {
                    Dictionary <string, object> eventTokenDict = eventConfig as Dictionary <string, object>;
                    string eventName  = eventTokenDict["from"] as string;
                    string eventToken = eventTokenDict["to"] as string;
                    RudderLogger.LogDebug("Adjust: " + eventName + " : " + eventToken);
                    this.eventTokenMap[eventName] = eventToken;
                }
            }

            string delayTime = null;

            if (config.ContainsKey("delay"))
            {
                delayTime = config["delay"] as string;
                RudderLogger.LogDebug("delayTime:" + delayTime);
            }

            if (appToken != null && !appToken.Equals(""))
            {
                RudderLogger.LogDebug("Initiating Adjust native SDK");
                AdjustConfig adjustConfig = new AdjustConfig(
                    appToken,
                    rudderConfig.logLevel >= RudderLogLevel.DEBUG ? AdjustEnvironment.Sandbox : AdjustEnvironment.Production,
                    true);
                adjustConfig.setLogLevel(rudderConfig.logLevel >= RudderLogLevel.DEBUG ? AdjustLogLevel.Verbose : AdjustLogLevel.Error);
                double delay = 0;
                try
                {
                    if (delayTime != null)
                    {
                        delay = double.Parse(delayTime);
                    }
                }
                catch (System.Exception ex)
                {
                    RudderLogger.LogError("Invalid delay time" + ex.Message);
                }
                if (delay < 0)
                {
                    delay = 0;
                }
                else if (delay > 10)
                {
                    delay = 10;
                }
                if (delay > 0)
                {
                    adjustConfig.setDelayStart(delay);
                }

                RudderLogger.LogDebug("Starting Adjust native SDK");
                Adjust.start(adjustConfig);
            }
            else
            {
                RudderLogger.LogError("appToken was not set in Dashboard");
            }
        }