Example #1
0
 /// <summary>
 ///     Call this when your application starts.
 ///     This will initiate a call to Leanplum's servers to get the values
 ///     of the variables used in your app.
 /// </summary>
 public override void Start(string userId, IDictionary <string, object> attributes,
                            Leanplum.StartHandler startResponseAction)
 {
     Started += startResponseAction;
     NativeSDK.CallStatic("initialize", gameObjectName, SharedConstants.SDK_VERSION, null);
     NativeSDK.CallStatic("start", userId, Json.Serialize(attributes));
 }
Example #2
0
        /// <summary>
        ///     Call this when your application starts.
        ///     This will initiate a call to Leanplum's servers to get the values
        ///     of the variables used in your app.
        /// </summary>
        public override void Start(string userId, IDictionary <string, object> attributes, Leanplum.StartHandler startResponseAction)
        {
            _setGameObject(LeanplumUnityHelper.Instance.gameObject.name);
            Started += startResponseAction;
            string attributesString = attributes == null ? null : Json.Serialize(attributes);

            _start(SharedConstants.SDK_VERSION, userId, attributesString);
        }
        /// <summary>
        ///     Call this when your application starts.
        ///     This will initiate a call to Leanplum's servers to get the values
        ///     of the variables used in your app.
        /// </summary>
        public override void Start(string userId, IDictionary <string, object> attributes,
                                   Leanplum.StartHandler startResponseAction)
        {
            // Invokes Started event through NativeCallback
            Started += startResponseAction;

            NativeSDK.CallStatic("start", userId, Json.Serialize(attributes));
        }
        /// <summary>
        ///     Call this when your application starts.
        ///     This will initiate a call to Leanplum's servers to get the values
        ///     of the variables used in your app.
        /// </summary>
        public override void Start(string userId, IDictionary <string, object> attributes,
                                   Leanplum.StartHandler startResponseAction)
        {
            lp_setGameObject(LeanplumUnityHelper.Instance.gameObject.name);
            // Invokes Started event through NativeCallback
            Started += startResponseAction;
            string attributesString = attributes == null ? null : Json.Serialize(attributes);

            lp_start(Constants.SDK_VERSION, userId, attributesString);
        }
