Skip to content

Commit

Permalink
refactor(sdk): add support to send tracking calls to the configured l…
Browse files Browse the repository at this point in the history
…ocation
  • Loading branch information
Abbas-khaliq authored and softvar committed Feb 23, 2022
1 parent f4fecab commit 02fc7d0
Show file tree
Hide file tree
Showing 46 changed files with 137 additions and 52 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.29.0] - 2022-02-23

### Changed

- Tracking data for the `Data Residency` enabled VWO accounts will be sent to the configured location
- Update year in all the copyright and liense headers

## [1.28.1] - 2022-01-23

### Changed
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2019-2021 Wingify Software Pvt. Ltd.
Copyright 2019-2022 Wingify Software Pvt. Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2019-2021 Wingify Software Pvt. Ltd.
Copyright 2019-2022 Wingify Software Pvt. Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ Please go through our [contributing guidelines](https://github.com/wingify/vwo-r

[Apache License, Version 2.0](https://github.com/wingify/vwo-ruby-sdk/blob/master/LICENSE)

Copyright 2019-2021 Wingify Software Pvt. Ltd.
Copyright 2019-2022 Wingify Software Pvt. Ltd.
4 changes: 2 additions & 2 deletions git-hooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

/**
* Copyright 2019-2021 Wingify Software Pvt. Ltd.
* Copyright 2019-2022 Wingify Software Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -248,7 +248,7 @@ let checkLicenseUtil = {
console.time('Execution time for License and Copyright');
console.log(`${AnsiColorEnum.CYAN}\nVerifying License and Copyright${AnsiColorEnum.RESET}\n`);
const isSuccess = checkLicenseUtil.checkLicenseAndCopyright({
year: `2019-2021`,
year: `2019-2022`,
author: 'Wingify Software Pvt. Ltd.',
paths: 'lib,tests',
stoppingCriteria: '\\*\\/',
Expand Down
5 changes: 4 additions & 1 deletion lib/vwo.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
require_relative 'vwo/utils/feature'
require_relative 'vwo/utils/custom_dimensions'
require_relative 'vwo/utils/utility'
require_relative 'vwo/utils/data_location_manager'
require_relative 'vwo/constants'
require_relative 'vwo/core/variation_decider'
require_relative 'vwo/services/batch_events_dispatcher'
Expand All @@ -41,6 +42,7 @@ class VWO
include Utils::Campaign
include Utils::Impression
include Utils::Utility
include VWO::Utils
include CONSTANTS

FILE = FileNameEnum::VWO
Expand Down Expand Up @@ -123,6 +125,7 @@ def initialize(
# Process the settings file
@config.process_settings_file
@settings_file = @config.get_settings_file
DataLocationManager.get_instance().set_settings(@settings_file)

@usage_stats = VWO::Services::UsageStats.new(usage_stats, @is_development_mode)

Expand Down
4 changes: 2 additions & 2 deletions lib/vwo/constants.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@ module CONSTANTS
HTTP_PROTOCOL = 'http://'
HTTPS_PROTOCOL = 'https://'
URL_NAMESPACE = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
SDK_VERSION = '1.28.1'
SDK_VERSION = '1.29.0'
SDK_NAME = 'ruby'
VWO_DELIMITER = '_vwo_'
MAX_EVENTS_PER_REQUEST = 5000
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/core/bucketer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/core/variation_decider.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/enums.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/logger.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
5 changes: 4 additions & 1 deletion lib/vwo/schemas/settings_file.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,9 @@ module Schema
isEventArchEnabled: {
type: ['boolean']
},
collectionPrefix: {
type: ['string']
},
campaigns: {
if: {
type: 'array'
Expand Down
6 changes: 4 additions & 2 deletions lib/vwo/services/batch_events_dispatcher.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,12 @@
require_relative '../logger'
require_relative '../enums'
require_relative '../utils/request'
require_relative '../utils/utility'
class VWO
module Services
class BatchEventsDispatcher
include VWO::Enums
include VWO::Utils::Utility
# Initialize the BatchEventDispatcher with logger and development mode
#
# @param [Boolean] : To specify whether the request
Expand All @@ -36,7 +38,7 @@ def initialize
# @return[Boolean]
#
def dispatch(impression, callback, query_params)
url = CONSTANTS::HTTPS_PROTOCOL + CONSTANTS::ENDPOINTS::BASE_URL + CONSTANTS::ENDPOINTS::BATCH_EVENTS
url = CONSTANTS::HTTPS_PROTOCOL + get_url(CONSTANTS::ENDPOINTS::BATCH_EVENTS)
account_id = query_params[:a]
resp = VWO::Utils::Request.post(url, query_params, impression)
if resp.code == '200'
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/batch_events_queue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
6 changes: 4 additions & 2 deletions lib/vwo/services/event_dispatcher.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,13 +15,15 @@
require_relative '../logger'
require_relative '../enums'
require_relative '../utils/request'
require_relative '../utils/utility'
require_relative '../constants'

class VWO
module Services
class EventDispatcher
include VWO::Enums
include VWO::CONSTANTS
include Utils::Utility

EXCLUDE_KEYS = ['url'].freeze

Expand Down Expand Up @@ -69,7 +71,7 @@ def dispatch(impression)
def dispatch_event_arch_post(params, post_data)
return true if @is_development_mode

url = HTTPS_PROTOCOL + ENDPOINTS::BASE_URL + ENDPOINTS::EVENTS
url = HTTPS_PROTOCOL + get_url(ENDPOINTS::EVENTS)
resp = VWO::Utils::Request.event_post(url, params, post_data, SDK_NAME)
if resp.code == '200'
@logger.log(
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/hooks_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/operand_evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/segment_evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/settings_file_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/settings_file_processor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/services/usage_stats.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/user_storage.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/utils/campaign.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions lib/vwo/utils/custom_dimensions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ module CustomDimensions
include VWO::Utils::Utility

def get_url_params(settings_file, tag_key, tag_value, user_id, sdk_key)
url = HTTPS_PROTOCOL + ENDPOINTS::BASE_URL + ENDPOINTS::PUSH
url = HTTPS_PROTOCOL + get_url(ENDPOINTS::PUSH)
tag = { 'u' => {} }
tag['u'][tag_key] = tag_value

Expand Down
46 changes: 46 additions & 0 deletions lib/vwo/utils/data_location_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


require_relative '../constants'

# Utility module for generating uuid
class VWO
module Utils
class DataLocationManager

@@instance = nil

def self.get_instance
if @@instance.nil?
@@instance = self.new
end
@@instance
end


def get_data_location
url = VWO::CONSTANTS::ENDPOINTS::BASE_URL
if @settings.key?("collectionPrefix")
url = url + '/' + @settings["collectionPrefix"]
end
url
end

def set_settings(settings)
@settings = settings
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vwo/utils/feature.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/utils/function.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
7 changes: 3 additions & 4 deletions lib/vwo/utils/impression.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,12 +67,11 @@ def create_impression(settings_file, campaign_id, variation_id, user_id, sdk_key

impression = usage_stats.merge(impression)

url = HTTPS_PROTOCOL + ENDPOINTS::BASE_URL
logger = VWO::Logger.get_instance

if is_track_user_api
impression['ed'] = JSON.generate(p: 'server')
impression['url'] = "#{url}#{ENDPOINTS::TRACK_USER}"
impression['url'] = HTTPS_PROTOCOL + get_url(ENDPOINTS::TRACK_USER)
logger.log(
LogLevelEnum::DEBUG,
format(
Expand All @@ -82,7 +81,7 @@ def create_impression(settings_file, campaign_id, variation_id, user_id, sdk_key
)
)
else
impression['url'] = url + ENDPOINTS::TRACK_GOAL
impression['url'] = HTTPS_PROTOCOL + get_url(ENDPOINTS::TRACK_GOAL)
impression['goal_id'] = goal_id
impression['r'] = revenue if revenue
logger.log(
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/utils/request.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/utils/segment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
10 changes: 9 additions & 1 deletion lib/vwo/utils/utility.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
# Copyright 2019-2022 Wingify Software Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,16 @@

require 'json'
require_relative './validations'
require_relative './data_location_manager'
require_relative '../constants'

# Generic utility module
class VWO
module Utils
module Utility
include Validations
include VWO::Utils
include VWO::CONSTANTS

# converting hash with keys as strings into hash with keys as strings
# @param[Hash]
Expand All @@ -42,6 +46,10 @@ def remove_sensitive_properties(properties)
properties.delete("env".to_sym)
JSON.generate(properties)
end

def get_url(endpoint)
return DataLocationManager.get_instance().get_data_location + endpoint
end
end
end
end
Loading

0 comments on commit 02fc7d0

Please sign in to comment.