この記事では、URLの特定の位置にある文字列を取り出して、GA4のイベントのパラメータとして取得する方法を説明します。
今回の与件は、URLの例として、
https://ga4-quick.and-aaa.com/gtm-test/venezia/20220826/
というURL中の文字列(今回の場合は「/gtm-test/文字列/20220826/」)を取得して、イベントパメータに入れる方法を解説します。
変数の設定
「カスタム JavaScript」で変数を設定します。
コードは下記のようになります。
function () {
return window.location.pathname.split('gtm-test/')[1].split('/')[0];
}
「window.location.pathname」で URL のパスを取得します。パスとはドメイン以下、今回の場合は「/gtm-test/文字列/20220826/」です。
今回はパスの取得なので「.location.pathname」を使用しましたが、たとえば URL 全体を取得したい場合は「location.href」、パラメータ部分(?以降)を取得したい場合には「location.search」を使用します。
次に「/gtm-test/文字列/20220826/」の「文字列」部分のみを残すためにデータの加工を行います。「.split」で文字列を任意の場所で切り、その前([0])か後ろ([1])かを残すことができます。
今回の場合は「/gtm-test/」と「文字列」の後の「/」を除きたいので、.split(‘gtm-test/’)[1].split(‘/’)[0]と設定しました。
上記のスクリプトの場合はURLに’gtm-test’という文字列が入っていないと利用できない形です。こちらで汎用性が大きくなるようなスクリプト(カスタムJavascript変数)も紹介させていただきます。
function () {
/*
* ページパスは基本的に'/'で区切られるので
* window.location.pathnameでページパスを取得し
* さらにそれを".split('/')"することで
* 本例の場合以下のような配列の形になる
* [ '', 'gtm-test', 'venezia', '20220826', '' ]
*/
var texts = window.location.pathname.split('/');
/*
* 今回欲しい値は上のtextsの3番目(index相当で2)のため
* "[2]"で配列の3番目を取得し、それを返す
* この"2"を変更すること他のURLパターンの場合でも対応可能
*/
return texts[2];
}
次に、URLから取得した文字列をGA4に送信するイベントタグを設定します。
タグとトリガーの設定
イベントパラメータで、先程設定した変数「get_from_url2」の値を取得できるようにします。
このイベントのトリガーは、下記のように設定しておきます。
これで、URLから取得した文字列をGA4に送信するイベントタグの設定ができました。
ここまで出来たら、タグを「公開」してください。
文字列取得の確認
DebugViewにて、文字列の取得が確認できたら成功です。
Im grateful for the article post.Really thank you!
Enjoyed every bit of your article post. Cool.
A round of applause for your article.Much thanks again. Cool.
Thanks for sharing, this is a fantastic article.Much thanks again. Really Great.
A round of applause for your article post.Really looking forward to read more. Want more.
Im thankful for the blog post. Really Cool.
I value the article post.Really looking forward to read more.
I appreciate you sharing this blog article.Really looking forward to read more. Great.
Thanks so much for the article post. Want more.
Thank you ever so for you article post. Fantastic.
I really like and appreciate your article post.Really thank you! Great.
I loved your article post.Really thank you! Really Cool.
I really liked your post.Much thanks again. Much obliged.
I really enjoy the blog article.Really thank you! Cool.
writing an essay onlinecollege essay writingwriting essays online
An interesting discussion is worth comment. I think that you ought to write more about this subject matter, it might not be a taboo matter but usually folks don’t talk about such topics. To the next! All the best!!
Just bookmarked this post as I have found it quite helpful.
Enjoyed every bit of your article post.Really looking forward to read more. Want more.
Thanks for sharing, this is a fantastic blog post.Really thank you! Will read on…
Thanks so much and I am looking ahead to touch you.judi online indonesia
Remarkable! Its really amazing piece of writing, I have got much clear idea regarding from this piece of writing.
Maxims and aphorisms let us remember that wisdom is the true salt of literature and the books that are most nourishing are richly stored with it and that is the main object to seek in reading books.
I live in London ivermectin manfaat Whomever the Nets pick as captain for this squad â and they have an incumbent in Williams and the longtime Celtics captain in Paul Pierce â itâs really just a figurehead position unless it goes to Garnett.
Hey just wanted to give you a quick heads up and let you know a few of the images aren’tloading correctly. I’m not sure why but I think its a linkingissue. I’ve tried it in two different internet browsers and bothshow the same outcome.
Thanks-a-mundo for the blog post.Thanks Again. Will read on…
Im thankful for the blog post.Thanks Again. Want more.
Good blog you have here.. Itís difficult to find quality writing like yours these days. I truly appreciate people like you! Take care!!
Thanks a lot for the article.Thanks Again.
1st and main attraction is made for certain the material employed.
Hi! Do you know if they make any plugins to protect against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?
693726 596299Woh Everybody loves you , bookmarked ! My partner and i take problem in your last point. 658795
stromectol tab – ivermectin pills ivermectin for covid 19
Thanks-a-mundo for the post.Really thank you!
to a single Sony PSN Card… about this since the very
Great, thanks for sharing this blog.Really looking forward to read more. Fantastic.
I loved your blog.Really thank you! Cool.
Hey! I just wanted to ask if you ever have any trouble with hackers?My last blog (wordpress) was hacked and I ended up losing afew months of hard work due to no back up.Do you have any methods to stop hackers?
RoyalCBD says:You should take part in a contest for one of the finest blogs on the internet. I’m going to recommend this blog!Reply 08/13/2020 at 3:56 am
effects of plaquenil canada pharmacy online does plaquenil make you gain weight how long do the side effects of plaquenil last
Muchos Gracias for your article.Much thanks again. Really Cool.
treatments for ed: ed medication – top rated ed pills
Always love reading your blogs whenever I get some time because the way you describe information in your blogs, it helps me a lot in improving my writing skills as well. AC Repair Weston
An interesting discussion is definitely worth comment. I believe that you need to publish more on this subject, it may not be a taboo subject but typically folks don’t speak about such subjects. To the next! All the best.
The the very next time I read a blog, Hopefully which it doesnt disappoint me around brussels. What i’m saying is, It was my choice to read, but I just thought youd have some thing interesting to convey. All I hear can be a couple of whining about something you could fix in the event you werent too busy in search of attention.
It’s very trouble-free to find out any matter on net as compared to books, as I found this piece of writing at this web site.
Heya i am for the first time here. I came across this
board and I find It truly useful & it helped me out a lot.
I hope to give something back and aid others like
you helped me.
Say, you got a nice article.Thanks Again. Want more.
A big thank you for your article post.Thanks Again. Want more.
Wow, this post is pleasant, my sister is analyzing these things,
therefore I am going to tell her.
Hey! This is kind of off topic but I need some advice from an established
blog. Is it hard to set up your own blog?
I’m not very techincal but I can figure things out pretty quick.
I’m thinking about creating my own but I’m not sure where to begin. Do you
have any tips or suggestions? Cheers
This design is incredible! You definitely know how to keep a reader amused.
Between your wit and your videos, I was almost moved to start my own blog (well,
almost…HaHa!) Great job. I really enjoyed what
you had to say, and more than that, how you presented it.
Too cool!
Great blog. Great.
Sicherer Online-Kauf von Medikamenten galena Oldenzaal Les risques associés
à l’achat de médicaments en ligne
Very nice article. I definitely love this website.
Keep it up!
You have a gift for explaining things. What Is Cryptocurrency
My spouse and I stumbled over here coming from a
different web address and thought I may as well check things out.
I like what I see so now i am following you. Look forward to finding out about your web page repeatedly.
hello!,I really like your writing very much!
percentage we be in contact extra approximately your article
on AOL? I need a specialist on this space to solve my problem.
May be that is you! Taking a look ahead to see
you.
medicamentos sin prescripción médica en Chile zydus Cartagena Apotheke in Spanien für Medikamente
I’m gone to tell my little brother, that he should also pay a quick visit this
webpage on regular basis to obtain updated from newest news update.
Preis von Medikamente auf Rezept Heumann Durbuy Sicherer
Kauf von Medikamente
Replica Sneakers eu952
Replica Sneakers for women,
fake jordans xc092
баян аймагамбетова биография, аймагамбетов канат рахимович рация мчс
слушать, кто работает на частоте
400-470 мгц анна данченко биография год рождения, анна данченко телеведущая биография бұл өмірде аккорды укулеле, бір досым
бар аккорды
аққан жұлдыз басты кейіпкер, аққан жұлдыз 2 кітап
мерседес кабан колеса, мерседес кабан 600 цена ұлдардың туған күніне
не сыйлауға болады, ұлдарға жаңа жылға не сыйлауға болады онлайн подработка казахстан, удаленная работа в казахстане отзывы
какие молитвы читают по усопшему до 9 дней сонник
к чему снится муравьи 23 сентября 1995 знак зодиака, таблица знаков зодиака
курсы нумерологии с сертификатом онлайн приснилась лягушка прыгает на меня большая
achat de médicaments en ligne sans ordonnance Almus Zollikon dove trovare i farmaci in Svizzera
работа подработка одинцовский район набережные челны дом
мебели часы работы ночная подработка
в минске с ежедневной платформа для заработка в интернете реальные отзывы