Skip to content

Instantly share code, notes, and snippets.

@katzueno
Last active December 11, 2016 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save katzueno/8d61e2a9e30614f098a698b3f96e8311 to your computer and use it in GitHub Desktop.
Save katzueno/8d61e2a9e30614f098a698b3f96e8311 to your computer and use it in GitHub Desktop.
<?php
/*
******************************
concrete5 ログインユーザーの属性を Mautic のトラッキングコードに引き渡すサンプル
******************************
concrete5 テーマファイルに実装していただく想定です。
concrete5 側のユーザー属性サンプル
メールアドレスは concrete5 のデフォルトのメールアドレスを取得する
last_name: 姓
first_name: 名
company: 会社名
Mautic 側で設定した属性のハンドル
email: メールアドレス (固定)
lastname: 姓
firstname: 名
company: 会社名
*/
// 自分のMautic サイトの URL (最後にスラッシュはつけない)
$mauticURL = 'https://katz.mautic.net';
// 左に Mautic の属性のハンドル、右側に concrete5 のユーザー属性のハンドルを入れる
// 1属性を1行ごとに分けてください
// concrete5 の属性のハンドルを間違えるとエラーが出るので気をつけてください
$attributeSettings = "lastname, last_name
firstname, first_name
company, company";
// Mautic & concrete5 の属性ここまで
$u = new User();
$mtTag = null;
if (is_object($u) && $u->checkLogin()) {
$mtTags = array();
$attributeSettings = explode(PHP_EOL, $attributeSettings);
if (is_array($attributeSettings)) {
foreach ($attributeSettings as $i => $attributeSetting) {
$path_array = explode(',', $attributeSetting);
$mtTags[$i]['mautic'] = trim($path_array[0]);
$mtTags[$i]['concrete5'] = trim($path_array[1]);
}
}
$ui = UserInfo::getByID($u->uID);
$mtTag = array('email' => $ui->getUserEmail()); // まず concrete5 のユーザーのメールアドレスを登録
if(is_array($mtTags)) {
foreach ($mtTags as $mtTagsItem) {
$mtTag = array_merge($mtTag,
array(
$mtTagsItem['mautic'] => $ui->getAttribute($mtTagsItem['concrete5'])
)
);
}
}
$mtTag = json_encode($mtTag, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
}
if(!$c->getAttribute('exclude_mautic_tracking')) {
?>
<script>
(function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
})(window,document,'script','<?php echo $mauticURL; ?>/mtc.js','mt');
<?php if( $mtTag ) { ?>
mt('send', 'pageview', <?php echo $mtTag; ?>);
<?php } else { ?>
mt('send', 'pageview');
<?php } ?>
</script>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment