class Crowdskout::Components::TrackingCode
Attributes
client[RW]
organization[RW]
source[RW]
Public Class Methods
create(props)
click to toggle source
Factory method to create a TrackingCode
object from a json string @param [Hash] props - properties to create object from @return [TrackingCode]
# File lib/crowdskout/components/quartermaster/tracking_code.rb, line 15 def self.create(props) obj = TrackingCode.new if props props.each do |key, value| obj.send("#{key}=", value.to_i) if obj.respond_to? key end end obj end
Public Instance Methods
tracking_code_source()
click to toggle source
Generate the crowdskout tracking source based on the codes @return [String] javascript function with the tracking information
# File lib/crowdskout/components/quartermaster/tracking_code.rb, line 27 def tracking_code_source if !source.nil? && !organization.nil? && !client.nil? %{ <!-- Crowdskout --> <script> (function(s,k,o,u,t){ s.cs=s.cs||function(){cs.q.push(arguments);}; cs.q=cs.q||[];cs.apiUrl=t; s.sourceId = #{source};s.clientId = #{client};s.organizationId = #{organization}; var a=k.getElementsByTagName(o)[0];var b=k.createElement(o);b.src=u+'/analytics.js'; b.onreadystatechange = b.onload = function() { if ((!b.readyState || /loaded|complete/.test(b.readyState))) { s._csCalledBackup = s._csCalled; s._csCalled = function(type, body) { if (type === 'page-view') { s.cspageviewuuid = body.uuid; } if (s._csCalledBackup) { s._csCalledBackup(type, body); } }; } }; a.parentNode.insertBefore(b,a); })(window,document,'script','//s.crowdskout.com','https://a.crowdskout.com'); </script> } else %{ Tracking Codes Error Source: #{source} Organization: #{organization} Client: #{client} } end end
tracking_code_source_no_script()
click to toggle source
Generate the crowdskout tracking source without script tags and minimized based on the codes @return [String] javascript function with the tracking information
# File lib/crowdskout/components/quartermaster/tracking_code.rb, line 66 def tracking_code_source_no_script if !source.nil? && !organization.nil? && !client.nil? script = "(function(s,k,o,u,t){s.cs=s.cs||function(){cs.q.push(arguments);};cs.q=cs.q||[];cs.apiUrl=t;s.sourceId = #{source};s.clientId = #{client};s.organizationId = #{organization};var a=k.getElementsByTagName(o)[0];var b=k.createElement(o);b.src=u+'/analytics.js';b.onreadystatechange = b.onload = function() {if ((!b.readyState || /loaded|complete/.test(b.readyState))) {s._csCalledBackup = s._csCalled;s._csCalled = function(type, body) {if (type === 'page-view') {s.cspageviewuuid = body.uuid;} if (s._csCalledBackup) {s._csCalledBackup(type, body);}};}};a.parentNode.insertBefore(b,a);})(window,document,'script','//s.crowdskout.com','https://a.crowdskout.com');" else %{ Tracking Codes Error Source: #{source} Organization: #{organization} Client: #{client} } end end