Sha256: 5bbda92645633c30e8e180955b100dcbe3f39d38016580527cf2a300838db9e6

Contents?: true

Size: 598 Bytes

Versions: 4

Compression:

Stored size: 598 Bytes

Contents

module PlataformaSocial
  class UTM
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
plataforma_social-0.0.38 lib/plataforma_social/utm.rb
plataforma_social-0.0.37 lib/plataforma_social/utm.rb
plataforma_social-0.0.36 lib/plataforma_social/utm.rb
plataforma_social-0.0.35 lib/plataforma_social/utm.rb