Example #5
0
        /// <summary>
        ///     Call this when your application starts.
        ///     This will initiate a call to Leanplum's servers to get the values
        ///     of the variables used in your app.
        /// </summary>
        public override void Start(string userId, IDictionary <string, object> attributes,
                                   Leanplum.StartHandler startResponseAction)
        {
            Started += startResponseAction;

            // This also constructs LeanplumUnityHelper and the game object.
            gameObjectName = LeanplumUnityHelper.Instance.gameObject.name;

            NativeSDK.CallStatic("initialize", gameObjectName, Constants.SDK_VERSION, null);
            NativeSDK.CallStatic("start", userId, Json.Serialize(attributes));
        }
        /// <summary>
        ///     Call this when your application starts.
        ///     This will initiate a call to Leanplum's servers to get the values
        ///     of the variables used in your app.
        /// </summary>
        public override void Start(string userId, IDictionary <string, object> attributes,
                                   Leanplum.StartHandler startResponseAction)
        {
            if (calledStart)
            {
                CompatibilityLayer.Log("Already called start");
                return;
            }
            if (String.IsNullOrEmpty(LeanplumRequest.AppId))
            {
                CompatibilityLayer.LogError("You cannot call Start without setting your app's " +
                                            "API keys.");
                return;
            }

            if (CompatibilityLayer.GetPlatformName() == "Standalone")
            {
                // TODO: Fix this.
                // This is a workaround for SSL issues when running on
                // standalone when connecting with the production server.
                // No issue on staging.
                Constants.API_SSL = false;
            }

            if (startResponseAction != null)
            {
                Started += startResponseAction;
            }
            if (Constants.isNoop)
            {
                _hasStarted     = true;
                startSuccessful = true;
                OnVariablesChanged();
                OnVariablesChangedAndNoDownloadsPending();
                OnStarted(true);
                VarCache.ApplyVariableDiffs(null, null);
                return;
            }

            ValidateAttributes(attributes);
            calledStart = true;

            // Load the variables that were stored on the device from the last session.
            VarCache.IsSilent = true;
            VarCache.LoadDiffs();
            VarCache.IsSilent = false;

            // Setup class members.
            VarCache.Update += delegate
            {
                OnVariablesChanged();
                if (LeanplumRequest.PendingDownloads == 0)
                {
                    OnVariablesChangedAndNoDownloadsPending();
                }
            };

            LeanplumRequest.NoPendingDownloads += delegate
            {
                OnVariablesChangedAndNoDownloadsPending();
            };

            string deviceId;

            if (customDeviceId != null)
            {
                deviceId = customDeviceId;
            }
            else
            {
                deviceId = CompatibilityLayer.GetDeviceId();
            }
            LeanplumRequest.DeviceId = deviceId;

            // Don't overwrite UserID if it was set previously if Start()
            // was called without a new UserID.
            if (!String.IsNullOrEmpty(userId))
            {
                LeanplumRequest.UserId = userId;
            }
            if (String.IsNullOrEmpty(LeanplumRequest.UserId))
            {
                LeanplumRequest.UserId = deviceId;
            }

            // Setup parameters.
            var parameters = new Dictionary <string, string>();

            parameters[Constants.Params.INCLUDE_DEFAULTS]      = false.ToString();
            parameters[Constants.Params.VERSION_NAME]          = CompatibilityLayer.VersionName ?? "";
            parameters[Constants.Params.DEVICE_NAME]           = CompatibilityLayer.GetDeviceName();
            parameters[Constants.Params.DEVICE_MODEL]          = CompatibilityLayer.GetDeviceModel();
            parameters[Constants.Params.DEVICE_SYSTEM_NAME]    = CompatibilityLayer.GetSystemName();
            parameters[Constants.Params.DEVICE_SYSTEM_VERSION] =
                CompatibilityLayer.GetSystemVersion();
            TimeZone timezone = System.TimeZone.CurrentTimeZone;

            if (timezone.IsDaylightSavingTime(DateTime.UtcNow))
            {
                parameters[Constants.Keys.TIMEZONE] = timezone.DaylightName;
            }
            else
            {
                parameters[Constants.Keys.TIMEZONE] = timezone.StandardName;
            }
            parameters[Constants.Keys.TIMEZONE_OFFSET_SECONDS] =
                timezone.GetUtcOffset(DateTime.UtcNow).TotalSeconds.ToString();
            parameters[Constants.Keys.COUNTRY]  = Constants.Values.DETECT;
            parameters[Constants.Keys.REGION]   = Constants.Values.DETECT;
            parameters[Constants.Keys.CITY]     = Constants.Values.DETECT;
            parameters[Constants.Keys.LOCATION] = Constants.Values.DETECT;
            if (attributes != null)
            {
                parameters[Constants.Params.USER_ATTRIBUTES] = Json.Serialize(attributes);
            }

            // Issue start API call.
            LeanplumRequest req = LeanplumRequest.Post(Constants.Methods.START, parameters);

            req.Response += delegate(object responsesObject)
            {
                IDictionary <string, object> response =
                    Util.GetLastResponse(responsesObject) as IDictionary <string, object>;
                IDictionary <string, object> values =
                    Util.GetValueOrDefault(response, Constants.Keys.VARS) as
                    IDictionary <string, object> ?? new Dictionary <string, object>();
                IDictionary <string, object> fileAttributes =
                    Util.GetValueOrDefault(response, Constants.Keys.FILE_ATTRIBUTES) as
                    IDictionary <string, object> ?? new Dictionary <string, object>();
                List <object> variants = Util.GetValueOrDefault(response, Constants.Keys.VARIANTS) as
                                         List <object> ?? new List <object>();
                bool isRegistered = (bool)Util.GetValueOrDefault(response,
                                                                 Constants.Keys.IS_REGISTERED, false);

                LeanplumRequest.Token = Util.GetValueOrDefault(response, Constants.Keys.TOKEN) as
                                        string ?? "";

                // Allow bidirectional realtime variable updates.
                if (Constants.isDevelopmentModeEnabled)
                {
                    VarCache.SetDevModeValuesFromServer(
                        Util.GetValueOrDefault(response, Constants.Keys.VARS_FROM_CODE) as
                        Dictionary <string, object>);

                    if (Constants.EnableRealtimeUpdatesInDevelopmentMode &&
                        SocketUtilsFactory.Utils.AreSocketsAvailable)
                    {
                        leanplumSocket = new LeanplumSocket(delegate() {
                            // Callback when we receive an updateVars command through the
                            // development socket.
                            // Set a flag so that the next time VarCache.CheckVarsUpdate() is
                            // called the variables are updated.
                            VarCache.VarsNeedUpdate = true;
                        });
                    }

                    // Register device.
                    if (isRegistered)
                    {
                        // Check for updates.
                        string latestVersion = Util.GetValueOrDefault(response,
                                                                      Constants.Keys.LATEST_VERSION) as string;
                        if (latestVersion != null)
                        {
                            CompatibilityLayer.Log("Leanplum Unity SDK " + latestVersion +
                                                   " available. Go to https://www.leanplum.com/dashboard to " +
                                                   "download it.");
                        }
                        OnHasStartedAndRegisteredAsDeveloper();
                    }
                }

                VarCache.ApplyVariableDiffs(values, fileAttributes, variants);
                _hasStarted     = true;
                startSuccessful = true;
                OnStarted(true);
                CompatibilityLayer.Init();
            };
            req.Error += delegate
            {
                VarCache.ApplyVariableDiffs(null, null);
                _hasStarted     = true;
                startSuccessful = false;
                OnStarted(false);
                CompatibilityLayer.Init();
            };
            req.SendIfConnected();
        }
Example #7
0
 /// <summary>
 ///     Call this when your application starts.
 ///     This will initiate a call to Leanplum's servers to get the values
 ///     of the variables used in your app.
 /// </summary>
 public abstract void Start(string userId, IDictionary <string, object> attributes,
                            Leanplum.StartHandler startResponseAction);