※社内専用

サンクスページへのCVタグ設置【WPなしシード・リミテッド】

  • HOME
  • トピックス
  • サンクスページへのCVタグ設置【WPなしシード・リミテッド】
下記ファイル構造のとき
(古い案件多少違うこともあるためそのときはまた要確認 とりあえず今回のもの。やらなければならないことは同じ)

/contact/view/template.html
/contact/confirm.php (確認画面)
/contact/index.php
/contact/submit.php (送信後画面:お礼ページ)


スクラッチのシード・リミテッドは
入力ページ、確認画面、お礼ページのヘッダー・フッターが共通ファイル
今回のようにお礼ページのヘッダーにのみタグを追記したい場合は、ページによって、出力する内容が変わるように調整する必要がある。

/contact/view/template.html

タグを設置したい箇所に{$tag}を追記

  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <link rel="canonical" href="https://www.hidamari-hoikuen.info/contact/">
  <title></title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://fonts.googleapis.com/css?family=Noto+Sans+JP:400,700&amp;subset=japanese" rel="stylesheet" />
  <link href="../assets/css/main.css" rel="stylesheet">
  <link href="../assets/css/animate.min.css" rel="stylesheet">
  <link href="//cdn.jsdelivr.net/npm/flatpickr@2.6.3/dist/flatpickr.min.css" rel="stylesheet">

  {$tag}

  <script src="../assets/js/vendor/respond.min.js"></script>
</head>

/contact/confirm.php
/contact/index.php

最後の echo $html; の前に追記する

追記する内容

  $tag = "";
  $html = str_replace('{$tag}', $tag, $html);
完成形

  <?php
  
  require_once 'src/config.php';
  session_start();
  
  require_once PATH_SRC . DS . 'confirm_controller.php';
  
  if (isset($sys_mode) && $sys_mode == 'error') {
    require_once PATH_SRC . DS . 'index_controller.php';
    $view_file = PATH_VIEW . DS . 'form.php';
  } else {
    $view_file = PATH_VIEW . DS . 'confirm.php';
  }
  
  $template_file = PATH_VIEW . DS . 'template.html';
  if (!file_exists($view_file) || !file_exists($template_file)) {
    exit(1);
  }
  ob_start();
  include $view_file;
  $view_html = ob_get_contents();
  ob_end_clean();
  $template_html = file_get_contents($template_file);
  $template_html = file_get_contents($template_file);
  $html = str_replace('{$form}', $view_html, $template_html);
  $tag = "";
  $html = str_replace('{$tag}', $tag, $html);
  echo $html;
  exit;

/contact/submit.php

/contact/confirm.php
/contact/index.php
と同じ箇所に追記

追記する内容

  $tag = "ここから設置するタグ
  <!-- Global site tag (gtag.js) - Google Ads: 758819566 -->
  
  
  <!-- Event snippet for お問い合わせ conversion page -->
  
  ここまで";
  $html = str_replace('{$tag}', $tag, $html);
完成形

  <?php
  
  require_once 'src/config.php';
  session_start();
  
  require_once PATH_SRC . DS . 'submit_controller.php';
  
  $view_file = PATH_VIEW . DS . 'submit.php';
  $template_file = PATH_VIEW . DS . 'template.html';
  if (!file_exists($view_file) || !file_exists($template_file)) {
    exit(1);
  }
  ob_start();
  include $view_file;
  $view_html = ob_get_contents();
  ob_end_clean();
  $template_html = file_get_contents($template_file);
  $template_html = file_get_contents($template_file);
  $html = str_replace('{$form}', $view_html, $template_html);
  $tag = "ここから設置するタグ
  <!-- Global site tag (gtag.js) - Google Ads: 758819566 -->
  
  
  <!-- Event snippet for お問い合わせ conversion page -->
  
  ここまで";
  $html = str_replace('{$tag}', $tag, $html);
  echo $html;
  exit;
参考:https://blog-and-destroy.com/1954
設置済みサイト(更新の可能有):https://www.hidamari-hoikuen.info/contact/