Skip to content

Commit 9164c50

Browse files
committed
Add more analytics and commenting options
1 parent 3bd495f commit 9164c50

File tree

13 files changed

+111
-42
lines changed

13 files changed

+111
-42
lines changed

_config.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ facebook:
2424
username : &facebook "site_facebook"
2525
app_id :
2626
publisher :
27-
disqus_shortname : "mmistakes-dev" # https://help.disqus.com/customer/portal/articles/466208-what-s-a-shortname-
27+
comments:
28+
provider : false # false (default), "disqus", "facebook", "google-plus", custom"
29+
disqus:
30+
shortname : "mmistakes-dev" # https://help.disqus.com/customer/portal/articles/466208-what-s-a-shortname-
31+
facebook:
32+
# https://developers.facebook.com/docs/plugins/comments
33+
appid :
34+
num_posts : # 5 (default)
35+
width : # 580 (default)
36+
colorscheme : # "light" (default), "dark"
2837
google_site_verification :
2938
bing_site_verification :
3039
alexa_site_verification :
3140
yandex_site_verification :
32-
google_analytics : # Universal Analytics tracking ID
41+
analytics:
42+
provider : false # false (default), "google", "google-universal", "custom"
43+
google:
44+
tracking_id : "UA-123456-7"
3345
google_ad_client :
3446
google_ad_slot :
3547

_includes/analytics

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% if site.analytics.provider and page.analytics != false %}
2+
3+
{% case site.analytics.provider %}
4+
{% when "google" %}
5+
{% include /analytics-providers/google %}
6+
{% when "google-universal" %}
7+
{% include /analytics-providers/google-universal %}
8+
{% when "custom" %}
9+
{% include /analytics-providers/custom %}
10+
{% endcase %}
11+
12+
{% endif %}

_includes/analytics-providers/custom

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- start custom analytics snippet -->
2+
3+
<!-- end custom analytics snippet -->

_includes/analytics-providers/google

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script type="text/javascript">
2+
var _gaq = _gaq || [];
3+
_gaq.push(['_setAccount', '{{ site.analytics.google.tracking_id }}']);
4+
_gaq.push(['_trackPageview']);
5+
6+
(function() {
7+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
8+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
9+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
10+
})();
11+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
3+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
4+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
5+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
6+
7+
ga('create', {{ site.analytics.google.tracking_id }}', 'auto');
8+
ga('send', 'pageview');
9+
</script>

_includes/comments

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% if site.comments.provider and page.comments %}
2+
3+
{% case site.comments.provider %}
4+
{% when "disqus" %}
5+
{% include /comments-providers/disqus %}
6+
{% when "facebook" %}
7+
{% include /comments-providers/facebook %}
8+
{% when "google-plus" %}
9+
{% include /comments-providers/google-plus %}
10+
{% when "custom" %}
11+
{% include /comments-providers/custom %}
12+
{% endcase %}
13+
14+
{% endif %}

_includes/comments-providers/custom

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- start custom comments snippet -->
2+
3+
<!-- end custom comments snippet -->

_includes/comments-providers/disqus

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{% if site.comments.disqus.shortname %}
2+
<script type="text/javascript">
3+
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
4+
var disqus_shortname = '{{ site.comments.disqus.shortname }}';
5+
6+
/* * * DON'T EDIT BELOW THIS LINE * * */
7+
(function() {
8+
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
9+
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
10+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
11+
})();
12+
13+
/* * * DON'T EDIT BELOW THIS LINE * * */
14+
(function () {
15+
var s = document.createElement('script'); s.async = true;
16+
s.type = 'text/javascript';
17+
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
18+
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
19+
}());
20+
</script>
21+
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
22+
{% endif %}

_includes/comments-providers/facebook

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div id="fb-root"></div>
2+
<script>(function(d, s, id) {
3+
var js, fjs = d.getElementsByTagName(s)[0];
4+
if (d.getElementById(id)) return;
5+
js = d.createElement(s); js.id = id;
6+
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5{% if site.comments.facebook.appid %}&appId={{ site.comments.facebook.appid }}{% endif %}";
7+
fjs.parentNode.insertBefore(js, fjs);
8+
}(document, 'script', 'facebook-jssdk'));</script>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script async type="text/javascript" src="//apis.google.com/js/plusone.js?callback=gpcb"></script>
2+
<noscript>Please enable JavaScript to view the <a href="https://plus.google.com/">comments powered by Google+.</a></noscript>

_includes/disqus-comments

-22
This file was deleted.

_includes/scripts

+2-16
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,5 @@
22
<script>window.jQuery || document.write('<script src="{{ base_path }}/assets/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
33
<script src="{{ base_path }}/assets/js/scripts.min.js"></script>
44

5-
{% if site.google_analytics %}
6-
<script>
7-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
8-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
9-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
10-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
11-
12-
ga('create', '{{ site.google_analytics }}', 'auto');
13-
ga('send', 'pageview');
14-
15-
</script>
16-
{% endif %}
17-
18-
{% if page.comments %}
19-
{% include disqus-comments %}
20-
{% endif %}
5+
{% include analytics %}
6+
{% include comments %}

_layouts/single.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ <h1 itemprop="headline"><a href="{{ base_path }}{{ page.url }}" rel="bookmark">{
3232
</footer>
3333
</div><!-- /.article-wrap -->
3434

35-
{% if site.disqus_shortname and page.comments %}
36-
<section id="disqus_thread"></section><!-- /#disqus_thread -->
35+
{% if site.comments.provider and page.comments %}
36+
{% case site.comments.provider %}
37+
{% when "disqus" %}
38+
<section id="disqus_thread"></section>
39+
{% when "facebook" %}
40+
<section class="fb-comments" data-href="{{ base_path }}{{ page.url }}" data-num-posts="{{ site.comments.facebook.num_posts | default: 5 }}" data-width="{{ site.comments.facebook.width | default: 580 }}" data-colorscheme="{{ site.comments.facebook.colorscheme | default: 'light' }}"></section>
41+
{% when "google-plus" %}
42+
<section class="g-comments" data-href="{{ base_path }}{{ page.url }}" data-first_party_property="BLOGGER" data-view_type="FILTERED_POSTMOD">Loading Google+ Comments ...</section>
43+
{% when "custom" %}
44+
<section id="comments"></section>
45+
{% endcase %}
3746
{% endif %}
3847
</article>
3948

0 commit comments

Comments
 (0)