Class: Kameleoon::KameleoonClient

Inherits:
Object
  • Object
show all
Includes:
Exception
Defined in:
lib/kameleoon/kameleoon_client.rb

Overview

Client for Kameleoon

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_code, config) ⇒ KameleoonClient

You should create KameleoonClient with the Client Factory only.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/kameleoon/kameleoon_client.rb', line 46

def initialize(site_code, config)
  raise Exception::SiteCodeIsEmpty, 'Provided site_sode is empty' if site_code&.empty? != false

  Logging::KameleoonLogger.info("CALL: KameleoonClient.new(site_code: '%s', config: %s)",
                                site_code, config)
  @scheduler = Rufus::Scheduler.new
  @site_code = site_code
  @config = config
  @real_time_configuration_service = nil
  @update_configuration_handler = nil
  @fetch_configuration_update_job = nil
  data_file = Configuration::DataFile.new(config.environment, nil)
  @data_manager = Managers::Data::DataManager.new(data_file)
  @visitor_manager = Kameleoon::DataManager::VisitorManager.new(
    @data_manager, config.session_duration_second, @scheduler
  )
  @hybrid_manager = Hybrid::ManagerImpl.new(HYBRID_EXPIRATION_TIME)
  @network_manager = Network::NetworkManager.new(
    config.environment,
    config.default_timeout_millisecond,
    Network::AccessTokenSourceFactory.new(config.client_id, config.client_secret),
    Network::UrlProvider.new(site_code)
  )
  @tracking_manager = Managers::Tracking::TrackingManager.new(
    @data_manager, @network_manager, @visitor_manager, config.tracking_interval_second, @scheduler
  )
  @warehouse_manager = Managers::Warehouse::WarehouseManager.new(@network_manager, @visitor_manager)
  @remote_data_manager = Managers::RemoteData::RemoteDataManager.new(
    @data_manager, @network_manager, @visitor_manager
  )
  @cookie_manager = Network::Cookie::CookieManager.new(@data_manager, config.top_level_domain)
  @readiness = ClientReadiness.new
  @targeting_manager = Targeting::TargetingManager.new(@data_manager, @visitor_manager)

  if @config.verbose_mode == true && Logging::KameleoonLogger.log_level == Logging::LogLevel::WARNING
    Logging::KameleoonLogger.log_level = Logging::LogLevel::INFO
  end

  Logging::KameleoonLogger.info("RETURN: KameleoonClient.new(site_code: '%s', config: %s)",
                                site_code, config)
end

Instance Attribute Details

#site_codeObject (readonly)

Returns the value of attribute site_code.



41
42
43
# File 'lib/kameleoon/kameleoon_client.rb', line 41

def site_code
  @site_code
end

Instance Method Details

#add_data(visitor_code, *args) ⇒ Object

Associate various data to a visitor.

Note that this method doesn’t return any value and doesn’t interact with the Kameleoon back-end servers by itself. Instead, the declared data is saved for future sending via the flush method. This reduces the number of server calls made, as data is usually grouped into a single server call triggered by the execution of the flush method.

Parameters:

  • visitor_code (String)

    Visitor code

  • data (...Data)

    Data to associate with the visitor code

Raises:



160
161
162
163
164
165
166
167
168
169
# File 'lib/kameleoon/kameleoon_client.rb', line 160

def add_data(visitor_code, *args)
  Logging::KameleoonLogger.info("CALL: KameleoonClient.add_data(visitor_code: '%s', args: %s)",
                                visitor_code, args)
  Utils::VisitorCode.validate(visitor_code)
  @visitor_manager.add_data(visitor_code, *args)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.add_data(visitor_code: '%s', args: %s)",
    visitor_code, args
  )
end

#feature_active?(visitor_code, feature_key, is_unique_identifier: nil) ⇒ Boolean

Check if feature is active for a given visitor code

This method takes a visitor_code and feature_key as mandatory arguments to check if the specified feature will be active for a given user. If such a user has never been associated with this feature flag, the SDK returns a boolean value randomly (true if the user should have this feature or false if not). If a user with a given visitorCode is already registered with this feature flag, it will detect the previous feature flag value. You have to make sure that proper error handling is set up in your code as shown in the example to the right to catch potential exceptions.

identifier. This field is optional.

