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 14 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
33 changes: 33 additions & 0 deletions app/DoctrineMigrations/Version20210216120000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210216120000 extends AbstractMigration
{
public function up(Schema $schema): void
{
// データ存在チェック
$count = $this->connection->fetchColumn("SELECT COUNT(*) FROM dtb_block WHERE block_name = 'Googleアナリティクス'");
if ($count > 0) {
return;
}

// idを取得する
$id = $this->connection->fetchColumn('SELECT MAX(id) FROM dtb_block');
$id++;

$this->addSql("INSERT INTO dtb_block (id, block_name, file_name, use_controller, deletable, create_date, update_date, device_type_id, discriminator_type) VALUES ($id, 'Googleアナリティクス', 'google_analytics', false, false, '2021-02-16 12:00:00', '2021-02-16 12:00:00', 10, 'block')");
$this->addSql("INSERT INTO dtb_block_position (section, block_id, layout_id, block_row, discriminator_type) VALUES (1, $id, 1, 0, 'blockposition')");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
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 $gaId;

/**
* 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->gaId = $gaId;

return $this;
}

/**
* Get gaId.
*
* @return string|null
*/
public function getGaId()
{
return $this->gaId;
}
}
}
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
1 change: 1 addition & 0 deletions src/Eccube/Resource/doctrine/import_csv/en/dtb_block.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ id,device_type_id,block_name,file_name,create_date,update_date,use_controller,de
12,10,News,news,2017-03-07 10:14:52,2017-03-07 10:14:52,0,0,block
13,10,Product Search,search_product,2017-03-07 10:14:52,2017-03-07 10:14:52,1,0,block
14,10,Featured,topic,2017-03-07 10:14:52,2017-03-07 10:14:52,0,0,block
16,10,Google Analytics,google_analytics,2021-02-16 12:00:00,2021-02-16 12:00:00,0,0,block
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
"11","13","2","1","blockposition"
"11","4","2","2","blockposition"
"11","9","2","3","blockposition"
"1","16","1","0","blockposition"
1 change: 1 addition & 0 deletions src/Eccube/Resource/doctrine/import_csv/ja/dtb_block.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"12","10","新着情報","news","2017-03-07 10:14:52","2017-03-07 10:14:52","0","0","block"
"13","10","商品検索","search_product","2017-03-07 10:14:52","2017-03-07 10:14:52","1","0","block"
"14","10","トピック","topic","2017-03-07 10:14:52","2017-03-07 10:14:52","0","0","block"
"16","10","Googleアナリティクス","google_analytics","2021-02-16 12:00:00","2021-02-16 12:00:00","0","0","block"
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
"11","13","2","1","blockposition"
"11","4","2","2","blockposition"
"11","9","2","3","blockposition"
"1","16","1","0","blockposition"
4 changes: 4 additions & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ admin.common.device_type: Type of Device
admin.common.authority: Role
admin.common.payment_method: Payment Method
admin.common.charge: Charge
admin.common.ga.tracking_id: 'UA-XXXXXXXX-1'
#------------------------------------------------------------------------------------
# Home
#------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1115,6 +1116,8 @@ admin.setting.shop.shop.option_point: Point Settings
admin.setting.shop.shop.option_point_enabled: Points
admin.setting.shop.shop.option_point_rate: Point Return Rate
admin.setting.shop.shop.option_point_conversion_rate: Point Conversion Rate
admin.setting.shop.shop.ga: 'Google Analytics'
admin.setting.shop.shop.ga.tracking_id: 'Tracking ID'

#------------------------------------------------------------------------------------
# Settings : Store Settings : Payment Methods
Expand Down Expand Up @@ -1597,6 +1600,7 @@ tooltip.setting.shop.shop.option_product_tax: If turned on, you can set the tax
tooltip.setting.shop.shop.option_point_enabled: If turned on, the point system is enabled.
tooltip.setting.shop.shop.option_point_rate: You can change the point return rate by purchase amount.
tooltip.setting.shop.shop.option_point_conversion_rate: Conversion rate per 1 point. E.g. If you set ''1'', the point becomes available to shoppers with the rate of 1 point = 1 yen.
tooltip.setting.shop.shop.ga.tracking_id: 'Set tracking id when you analyze your site access using Google Analytics.'
tooltip.setting.shop.payment.logo_image: You can upload the payment option icons displayed in the payment methods during the checkout process. If not registered, the payment methods will be displayed w/o images.
tooltip.setting.shop.delivery.tracking_number_url: Enter the URL of the shipping tracker of the delivery company.
tooltip.setting.shop.delivery.sale_type: Specify the sales type(s) available for this delivery method.
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-ga" class="card-body">
<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 %}
21 changes: 21 additions & 0 deletions src/Eccube/Resource/template/default/Block/google_analytics.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
{% if BaseInfo.ga_id is not empty %}
<!-- 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 %}
24 changes: 24 additions & 0 deletions tests/Eccube/Tests/Web/TopControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

namespace Eccube\Tests\Web;

use Eccube\Entity\BaseInfo;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\Master\OrderStatusRepository;

class TopControllerTest extends AbstractWebTestCase
{
public function testRoutingIndex()
Expand All @@ -27,4 +31,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->entityManager->getRepository(BaseInfo::class)->get();
$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);
}
}