Class: ParamBuilder
- Inherits:
-
Object
- Object
- ParamBuilder
- Defined in:
- lib/capi_param_builder.rb
Constant Summary collapse
- FBC_NAME =
"_fbc"- FBP_NAME =
"_fbp"- DEFAULT_1PC_AGE =
90 * 24 * 3600
- LANGUAGE_TOKEN =
Original Ruby language token
"BQ"- SUPPORTED_LANGUAGE_TOKENS =
["AQ", "Ag", "Aw", "BA", "BQ", "Bg"]
- MIN_PAYLOAD_SPLIT_LENGTH =
4- MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH =
5- IPV4_REGEX =
/\A(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/- IPV6_REGEX =
/\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,7}:\z|\A(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}\z|\A(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}\z|\A(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}\z|\A[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}\z|\A:(?::[0-9a-fA-F]{1,4}){1,7}\z|\A::\z|\A(?:[0-9a-fA-F]{1,4}:){6}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/- DEFAULT_FORMAT =
Appendix constants
0x01- LANGUAGE_TOKEN_INDEX =
Ruby language token index
0x05- APPENDIX_LENGTH_V1 =
2- APPENDIX_LENGTH_V2 =
8- APPENDIX_NO_CHANGE =
Appendix type constants
0x00- APPENDIX_GENERAL_NEW =
0x01- APPENDIX_NET_NEW =
0x02- APPENDIX_MODIFIED_NEW =
0x03
Instance Method Summary collapse
- #get_cookies_to_set ⇒ Object
- #get_event_source_url ⇒ Object
- #get_fbc ⇒ Object
- #get_fbp ⇒ Object
- #get_referrer_url ⇒ Object
-
#initialize(input = nil) ⇒ ParamBuilder
constructor
A new instance of ParamBuilder.
- #process_request(host, queries, cookies, referer = nil) ⇒ Object
-
#process_request_from_context(context = nil) ⇒ Object
Process a request from a context object.
Constructor Details
#initialize(input = nil) ⇒ ParamBuilder
Returns a new instance of ParamBuilder.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/capi_param_builder.rb', line 40 def initialize(input = nil) @fbc_params_configs = [FbcParamConfigs.new("fbclid", "", "clickID")] @appendix_net_new = get_appendix(APPENDIX_NET_NEW) @appendix_modified_new = get_appendix(APPENDIX_MODIFIED_NEW) @appendix_no_change = get_appendix(APPENDIX_NO_CHANGE) @referrer_url = nil @event_source_url = nil if input.nil? return end if input.is_a?(Array) @domain_list = [] input.each do |domain_item| @domain_list.push(extract_host_from_http_host(domain_item.downcase)) end elsif input.is_a?(EtldPlusOneResolver) @etld_plus_one_resolver = input end end |
Instance Method Details
#get_cookies_to_set ⇒ Object
239 240 241 |
# File 'lib/capi_param_builder.rb', line 239 def () return @cookie_to_set end |
#get_event_source_url ⇒ Object
255 256 257 |
# File 'lib/capi_param_builder.rb', line 255 def get_event_source_url() return @event_source_url end |
#get_fbc ⇒ Object
243 244 245 |
# File 'lib/capi_param_builder.rb', line 243 def get_fbc() return @fbc end |
#get_fbp ⇒ Object
247 248 249 |
# File 'lib/capi_param_builder.rb', line 247 def get_fbp() return @fbp end |
#get_referrer_url ⇒ Object
251 252 253 |
# File 'lib/capi_param_builder.rb', line 251 def get_referrer_url() return @referrer_url end |
#process_request(host, queries, cookies, referer = nil) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/capi_param_builder.rb', line 181 def process_request(host, queries, , referer=nil) @event_source_url = nil compute_etld_plus_one_for_host(host) @cookie_to_set_dict = {} @cookie_to_set = Set.new() @fbc = (, FBC_NAME) @fbp = (, FBP_NAME) @referrer_url = referer if @referrer_url.is_a?(String) && !@referrer_url.empty? @referrer_url = "#{@referrer_url}.#{@appendix_no_change}" end # Get new fbc payload new_fbc_payload = get_new_fbc_payload_from_url(queries, referer) # fbc update = (@fbc, new_fbc_payload) if !.nil? @cookie_to_set_dict[FBC_NAME] = @fbc = .value end # fbp update = (@fbp) if !.nil? @cookie_to_set_dict[FBP_NAME] = @fbp = .value end @cookie_to_set = Set.new(@cookie_to_set_dict.values) return @cookie_to_set end |
#process_request_from_context(context = nil) ⇒ Object
Process a request from a context object.
Accepts either a PlainDataObject (used directly) or any framework request / Rack-style env Hash that RequestContextAdaptor knows how to extract from. Nil falls through to the adapter’s empty-default behavior.
Note: PlainDataObject carries x_forwarded_for and remote_address for parity with the JS / PHP SDKs, but the Ruby ParamBuilder does not yet implement client-IP attribution; those fields are extracted by the adapter but ignored here.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/capi_param_builder.rb', line 223 def process_request_from_context(context = nil) data = context.is_a?(PlainDataObject) ? context : RequestContextAdaptor.extract(context) process_request( data.host, data.query_params, data., data.referer ) @event_source_url = construct_event_source_url(data) return @cookie_to_set end |