Parameters:

  • visitor_code (String)

    Unique identifier of the user. This field is mandatory.

  • feature_key (String)

    Key of the feature flag you want to expose to a user. This field is mandatory.

  • is_unique_identifier(DEPRECATED) (Bool)

    Parameter that specifies whether the visitorCode is a unique

Returns:

  • (Boolean)

Raises:



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/kameleoon/kameleoon_client.rb', line 270

def feature_active?(visitor_code, feature_key, is_unique_identifier: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.feature_active?(visitor_code: '%s', feature_key: '%s', is_unique_identifier: %s)",
    visitor_code, feature_key, is_unique_identifier
  )
  Utils::VisitorCode.validate(visitor_code)
  set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
  _, variation_key = _get_feature_variation_key(visitor_code, feature_key)
  feature_active = variation_key != Kameleoon::Configuration::VariationType::VARIATION_OFF
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.feature_active?(visitor_code: '%s', feature_key: '%s', is_unique_identifier: %s) " \
      '-> (feature_active: false)', visitor_code, feature_key, is_unique_identifier
  )
  feature_active
rescue Exception::FeatureEnvironmentDisabled
  Logging::KameleoonLogger.debug('Feature environment disabled')
  false
end

#flush(visitor_code = nil, instant: false, is_unique_identifier: nil) ⇒ Object

Flush the associated data.

The data added with the method add_data, is not directly sent to the kameleoon servers. It’s stored and accumulated until it is sent automatically by the trigger_experiment or track_conversion methods. With this method you can manually send it.

according to the scheduled tracking interval (‘false`). identifier. This field is optional.

longer than 255 chars

Parameters:

  • visitor_code (String) (defaults to: nil)

    Optional field - Visitor code, without visitor code it flush all of the data

  • instant (Bool) (defaults to: false)

    A boolean flag indicating whether the data should be sent instantly (‘true`) or

  • is_unique_identifier(DEPRECATED) (Bool)

    Parameter that specifies whether the visitorCode is a unique

Raises:



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/kameleoon/kameleoon_client.rb', line 219

def flush(visitor_code = nil, instant: false, is_unique_identifier: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.flush(visitor_code: '%s', instant: %s, is_unique_identifier: %s)",
                                visitor_code, instant, is_unique_identifier
  )
  if visitor_code.nil?
    @visitor_manager.enumerate do |visitor_code, visitor|
      has_unsent_data = false
      visitor.enumerate_sendable_data do |data|
        if data.unsent
          has_unsent_data = true
          next false
        end
        next true
      end
      @tracking_manager.add_visitor_code(visitor_code) if has_unsent_data
    end
  else
    Utils::VisitorCode.validate(visitor_code)
    set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
    if instant
      @tracking_manager.track_visitor(visitor_code)
    else
      @tracking_manager.add_visitor_code(visitor_code)
    end
  end
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.flush(visitor_code: '%s', instant: %s, is_unique_identifier: %s)",
    visitor_code, instant, is_unique_identifier
  )
end

#get_active_feature_list_for_visitor(visitor_code) ⇒ Array

Returns a list of active feature flag keys for a visitor

