<commit_before>---
layout: bootstrap
title: Guide
type: page
nav: nav
class: style-info
---

# Guide

## preload
preloadによる高速化実装例です。タッチデバイスでは動作できないため無効にしています。

<pre class="sh brush: html;">
&lt;script charset="utf-8" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="/js/jquery.preload.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="/js/jquery.pjax.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="/js/accelerate.js"&gt;&lt;/script&gt;
</pre>

preload: [https://github.com/falsandtru/jquery-preload](https://github.com/falsandtru/jquery-preload)  
pjax: [https://github.com/falsandtru/jquery-pjax](https://github.com/falsandtru/jquery-pjax)
accelerate:

<pre class="sh brush: js;">
// accelerate.js
  if (!/touch|tablet|mobile|phone|android|iphone|ipad|blackberry/i.test(window.navigator.userAgent)) {
    $.preload({
      forward: $.pjax.follow,
      check: $.pjax.getCache,
      encode: true,
      ajax: {
        success: function ( data, textStatus, XMLHttpRequest ) {
          !$.pjax.getCache( this.url ) && $.pjax.setCache( this.url, null, textStatus, XMLHttpRequest );
        }
      }
    });

    $.pjax({
      area: 'body',
      load: { head: 'base, meta, link', css: true, script: true },
      cache: { click: true, submit: false, popstate: true },
      speedcheck: true
    });

    $(document).bind('pjax:ready', function() {
      setTimeout(function () {
        $(document).trigger('preload');
      }, 2000);
  　});
  }
</pre>

## Google Analytics アクセス解析
ページに直接埋め込んで使用します。

###新 Google Analytics

<pre class="sh brush: js;">
  if (!window.ga) {
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-xxxxxxxx-x', 'auto');
    ga('require', 'displayfeatures');
  }
  ga('send', 'pageview', window.location.pathname.replace(/^\/?/, '/') + window.location.search);
</pre>

###旧 Google Analytics

<pre class="sh brush: js;">
  if (!window._gaq) {
    var _gaq = [];
    _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
    _gaq.push(['_trackPageview']);

    (function() {<commit_msg>Fix document<commit_after>---
layout: bootstrap
title: Guide
type: page
nav: nav
class: style-info
---

# Guide

## preload
preloadによる高速化実装例です。タッチデバイスでは動作できないため無効にしています。

<pre class="sh brush: html;">
&lt;script charset="utf-8" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="/js/jquery.preload.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="/js/jquery.pjax.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="/js/accelerate.js"&gt;&lt;/script&gt;
</pre>

preload: [https://github.com/falsandtru/jquery-preload](https://github.com/falsandtru/jquery-preload)  
pjax: [https://github.com/falsandtru/jquery-pjax](https://github.com/falsandtru/jquery-pjax)
accelerate:

<pre class="sh brush: js;">
// accelerate.js
  if (!/touch|tablet|mobile|phone|android|iphone|ipad|blackberry/i.test(window.navigator.userAgent)) {
    $.preload({
      forward: $.pjax.follow,
      check: $.pjax.getCache,
      encode: true,
      ajax: {
        success: function ( data, textStatus, XMLHttpRequest ) {
          !$.pjax.getCache( this.url ) && $.pjax.setCache( this.url, null, textStatus, XMLHttpRequest );
        }
      }
    });

    $.pjax({
      area: 'body',
      load: { head: 'base, meta, link', css: true, script: true },
      cache: { click: true, submit: false, popstate: true },
      speedcheck: true
    });

    $(document).bind('pjax:ready', function() {
      setTimeout(function () {
        $(document).trigger('preload');
      }, 2000);
  　});
  }
</pre>

## Google Analytics アクセス解析
ページに直接埋め込んで使用します。

### New Google Analytics

<pre class="sh brush: js;">
  if (!window.ga) {
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-xxxxxxxx-x', 'auto');
    ga('require', 'displayfeatures');
  }
  ga('send', 'pageview', window.location.pathname.replace(/^\/?/, '/') + window.location.search);
</pre>

### Old Google Analytics

<pre class="sh brush: js;">
  if (!window._gaq) {
    var _gaq = [];
    _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
    _gaq.push(['_trackPageview']);

    (function() {
{'fraction_non_alphanumeric': 0.21573976915005247, 'fraction_numerical': 0.005876180482686254, 'mean_word_length': 3.9337474120082816, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1424179', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1838, 'n_words': 267}