lib/analytical/console.rb in analytical-1.2.0 vs lib/analytical/console.rb in analytical-1.3.0
- old
+ new
@@ -11,33 +11,35 @@
def init_javascript(location)
init_location(location) do
js = <<-HTML
<!-- Analytical Init: Console -->
<script type="text/javascript">
- console.log('Analytical Init: Console');
+ if(typeof(console) !== 'undefined' && console != null) {
+ console.log('Analytical Init: Console');
+ }
</script>
HTML
js
end
end
def track(*args)
- "console.log(\"Analytical Track: \"+\"#{escape args.first}\");"
+ check_for_console "console.log(\"Analytical Track: \"+\"#{escape args.first}\");"
end
def identify(id, *args)
data = args.first || {}
- "console.log(\"Analytical Identify: \"+\"#{id}\"+\" \"+$H(#{data.to_json}).toJSON());"
+ check_for_console "console.log(\"Analytical Identify: \"+\"#{id}\"+\" \"+$H(#{data.to_json}).toJSON());"
end
def event(name, *args)
data = args.first || {}
- "console.log(\"Analytical Event: \"+\"#{name}\"+\" \"+$H(#{data.to_json}).toJSON());"
+ check_for_console "console.log(\"Analytical Event: \"+\"#{name}\"+\" \"+$H(#{data.to_json}).toJSON());"
end
def set(data)
- "console.log(\"Analytical Set: \"+$H(#{data.to_json}).toJSON());"
+ check_for_console "console.log(\"Analytical Set: \"+$H(#{data.to_json}).toJSON());"
end
private
CONSOLE_JS_ESCAPE_MAP = {
@@ -52,8 +54,12 @@
def escape(js)
js.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { CONSOLE_JS_ESCAPE_MAP[$1] }
end
+ def check_for_console(data)
+ "if(typeof(console) !== 'undefined' && console != null) { #{data} }"
+ end
+
end
end
-end
\ No newline at end of file
+end