@@ -3,6 +3,7 @@ import React from "react";
33import { useDispatch } from "react-redux" ;
44import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
55import { Link } from "react-router-dom" ;
6+ import { usePostHog } from "@posthog/react" ;
67
78// Geonorge WebComponents
89// eslint-disable-next-line no-unused-vars
@@ -23,6 +24,7 @@ import style from "@/components/partials/SearchResults.module.scss";
2324export const SearchResults = ( { searchData, searchResultsType, viewMode } ) => {
2425
2526 const dispatch = useDispatch ( ) ;
27+ const posthog = usePostHog ( ) ;
2628
2729 const getShowMoreLink = ( ) => {
2830 const newOffset = searchData ?. offset + 25 ;
@@ -84,11 +86,27 @@ export const SearchResults = ({ searchData, searchResultsType, viewMode }) => {
8486 return localStorage . getItem ( "urlDownloadCsv" ) ;
8587 } ;
8688
89+ const handleShowMoreClick = ( ) => {
90+ posthog ?. capture ( "show_more_results_clicked" , {
91+ results_type : searchResultsType ,
92+ current_offset : searchData ?. offset ,
93+ search_string : searchData ?. searchString ,
94+ } ) ;
95+ } ;
96+
97+ const handleCsvDownloadClick = ( ) => {
98+ posthog ?. capture ( "search_results_csv_clicked" , {
99+ results_type : searchResultsType ,
100+ search_string : searchData ?. searchString ,
101+ csv_url : downloadAsCsvUrl ( ) ,
102+ } ) ;
103+ } ;
104+
87105 const renderShowMoreLink = ( ) => {
88106 return (
89107 < div className = { style . morecontainer } >
90108 < gn-button color = "default" >
91- < Link to = { { search : getShowMoreLink ( ) } } replace className = { style . morebtn } >
109+ < Link to = { { search : getShowMoreLink ( ) } } replace className = { style . morebtn } onClick = { handleShowMoreClick } >
92110 < span > { dispatch ( getResource ( "ShowMoreResults" , "Vis flere" ) ) } </ span >
93111 < FontAwesomeIcon icon = { "angle-down" } key = "icon" />
94112 </ Link >
@@ -109,7 +127,7 @@ export const SearchResults = ({ searchData, searchResultsType, viewMode }) => {
109127 < div className = { style . searchResultContainer } >
110128 { renderMetadataSearchResults ( ) }
111129 < div className = { style . downloadcsv } >
112- < a href = { downloadAsCsvUrl ( ) } >
130+ < a href = { downloadAsCsvUrl ( ) } onClick = { handleCsvDownloadClick } >
113131 { dispatch ( getResource ( "SaveResultsAsCSV" , "Lagre listen som CSV" ) ) }
114132 </ a >
115133 </ div >
0 commit comments