/**
* コンストラクタの生成
*
* */
if (typeof BlzLinkC == 'undefined') {
/**
* コンストラクタ
* @param user ユーザーID
* @param template テンプレートID
* @param parts ツール名
*
* @return this
* */
var BlzLinkC = function(user, template, parts) {
this.user = user; // ユーザーID
this.tmp = template; // テンプレートID
this.parts = parts; // ツール名
return this;
};
//-----------------------------------
// 定数
//-----------------------------------
BlzLinkC.CONST = {
baseUrl : '//blozoo.com/', // アプリURL
cacheUrl : '//cache.blozoo.info/', // キャッシュサーバーURL
partsUrl : '//parts.blozoo.com/', // トラッキングサーバーURL
linkTrackUrl : '//link.blozoo.com/', // 広告ローテーショントラッキングサーバーURL
BLOG : [
'blog.livedoor.jp',
'ameblo.jp',
'blog.goo.ne.jp',
'yaplog.jp',
'ap.teacup.com',
'blog.oricon.co.jp',
'blog.3016.jp',
'maruta.be'
]
};
/**
* URLからドメインを取得する(ブログによってはディレクトリまで)
*/
BlzLinkC.prototype.getDomainUrl = function(url) {
// URLが存在しない
if (!url) return url;
// URLをパースする
var parser = document.createElement('a');
parser.href = url;
var protocol = parser.protocol,
hostname = parser.hostname,
pathname = parser.pathname;
pathname = pathname.indexOf('/') == 0 ? pathname : '/' + pathname;
var ret_url = protocol + '//' + hostname + '/';
// サブディレクトリブログ
var targetBlogs = BlzLinkC.CONST.BLOG;
for (var i = 0; i < targetBlogs.length; ++i) {
if (targetBlogs[i] === hostname) {
var path = pathname.split('/');
ret_url += path[1] + '/';
}
}
return ret_url;
};
/**
* インプレッション用のタグを取得
* */
BlzLinkC.prototype.imp = function() {
var img = document.createElement('img');
// parts.blozoo.com/p= !imp! [パーツ名] ! [テンプレートID] ! [ユーザID] ! [現在のURL] ! [リファラ] !
var _imp = BlzLinkC.CONST.partsUrl + 'parts.html?p=' + '!imp!' + this.parts + 'tool!' + this.tmp + '!' + this.user + '!' + BlzLinkC.prototype.getDomainUrl(location.href) + '!' + BlzLinkC.prototype.getDomainUrl(document.referrer) + '!' + '?_' + (new Date).getTime();
img.src = _imp;
img.style.width = '0px';
img.style.height = '0px';
img.style.display = 'none';
// 削除用IDを付加
img.id = 'imp' + '_' + this.parts + '_' + this.tmp + '_' + this.user;
// bodyに追加してトラッキングサーバーにリクエスト
document.getElementsByTagName('body')[0].appendChild(img);
// タグを削除
document.getElementById(img.id).parentNode.removeChild(document.getElementById(img.id));
};
/**
* 広告インプレッション用のタグを取得
* @param string tagId 広告ID
* */
BlzLinkC.prototype.impTag = function(tagId) {
if (!tagId) return false;
var img = document.createElement('img');
// link.blozoo.com/p= !imp! [テンプレートID] ! [広告タグID] [ユーザID] ! [現在のURL] ! [リファラ] !
var _imp = BlzLinkC.CONST.linkTrackUrl + 'link.html?p=' + '!imp!' + this.tmp + '!' + tagId + '!' + this.user + '!' + BlzLinkC.prototype.getDomainUrl(location.href) + '!' + BlzLinkC.prototype.getDomainUrl(document.referrer) + '!' + '?_' + (new Date).getTime();
img.src = _imp;
img.style.width = '0px';
img.style.height = '0px';
img.style.display = 'none';
// 削除用IDを付加
img.id = 'imp' + '_' + this.parts + '_' + this.tmp + '_' + this.user + '_' + tagId;
// bodyに追加してトラッキングサーバーにリクエスト
document.getElementsByTagName('body')[0].appendChild(img);
// タグを削除
document.getElementById(img.id).parentNode.removeChild(document.getElementById(img.id));
};
};
/**
* 即時関数
*
* */
(function() {
//-----------------------------------
// データチェック
//-----------------------------------
if(!blzU || !blzT || !blzP) return;
//-----------------------------------
// 実行スクリプトのオブジェクトを作成
//-----------------------------------
BlzLinkC[blzU + '_' + blzT + '_' + blzP] = {
'user' : blzU,
'tmp' : blzT,
'tool' : blzP
};
//-----------------------------------
// パーツ表示
//-----------------------------------
// インスタンスを生成
var blozoo = new BlzLinkC(blzU, blzT, blzP);
// 挿入要素のノードを取得
var target = document.getElementById('blz_' + blzP + '_' + blzU + '_' + blzT);
if (window['blzLinkToolTag_' + blzU + '_' + blzT]) {
// サービスタグの書き出し
document.write(window['blzLinkToolTag_' + blzU + '_' + blzT]);
// インプッションを計測
blozoo.imp();
// 広告のインプレッションを計測
blozoo.impTag(window['blzLinkToolTagId_' + blzU + '_' + blzT]);
}
if ( window['blzOverad'] == undefined ) {
if (typeof(blzAC) != "undefined") {
var bac = blzAC;
} else {
var bac = '';
}
document.write('');
}
// 各値を初期化
blzU = blzT = blzP = undefined;
if ( typeof(blzAC) != "undefined" ) {
blzAC = undefined;
}
})();