
先日紹介した「Parent Element Variable」変数テンプレートと同時に、Googleタグマネージャのコミュニティテンプレートギャラリーへ2019年10月24日に追加された「Trim Query」変数テンプレートがあります。
こちらもアユダンテ製の変数テンプレートで、リンククリック計測を行うイベント計測でClick URL変数を使った際に入り込んでくることがある_gaクエリなどを除去したりできるようになります。
In addition to the “Parent Element Variable” variable template introduced the other day, a “Trim Query” variable template was added to the Google Tag Manager community template gallery on October 24, 2019.
This is a variable template created by Ayudante that can remove _ga queries, etc. that can occur when using click URL variables in event measurements that perform link click measurements.
今回はこちらのTrim Query変数テンプレートについて、使い方などをまとめさせていただきました。
グローバルに世界中からアクセスされる可能性があるため、本記事についても日本語と英語を併記させていただいております。読み辛いかもしれませんが、ご了承ください。
This time, we summarized how to use this “Trim Query” variable template.
This article is written in both Japanese and English because it may be accessible from around the world.

Trim Query変数テンプレートとは:What is “Trim Query”
URLを値に持つ変数(Click URLやPage URLなど)から、指定した名前のクエリを削除した文字列を返す変数テンプレートです。
例えば「『Click URL』変数を対象に『_ga』クエリを除去する」ように使えば、クロスドメイントラッキングの対象となるリンクがクリックされた際も「_gaクエリが抜かれたURL全文」を取得することができます。(リンククリック計測をしようとした際、稀によく起こりますよね、_gaクエリの乱入)
This is a variable template that returns a string obtained by deleting a query with a specified name from a variable that has a URL value (“Click URL”, “Page URL”, etc.).
For example, if you use “Delete” _ga “Query” for the “Click URL” variable, clicking the cross-domain tracking link will show “Complete URL with _ga query deleted”. (In rare cases, a _ga query breaks in when trying to measure link clicks)

現在はコミュニティテンプレートギャラリーへ掲載されていますので、GTM内からどなたでも簡単に最新版をインポートしてご利用いただけます。
Already posted to the community template gallery, anyone can use it freely.
- 主な使い道:Typical usage
- GAでリンククリックをイベント計測する際、リンクURL(Click URL変数)に入ってくる_gaクエリなどを除去させる
When measuring link click event with Google Analytics, delete _ga query etc. included in link URL (“Click URL” variable)
- GAでリンククリックをイベント計測する際、リンクURL(Click URL変数)に入ってくる_gaクエリなどを除去させる
もともとは以前のカスタムテンプレートの紹介記事でサンプルとして掲載した「指定の変数から任意のクエリを除去するテンプレート」をベースに、コードやUIの見直しなどを行ったものとなります。
A function was added by brushing up based on a template that a template that removes a query from a specific variable as an example in an introduction article of a previous custom template.
インポート方法:Import method
コミュニティテンプレートギャラリーへ掲載されていますので、インポートはとても簡単です。
GTMの管理画面内から、常に最新のテンプレートをインポートできます。
Importing is very easy because it is posted in the community template gallery.
You can always import the latest template from the GTM management screen.
- Trim Queryを使用したいGTMコンテナを開く
Open the GTM container that uses the Trim Query. - 左メニューの「テンプレート」からテンプレートの一覧画面を開く
Open the template list screen from “Templates” in the left menu. - 「変数テンプレート」ブロックの右上にある「検索ギャラリー」ボタンをクリック
Click the “Search Gallery” button in the upper right corner of the Variable Template block. - 「Trim Query」を探し出してクリック
Find and click “Trim Query”. - テンプレートの詳細が表示されるので、右上の「ワークスペースに追加」ボタンをクリック
The details of the template will be displayed, so click the “Add to workspace” button on the top right - 確認アラートが出るので、右下の「追加」ボタンをクリック
A confirmation alert will be displayed. Click the “Add” button at the bottom right. - 完了(バージョン作成すれば他ワークスペースでも利用可能に)
Done (Create a version and use it in other workspaces)
使い方:How to use
インポート完了後、変数のタイプ選択リストの上のほうへ「Trim Query」が追加されますので、そこから選択することで変数として登録ができるようになります。
When the import is complete, a “Trim Query” is added to the top of the variable type selection list, so you can select it and register it as a variable.
使い方は単純で、
It’s easy to use,
- 「Target URL」でクエリを除去したいURL変数を選択
Select the URL variable to delete the query in “Target URL”. - 「Remove from what」でクエリとフラグメント(ハッシュタグ)のどちらから削除するかを選択
Select “Remove from what” to delete from the query or fragment (hashtag). - 「Delete query key」で削除したいクエリ名を入力
Enter the name of the query to be deleted in “Delete query key”.
という流れで設定できます。
You can set in the flow.

