287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/jekyll/attendease_plugin/tags.rb', line 287
def render(context)
site_settings = context.registers[:site].data['site_settings'].clone
analytics = site_settings['analytics']
has_analytics_id = !analytics.nil? && !analytics['googleAnalyticsTrackingId'].nil? && !analytics['googleAnalyticsTrackingId'].empty?
has_adwords_id = !analytics.nil? && !analytics['googleAnalyticsAdwordsId'].nil? && !analytics['googleAnalyticsAdwordsId'].empty?
return '' if analytics.nil? || (!has_analytics_id && !has_adwords_id)
gtag_id = has_analytics_id ? analytics['googleAnalyticsTrackingId'] : analytics['googleAnalyticsAdwordsId']
script = <<_EOT
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=#{gtag_id}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
#{ has_analytics_id ? " gtag('config', '#{analytics['googleAnalyticsTrackingId']}');" : ''}
#{ has_adwords_id ? " gtag('config', '#{analytics['googleAnalyticsAdwordsId']}');" : ''}
</script>
_EOT
script
end
|