Ejemplo n.º 1
0
        public static IServiceCollection AddAnalytics(this IServiceCollection services, string writeKey,
                                                      Action <RudderConfig> configuration)
        {
            var config = new RudderConfig();

            configuration?.Invoke(config);

            var client = new RudderClient(writeKey, config);

            services.AddSingleton <IRudderAnalyticsClient>(client);
            return(services);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public RudderFirebaseIntegration(Dictionary <string, object> config, RudderClient client, RudderConfig rudderConfig)
 {
     RudderLogger.LogDebug("Instantiating RudderFirebaseIntegration");
     RudderLogger.LogDebug("Starting Firebase native SDK");
 }
Ejemplo n.º 4
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");
            }
        }
 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);
            }
        }