Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Googleアナリティクス機能を追加 #4912

Merged
merged 20 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Eccube/Entity/BaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ class BaseInfo extends \Eccube\Entity\AbstractEntity
*/
private $Pref;

/**
* @var string|null
*
* @ORM\Column(name="ga_id", type="string", length=255, nullable=true)
*/
private $ga_id;
chihiro-adachi marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get id.
*
Expand Down Expand Up @@ -1076,5 +1083,29 @@ public function setPhpPath($php_path)

return $this;
}

/**
* Set gaId.
*
* @param string|null $gaId
*
* @return BaseInfo
*/
public function setGaId($gaId = null)
{
$this->ga_id = $gaId;

return $this;
}

/**
* Get gaId.
*
* @return string|null
*/
public function getGaId()
{
return $this->ga_id;
}
}
}
8 changes: 8 additions & 0 deletions src/Eccube/Form/Type/Admin/ShopMasterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]),
],
])
->add('ga_id', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
;

$builder->add(
Expand Down
4 changes: 4 additions & 0 deletions src/Eccube/Resource/locale/messages.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ admin.common.device_type: 端末種別
admin.common.authority: 権限
admin.common.payment_method: 支払方法
admin.common.charge: 手数料
admin.common.ga.tracking_id: 'UA-XXXXXXXX-1'
#------------------------------------------------------------------------------------
# ホーム
#------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1115,6 +1116,8 @@ admin.setting.shop.shop.option_point: ポイント設定
admin.setting.shop.shop.option_point_enabled: ポイント機能
admin.setting.shop.shop.option_point_rate: ポイント付与率
admin.setting.shop.shop.option_point_conversion_rate: ポイント換算レート
admin.setting.shop.shop.ga: 'Googleアナリティクス設定'
admin.setting.shop.shop.ga.tracking_id: 'トラッキングID'

#------------------------------------------------------------------------------------
# 設定:店舗設定:支払方法設定
Expand Down Expand Up @@ -1597,6 +1600,7 @@ tooltip.setting.shop.shop.option_product_tax: オンにすると、商品別に
tooltip.setting.shop.shop.option_point_enabled: オンにすると、ポイント機能を有効化できます。
tooltip.setting.shop.shop.option_point_rate: 購入金額に対するポイント付与率を編集できます。
tooltip.setting.shop.shop.option_point_conversion_rate: 1ポイントあたりの換算レートです。例:「1」と設定すると1ポイント「1円」として利用可能になります。
tooltip.setting.shop.shop.ga.tracking_id: 'Googleアナリティクスでのサイトのアクセス解析を行う場合に設定してください。'
tooltip.setting.shop.payment.logo_image: 購入フローのお支払い方法に表示される画像を登録できます。登録がない場合は画像なしで表示されます。
tooltip.setting.shop.delivery.tracking_number_url: 配送業者のお問い合わせページURLを指定します。
tooltip.setting.shop.delivery.sale_type: この配送方法で取り扱える販売種別を指定します。
Expand Down
19 changes: 18 additions & 1 deletion src/Eccube/Resource/template/admin/Setting/Shop/shop_master.twig
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@ file that was distributed with this source code.
</div>
</div>
</div>
<div class="card rounded border-0 mb-4">
<div class="card-header"><span>{{ 'admin.setting.shop.shop.ga'|trans }}</span></div>
<div id="ex-shop-point" class="card-body">
okazy marked this conversation as resolved.
Show resolved Hide resolved
<div class="row mb-3">
<div class="col-3">
<div class="d-inline-block" data-tooltip="true" data-placement="top" title="{{ 'tooltip.setting.shop.shop.ga.tracking_id'|trans }}">
<span>{{ 'admin.setting.shop.shop.ga.tracking_id'|trans }}</span>
<i class="fa fa-question-circle fa-lg ml-1"></i>
</div>
</div>
<div class="col mb-2">
{{ form_widget(form.ga_id, { attr : { placeholder : 'admin.common.ga.tracking_id' }} ) }}
{{ form_errors(form.ga_id) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand All @@ -352,4 +369,4 @@ file that was distributed with this source code.
</div>
</div>
</form>
{% endblock %}
{% endblock %}
13 changes: 13 additions & 0 deletions src/Eccube/Resource/template/default/default_frame.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ file that was distributed with this source code.
});
});
</script>

{% if BaseInfo.ga_id is not empty %}
chihiro-adachi marked this conversation as resolved.
Show resolved Hide resolved
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ BaseInfo.ga_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '{{ BaseInfo.ga_id }}');
</script>
{% endif %}

{# Layout: HEAD #}
{% if Layout.Head %}
{{ include('block.twig', {'Blocks': Layout.Head}) }}
Expand Down
22 changes: 22 additions & 0 deletions tests/Eccube/Tests/Web/TopControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Eccube\Tests\Web;

use Eccube\Repository\BaseInfoRepository;

class TopControllerTest extends AbstractWebTestCase
{
public function testRoutingIndex()
Expand All @@ -27,4 +29,24 @@ public function testCheckFavicon()
$node = $crawler->filter('link[rel=icon]');
$this->assertEquals('/html/user_data/assets/img/common/favicon.ico', $node->attr('href'));
}

public function test_GAスクリプト表示確認()
{
// GAスクリプト表示がある時
$BaseInfo = $this->container->get(BaseInfoRepository::class)->get();
chihiro-adachi marked this conversation as resolved.
Show resolved Hide resolved
$BaseInfo->setGaId('UA-12345678-1');
$this->entityManager->flush();

$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filterXPath('//script[contains(@src, "googletagmanager")]');
$this->assertEquals('https://www.googletagmanager.com/gtag/js?id=UA-12345678-1', $node->attr('src'));

// GAスクリプト表示がない時
$BaseInfo->setGaId('');
$this->entityManager->flush();

$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filterXPath('//script[contains(@src, "googletagmanager")]');
$this->assertEmpty($node);
}
}