3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/plataforma_social/utm.rb', line 3
def self.add_utm_to_url url, options = {}
settings = {
utm_source: 'dito',
utm_medium: nil,
utm_campaign: nil
}.merge options
parsedURL = URI.parse(url)
params = Rack::Utils.parse_nested_query(parsedURL.query).merge(settings)
hash = ''
if url.index('#')
splittedHash = url.split('#')
hash = splittedHash[1]
url = splittedHash[0]
end
url = url.split('?')[0] + '?' + params.to_param
url = url + '#' + hash if hash.present?
url
end
|