- Posts: 140
COMMUNITY FORUM
Add gtag search event to module search
- Uzi
- Topic Author
- Offline
- Premium Member
Less
More
1 year 1 week ago #181358
by Uzi
Add gtag search event to module search was created by Uzi
Hello,
I'd like to add the following code:
Where can i do this?I want to add this to the search module so i can track what people search or try to search in my k2 component.
I'd like to add the following code:
gtag("event", "search", { search_term: "t-shirts" });
Where can i do this?I want to add this to the search module so i can track what people search or try to search in my k2 component.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6220
1 year 5 days ago #181361
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Add gtag search event to module search
You would add this in a script tag (along with the rest of your GA snippet) inside your index.php file targetted to ONLY load on the "search" task for the itemlist view in K2 as well as the com_search component.
Something like this...
Something like this...
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
<?php
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$task = JRequest::getCmd('task');
if (
($option == 'com_k2' && $view == 'itemlist' && $task == 'search') ||
$option == 'com_search' ||
$option == 'com_finder'
):
?>
gtag("event", "search", { search_term: "t-shirts" });
<?php endif; ?>
gtag('config', 'YOUR_ID_HERE');
</script>
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Uzi
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 140
1 year 5 days ago #181363
by Uzi
Replied by Uzi on topic Add gtag search event to module search
Hi, thanks for your reply. I already have my gtag config set up. so i can freely add these tags in my files. But I need to add the search term dynamucally. so i need to have the file from k2 where the ajax search functionalit yis defined so i can add this to the file.. I can also add my own script to check for the specific text input.. maybe that is better.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6220
1 year 5 days ago #181365
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Add gtag search event to module search
It's not hard to grab the GET param for simple search result pages. However getting the value of a "live" search doesn't really make sense as the user is constantly typing. Even if you add a delay to grab whatever the finished search string is, the user may click on one of the suggested links and just visit another page. And don't forget that events to GA need to be sent async. So I doubt there's the needed time for all that in the case of live search.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.