- Target URL
- URLを値として持つ変数を指定します。
Specify a variable whose value is a URL. - デフォルトでは「Element URL」(=Click URLやForm URL)が選択されているので、リンクURLなどからクエリを除去したい、という場合はデフォルトのままでOKです。
またページURLからクエリを除去したい、という場合は「Page URL」または「Page URL All」を選択します。「Page URL」は同名の「Page URL」変数と同じで、プロトコルからクエリまでを含むURL全文ですが、フラグメント(ハッシュタグ)は含まれません。フラグメント(ハッシュタグ)も含みたい場合は「Page URL All」を選択してください。
By default, “Element URL” (= Click URL or Form URL) is selected, so if you want to delete a query from a link URL etc., you can keep the default.
Select “Page URL” or “Page URL All” to delete the query from the page URL. “Page URL” is the same as the “Page URL” variable of the same name, and is a complete URL that includes everything from the protocol to the query, but does not include fragments (hashtags). If you want to include fragments (hashtags), select “Page URL All”. - その他、登録されている他の変数も選択可能です。
ただし、値としてURL形式になっている変数を選択してご利用ください。
具体的にはクエリを除去したいのであれば「?」を、フラグメント(ハッシュタグ)を除去したいのであれば「#」を含む文字列となっている必要があります。
You can select other registered variables.
However, select a variable in URL format as the value. Specifically, to delete a query, it must be a string that contains “?”. In addition, when deleting a fragment (hash tag), it must be a character string containing “#”.
- Remove from what
- 除去対象を選択します。
Select the removal target. - デフォルトではQueries(クエリ)が選択されていますが、フラグメント(ハッシュタグ)も選択可能です。
また、両方を選択、も可能です。
By default, the query is selected, but you can also select a fragment (hashtag). You can select both. - Delete query key
- 除去したいクエリ名を入力します。
Enter the name of the query that you want to delete. - 「行を追加」ボタンから行を追加すると入力欄が出ますので、そちらへ1クエリ名ずつ入力してください。
判定は完全一致で行われます。(「含む」ではありません)
また、同じ名前のクエリが複数ある場合も、すべての対象クエリが除去されます。
When you add a row from the “Add Row” button, an input field appears. Enter one query name at a time.
Judgments are made in perfect agreement. If there are multiple queries with the same name, all target queries are deleted.
設定後は普通の変数と同様に、プレビューなどで期待したものになっているかを確認してください。
After setting, confirm that it is what you expected in the preview like a normal variable.

いかがでしたでしょうか。
たまにピンポイントでほしくなる、そんなテンプレートになっているかと思います。
I think that is a template that sometimes makes me want.
今回・前回と弊社製のコミュニティテンプレートを紹介しましたが、他にもたくさんのテンプレートがギャラリーへは日々追加されていっています。
もし「こんなことができたらいいのにな」と思ったら、ギャラリーから使えそうなものがないか探してみても良いかもしれません。
We introduced the community templates we created, but many other templates are added to the gallery every day.
If you wish, we encourage you to search for what you can use from the gallery.