class Feeligo::Stickers::LoaderScriptTag
Public Class Methods
new(opts)
click to toggle source
# File lib/feeligo/stickers/loader_script_tag.rb, line 6 def initialize opts @opts = opts end
Public Instance Methods
to_s()
click to toggle source
# File lib/feeligo/stickers/loader_script_tag.rb, line 11 def to_s code = "<script type='text/javascript'>\n#{js_code}</script>" if code.respond_to?(:html_safe) then code.html_safe else code end end
Protected Instance Methods
client_hostname()
click to toggle source
The hostname of the client Community if unspecified will use the document.location.hostname JS variable
# File lib/feeligo/stickers/loader_script_tag.rb, line 69 def client_hostname @opts[:hostname] end
feeligo_api_hostname()
click to toggle source
The hostname of Feeligo's API defaults to stickersapi.feeligo.com, or stickersapissl.feeligo.com if https
# File lib/feeligo/stickers/loader_script_tag.rb, line 51 def feeligo_api_hostname @opts[:feeligo_api_hostname] || if protocol.to_s == 'https' 'stickersapissl.feeligo.com' else 'stickersapi.feeligo.com' end end
js_code()
click to toggle source
The Javascript code
# File lib/feeligo/stickers/loader_script_tag.rb, line 23 def js_code product = 'feeligo-stickers-ruby' version = Feeligo::Stickers::VERSION user_id = self.user_id ? ",'#{self.user_id}'" : "" hostname = client_hostname || "'+ee.location.hostname+'" <<-JS (function(f,ee,l,i,g,o){f[l]=f[l]||{};o&&(o+='').length?(f[l].context={viewer: {id:o},platform:{name:i,version:g}})&&(o='-'+o):(o='');(function(s,t,k,r){ t=ee.createElement(r='script');k=ee.getElementsByTagName(r)[0];t.async=1;t.src=s; k.parentNode.insertBefore(t,k);})('#{protocol}://#{feeligo_api_hostname}/#{hostname}/loader'+o+'.js'); f[l].q=[];f[l].on=function(s,t,k){f[l].q.push([s,t,k])}; })(window,document,'flg','#{product}','#{version}'#{user_id}); JS end
protocol()
click to toggle source
The protocol used to load the loader script defaults to http
# File lib/feeligo/stickers/loader_script_tag.rb, line 62 def protocol @opts[:protocol] || 'http' end
user_id()
click to toggle source
The user id if provided and valid, or nil otherwise
# File lib/feeligo/stickers/loader_script_tag.rb, line 40 def user_id if (id = (@opts[:user_id] || @opts['user_id'])) && id.respond_to?(:to_s) if (id = id.to_s).size > 0 && id != '0' return id end end end