DEPRECATED. Please use ‘get_active_features` instead.

Returns:

  • (Array)

    array of active feature flag keys for a visitor

Raises:



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/kameleoon/kameleoon_client.rb', line 510

def get_active_feature_list_for_visitor(visitor_code)
  Logging::KameleoonLogger.warning('[DEPRECATION] `get_active_feature_list_for_visitor` is deprecated.' \
                                     ' Please use `get_active_features` instead.')
  Logging::KameleoonLogger.info("CALL: KameleoonClient.get_active_feature_list_for_visitor(visitor_code: '%s')",
                                visitor_code)
  Utils::VisitorCode.validate(visitor_code)
  list_keys = []
  @data_manager.data_file.feature_flags.each do |feature_key, feature_flag|
    next unless feature_flag.environment_enabled

    variation, rule, = _calculate_variation_key_for_feature(visitor_code, feature_flag)
    variation_key = _get_variation_key(variation, rule, feature_flag)
    list_keys.push(feature_key) if variation_key != Kameleoon::Configuration::VariationType::VARIATION_OFF
  end
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_active_feature_list_for_visitor(visitor_code: '%s') -> (features: %s)",
    visitor_code, list_keys
  )
  list_keys
end

#get_active_features(visitor_code) ⇒ Hash

Returns a Hash that contains the assigned variations of the active features using the keys

of the corresponding active features.

Parameters:

  • visitor_code (String)

    unique identifier of a visitor.

Returns:

  • (Hash)

    Hash of active features for a visitor

Raises:



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/kameleoon/kameleoon_client.rb', line 540

def get_active_features(visitor_code)
  Logging::KameleoonLogger.info("CALL: KameleoonClient.get_active_features(visitor_code: '%s')", visitor_code)
  Utils::VisitorCode.validate(visitor_code)
  map_active_features = {}

  @data_manager.data_file.feature_flags.each_value do |feature_flag|
    next unless feature_flag.environment_enabled

    var_by_exp, rule = _calculate_variation_key_for_feature(visitor_code, feature_flag)
    variation_key = _get_variation_key(var_by_exp, rule, feature_flag)

    next if variation_key == Configuration::VariationType::VARIATION_OFF

    variation = feature_flag.get_variation_key(variation_key)
    variables = {}

    variation&.variables&.each do |variable|
      variables[variable.key] = Kameleoon::Types::Variable.new(
        variable.key,
        variable.type,
        _parse_feature_variable(variable)
      )
    end

    variables.freeze
    map_active_features[feature_flag.feature_key] = Kameleoon::Types::Variation.new(
      variation_key,
      var_by_exp ? var_by_exp.variation_id : nil,
      rule ? rule.experiment_id : nil,
      variables
    )
  end

  map_active_features.freeze
  Logging::KameleoonLogger.info("RETURN: KameleoonClient.get_active_features(visitor_code: '%s') -> (features: %s)",
                                visitor_code, map_active_features)
  map_active_features
end

#get_engine_tracking_code(visitor_code) ⇒ String

The ‘get_engine_tracking_code` returns the JavasScript code to be inserted in your page to send automatically the exposure events to the analytics solution you are using.

the exposure events to the analytics solution you are using.

Parameters:

  • visitor_code (String)

    The user’s unique identifier. This field is mandatory.

Returns:

  • (String)

    JavasScript code to be inserted in your page to send automatically



599
600
601
602
603
604
605
606
607
608
# File 'lib/kameleoon/kameleoon_client.rb', line 599

def get_engine_tracking_code(visitor_code)
  Logging::KameleoonLogger.info("CALL: KameleoonClient.get_engine_tracking_code(visitor_code: '%s')", visitor_code)
  visitor_variations = @visitor_manager.get_visitor(visitor_code)&.variations
  engine_tracking_code = @hybrid_manager.get_engine_tracking_code(visitor_variations)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_engine_tracking_code(visitor_code: '%s') -> (engine_tracking_code: '%s')",
    visitor_code, engine_tracking_code
  )
  engine_tracking_code
end

#get_feature_listArray

Returns a list of all feature flag keys

Returns:

  • (Array)

    array of all feature flag keys



495
496
497
498
499
500
# File 'lib/kameleoon/kameleoon_client.rb', line 495

def get_feature_list # rubocop:disable Naming/AccessorMethodName
  Logging::KameleoonLogger.info('CALL: KameleoonClient.get_feature_list')
  features = @data_manager.data_file.feature_flags.keys
  Logging::KameleoonLogger.info('RETURN: KameleoonClient.get_feature_list -> (features: %s)', features)
  features
end

#get_feature_variable(visitor_code, feature_key, variable_name, is_unique_identifier: nil) ⇒ Object

Retrieves a feature variable value from assigned for visitor variation

A feature variable can be changed easily via our web application.

identifier. This field is optional.

the current environment

Parameters:

  • visitor_code (String)
  • feature_key (String)
  • variable_name (String)
  • is_unique_identifier(DEPRECATED) (Bool)

    Parameter that specifies whether the visitorCode is a unique

Raises:



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/kameleoon/kameleoon_client.rb', line 342

def get_feature_variable(visitor_code, feature_key, variable_name, is_unique_identifier: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.get_feature_variable(visitor_code: '%s', feature_key: '%s', variable_name: '%s', " \
      'is_unique_identifier: %s)', visitor_code, feature_key, variable_name, is_unique_identifier
  )
  Utils::VisitorCode.validate(visitor_code)
  set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
  feature_flag, variation_key = _get_feature_variation_key(visitor_code, feature_key)
  variation = feature_flag.get_variation_key(variation_key)
  variable = variation&.get_variable_by_key(variable_name)
  if variable.nil?
    raise Exception::FeatureVariableNotFound.new(variable_name),
          "Feature variable #{variable_name} not found"
  end
  value = _parse_feature_variable(variable)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_feature_variable(visitor_code: '%s', feature_key: '%s', variable_name: '%s', " \
      'is_unique_identifier: %s) -> (variable: %s)',
    visitor_code, feature_key, variable_name, is_unique_identifier, value
  )
  value
end

#get_feature_variation_key(visitor_code, feature_key, is_unique_identifier: nil) ⇒ Object

get_feature_variation_key returns a variation key for visitor code

This method takes a visitorCode and featureKey as mandatory arguments and returns a variation assigned for a given visitor If such a user has never been associated with any feature flag rules, the SDK returns a default variation key You have to make sure that proper error handling is set up in your code as shown in the example to the right to catch potential exceptions.

identifier. This field is optional.

the current environment

Parameters:

  • visitor_code (String)
  • feature_key (String)
  • is_unique_identifier(DEPRECATED) (Bool)

    Parameter that specifies whether the visitorCode is a unique

Raises:



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/kameleoon/kameleoon_client.rb', line 308

def get_feature_variation_key(visitor_code, feature_key, is_unique_identifier: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.get_feature_variation_key(visitor_code: '%s', feature_key: '%s', " \
      'is_unique_identifier: %s)',
    visitor_code, feature_key, is_unique_identifier
  )
  Utils::VisitorCode.validate(visitor_code)
  set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
  _, variation_key = _get_feature_variation_key(visitor_code, feature_key)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_feature_variation_key(visitor_code: '%s', feature_key: '%s', " \
      "is_unique_identifier: %s) -> (variation_key: '%s')",
    visitor_code, feature_key, is_unique_identifier, variation_key
  )
  variation_key
end

#get_feature_variation_variables(feature_key, variation_key) ⇒ Object

Retrieves all feature variable values for a given variation

This method takes a feature_key and variation_key as mandatory arguments and returns a list of variables for a given variation key A feature variable can be changed easily via our web application.

Parameters:

  • feature_key (String)
  • variation_key (String)

Raises:



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/kameleoon/kameleoon_client.rb', line 379

def get_feature_variation_variables(feature_key, variation_key)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.get_feature_variation_variables(feature_key: '%s', variation_key: '%s')",
    feature_key, variation_key
  )
  feature_flag = @data_manager.data_file.get_feature_flag(feature_key)
  variation = feature_flag.get_variation_key(variation_key)
  if variation.nil?
    raise Exception::FeatureVariationNotFound.new(variation_key),
          "Variation key #{variation_key} not found"
  end
  variables = {}
  variation.variables.each { |var| variables[var.key] = _parse_feature_variable(var) }
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_feature_variation_variables(feature_key: '%s', variation_key: '%s') " \
      '-> (variables: %s)', feature_key, variation_key, variables
  )
  variables
end

#get_remote_data(key, timeout = @default_timeout) ⇒ Hash

The get_remote_data method allows you to retrieve data (according to a key passed as argument) stored on a remote Kameleoon server. Usually data will be stored on our remote servers via the use of our Data API. This method, along with the availability of our highly scalable servers for this purpose, provides a convenient way to quickly store massive amounts of data that can be later retrieved for each of your visitors / users.

This field is optional.

Parameters:

  • key (String)

    Key you want to retrieve data. This field is mandatory.

  • timeout (Integer) (defaults to: @default_timeout)

    Timeout for request (in milliseconds). Equals default_timeout in a config file.

Returns:

  • (Hash)

    Hash object of the json object.



411
412
413
414
415
416
417
418
419
420
# File 'lib/kameleoon/kameleoon_client.rb', line 411

def get_remote_data(key, timeout = @default_timeout)
  Logging::KameleoonLogger.info("CALL: KameleoonClient.get_remote_data(key: '%s', timeout: %s)",
                                key, timeout)
  remote_data = @remote_data_manager.get_data(key, timeout)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_remote_data(key: '%s', timeout: %s) -> (remote_data: %s)",
    key, timeout, remote_data
  )
  remote_data
end

#get_remote_visitor_data(visitor_code, timeout = nil, add_data: true, filter: nil, is_unique_identifier: nil) ⇒ Array

The get_remote_visitor_data is a method for retrieving custom data for the latest visit of ‘visitor_code` from Kameleoon Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.

This field is mandatory. for a visitor. If not specified, the default value is ‘True`. This field is optional. This field is optional. identifier. This field is optional.

Parameters:

  • visitor_code (String)

    The visitor code for which you want to retrieve the assigned data.

  • add_data (Bool) (defaults to: true)

    A boolean indicating whether the method should automatically add retrieved data

  • timeout (Integer) (defaults to: nil)

    Timeout for request (in milliseconds). Equals default_timeout in a config file.

  • is_unique_identifier(DEPRECATED) (Bool)

    Parameter that specifies whether the visitorCode is a unique

Returns:

  • (Array)

    An array of data assigned to the given visitor.



438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/kameleoon/kameleoon_client.rb', line 438

def get_remote_visitor_data(visitor_code, timeout = nil, add_data: true, filter: nil, is_unique_identifier: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.get_remote_visitor_data(visitor_code: '%s', timeout: %s, add_data: %s, " \
      'filter: %s, is_unique_identifier: %s)', visitor_code, timeout, add_data, filter, is_unique_identifier
  )
  set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
  visitor_data = @remote_data_manager.get_visitor_data(visitor_code, add_data, filter, timeout)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_remote_visitor_data(visitor_code: '%s', timeout: %s, add_data: %s, " \
      'filter: %s, is_unique_identifier: %s) -> (visitor_data: %s)',
    visitor_code, timeout, add_data, filter, is_unique_identifier, visitor_data
  )
  visitor_data
end

#get_visitor_code(cookies, default_visitor_code = nil) ⇒ String

Note:

The implementation logic is described here:

Obtain a visitor code.

This method should be called to obtain the Kameleoon visitor_code for the current visitor. This is especially important when using Kameleoon in a mixed front-end and back-end environment, where user identification consistency must be guaranteed. First we check if a kameleoonVisitorCode cookie or query parameter associated with the current HTTP request can be found. If so, we will use this as the visitor identifier. If no cookie / parameter is found in the current request, we either randomly generate a new identifier, or use the default_visitor_code argument as identifier if it is passed. This allows our customers to use their own identifiers as visitor codes, should they wish to. This can have the added benefit of matching Kameleoon visitors with their own users without any additional look-ups in a matching table. In any case, the server-side (via HTTP header) kameleoonVisitorCode cookie is set with the value. Then this identifier value is finally returned by the method.

cookies = => ‘1234asdf4321fdsa’ visitor_code = get_visitor_code(cookies, ‘my-domaine.com’)

Parameters:

  • cookies (Hash)

    Cookies of the request.

  • top_level_domain (String)

    Top level domain of your website, settled while writing cookie.

  • default_visitor_code (String) (defaults to: nil)
    • Optional - Define your default visitor_code (maximum length 100 chars).

Returns:

  • (String)

    visitor code



121
122
123
124
125
126
127
128
129
130
# File 'lib/kameleoon/kameleoon_client.rb', line 121

def get_visitor_code(cookies, default_visitor_code = nil)
  Logging::KameleoonLogger.info("CALL: KameleoonClient.get_visitor_code(cookies: %s, default_visitor_code: '%s')",
                       cookies, default_visitor_code)
  visitor_code = @cookie_manager.get_or_add(cookies, default_visitor_code)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_visitor_code(cookies: %s, default_visitor_code: '%s') -> (visitor_code: '%s')",
    cookies, default_visitor_code, visitor_code
  )
  visitor_code
end

#get_visitor_warehouse_audience(visitor_code, custom_data_index, timeout = nil, warehouse_key: nil) ⇒ Kameleoon::CustomData

Retrieves data associated with a visitor’s warehouse audiences and adds it to the visitor. Retrieves all audience data associated with the visitor in your data warehouse using the specified ‘visitor_code` and `warehouse_key`. The `warehouse_key` is typically your internal user ID. The `custom_data_index` parameter corresponds to the Kameleoon custom data that Kameleoon uses to target your visitors. You can refer to the <a href=“help.kameleoon.com/warehouse-audience-targeting/”>warehouse targeting documentation</a> for additional details. The method returns a `CustomData` object, confirming that the data has been added to the visitor and is available for targeting purposes.

This field is mandatory. your BigQuery Audiences. This field is mandatory. This field is optional. This field is optional.

Parameters:

  • visitor_code (String)

    A unique visitor identification string, can’t exceed 255 characters length.

  • custom_data_index (Integer)

    An integer representing the index of the custom data you want to use to target

  • warehouse_key (String) (defaults to: nil)

    A key to identify the warehouse data, typically your internal user ID.

  • timeout (Integer) (defaults to: nil)

    Timeout for request (in milliseconds). Equals default_timeout in a config file.

Returns:

  • (Kameleoon::CustomData)

    A ‘CustomData` instance confirming that the data has been added to the visitor.

Raises:



476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/kameleoon/kameleoon_client.rb', line 476

def get_visitor_warehouse_audience(visitor_code, custom_data_index, timeout = nil, warehouse_key: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.get_visitor_warehouse_audience(visitor_code: '%s', custom_data_index: %s, " \
      "timeout: %s, warehouse_key: '%s')", visitor_code, custom_data_index, timeout, warehouse_key
  )
  warehouse_audience = @warehouse_manager.get_visitor_warehouse_audience(visitor_code,
                                                                         custom_data_index, warehouse_key, timeout)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.get_visitor_warehouse_audience(visitor_code: '%s', custom_data_index: %s, " \
      "timeout: %s, warehouse_key: '%s') -> (warehouse_audience: %s)",
    visitor_code, custom_data_index, timeout, warehouse_key, warehouse_audience
  )
  warehouse_audience
end

#on_update_configuration(handler) ⇒ Object

The ‘on_update_configuration()` method allows you to handle the event when configuration has updated data. It takes one input parameter: callable handler. The handler that will be called when the configuration is updated using a real-time configuration event.

is updated using a real-time configuration event.

Parameters:

  • handler (Callable | NilClass)

    The handler that will be called when the configuration



586
587
588
589
# File 'lib/kameleoon/kameleoon_client.rb', line 586

def on_update_configuration(handler)
  Logging::KameleoonLogger.info('CALL/RETURN: KameleoonClient.on_update_configuration(handler)')
  @update_configuration_handler = handler
end


132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/kameleoon/kameleoon_client.rb', line 132

def set_legal_consent(visitor_code, consent, cookies = nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.set_legal_consent(visitor_code: '%s', consent: %s, cookies: %s)",
    visitor_code, consent, cookies
  )
  Utils::VisitorCode.validate(visitor_code)
  visitor = @visitor_manager.get_or_create_visitor(visitor_code)
  visitor.legal_consent = consent
  @cookie_manager.update(visitor_code, consent, cookies)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.set_legal_consent(visitor_code: '%s', consent: %s, cookies: %s)",
    visitor_code, consent, cookies
  )
end

#track_conversion(visitor_code, goal_id, revenue = 0.0, is_unique_identifier: nil) ⇒ Object

Track conversions on a particular goal

This method requires visitor_code and goal_id to track conversion on this particular goal. In addition, this method also accepts revenue as a third optional argument to track revenue. The visitor_code usually is identical to the one that was used when triggering the experiment. The track_conversion method doesn’t return any value. This method is non-blocking as the server call is made asynchronously.

identifier. This field is optional.

Parameters:

  • visitor_code (String)

    Visitor code

  • goal_id (Integer)

    Id of the goal

  • revenue (Float) (defaults to: 0.0)

    Optional - Revenue of the conversion.

  • is_unique_identifier(DEPRECATED) (Bool)

    Parameter that specifies whether the visitorCode is a unique

Raises:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/kameleoon/kameleoon_client.rb', line 188

def track_conversion(visitor_code, goal_id, revenue = 0.0, is_unique_identifier: nil)
  Logging::KameleoonLogger.info(
    "CALL: KameleoonClient.track_conversion(visitor_code: '%s', goal_id: %s, revenue: %s, is_unique_identifier: %s)",
    visitor_code, goal_id, revenue, is_unique_identifier
  )
  Utils::VisitorCode.validate(visitor_code)
  set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
  add_data(visitor_code, Conversion.new(goal_id, revenue))
  @tracking_manager.add_visitor_code(visitor_code)
  Logging::KameleoonLogger.info(
    "RETURN: KameleoonClient.track_conversion(visitor_code: '%s', goal_id: %s, revenue: %s, is_unique_identifier: %s)",
    visitor_code, goal_id, revenue, is_unique_identifier
  )
end

#wait_initObject



88
89
90
91
92
93
# File 'lib/kameleoon/kameleoon_client.rb', line 88

def wait_init
  Logging::KameleoonLogger.info('CALL: KameleoonClient.wait_init')
  result = @readiness.wait
  Logging::KameleoonLogger.info('RETURN: KameleoonClient.wait_init -> (result: %s)', result)
  result
end