A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.reactivesearch.io/docs/reactivesearch/vue/advanced/analytics/ below:

Reactivesearch.io Docs - Search stack for Elasticsearch, OpenSearch, Solr, MongoDB

You can take advantage of search and click analytics when using Appbase.io as a backend with ReactiveSearch. Search analytics work out of the box with analytics prop in ReactiveBase. This recipe explains how to implement click analytics for your app.

Click Analytics

Click analytics have to be wired into the result components. Its supported in ReactiveList.When using ReactiveList, the renderItem or render slot receives an extra property to make click analytics work which you have to invoke with onClick. This method also supports the document id(optional) as the second param. If document id is not set then ReactiveSearch will calculate it based on the click position.

<reactive-list>
    <template #renderItem="{ item,  triggerClickAnalytics}">
        <div @click="triggerClickAnalytics">{{ item.title }}</div>
    </template>
</reactive-list>

When rendering your component using render you have to call the triggerClickAnalytics function by using the _click_id property of the result items as an argument. This method also supports the document id(optional) as the second param. If document id is not set then ReactiveSearch will calculate it based on the click position. Example:

<reactive-list>
    <template #render="{ data, triggerClickAnalytics }">
        <div
            v-for="(item, index) in data"
            @click="triggerClickAnalytics(item._click_id)"
        >
            {{ item.title }}
        </div>
    </template>
</reactive-list>
Track Impressions for Search Results

Impressions tracking is tied to the result components. You may have to do some extra setup in the ReactiveList component to track the impressions. Please follow the following instructions for different kind of use-cases.

  1. If you're using the render or renderItem slot for the results UI then you have to define the id property for each result element. The value of id property must be the _id value from the elasticsearch hit object.

For an example, the following example uses the renderItem slot

<reactive-list>
    <template #renderItem="{ item }">
        <div :id="hit._id" :key="hit._id">{{ item.title }}</div>
    </template>
</reactive-list>

Check this example with the render slot

<reactive-list>
    <template #render="{ data }">
        <div
            v-for="(hit, index) in data"
            :id="hit._id"
            :key="hit._id"
        >
            {{ hit.title }}
        </div>
    </template>
</reactive-list>
  1. If you're using render slot with ResultCard or ResultList components then you have to define the id prop for those components.

For an example,

<reactive-list componentId="SearchResult">
    <template #render="{ data }">
        <result-cards-wrapper>
            <result-card
                v-for="(hit, index) in data"
                :id="hit._id"
                :key="hit._id"
            >
                <result-card-title>{{ item.original_title }}</result-card-title>
                <result-card-description>by {{ item.authors }}</result-card-description>
            </result-card>
        </result-cards-wrapper>
    </template>
</reactive-list>
Configure with inject API

We can use the @appbaseio/analytics library without installing it or any configuration by using the inject API. When used, it returns an instance of the analytics library. It uses the url and credentials provided to the parent ReactiveBase component.

For example, if we want to track conversions when a user clicks on "Visit Store" button then we can make a button as shown in snippet below.

We make a new file VisitStoreButton.vue using the SFC format from Vue. The analytics instance is provided as $analytics prop. Note queryID is required property and we can populate it automatically by calling a method on the same instance.

<template>
	<button class="visit-store-btn" @click="handleVisitStore">Visit Store</button>
</template>
<script>
export default {
    name: 'VisitStoreButton',
    inject: {
		$analytics: {
			default: null
        }
	},
    methods: {
        handleVisitStore() {
            this.$analytics.conversion({
                queryID: this.$analytics.getQueryID(),
                objects: ['Harry Potter', 'Frankenstein'],
            })
		}
	}
}
</script>

You can also view the complete demo as a codesandbox example below.

Configure the analytics experience

You can define the reactivesearchAPIConfig prop in the ReactiveBase component to customize the analytics experience when appbase.io is used as a backend. It accepts an object which has the following properties:


For example in the following code, we're setting up two custom events that will be recorded with each search request.
<template>
	<reactive-base :reactivesearchAPIConfig="reactivesearchAPIConfig" />
</template>
<script>
	export default {
		name: 'app',
		methods: {
			computed: {
				reactivesearchAPIConfig() {
					return {
						customEvents: {
							platform: 'ios',
							device: 'iphoneX',
						},
					};
				},
			},
		},
	};
</script>

For example in the following code, we're setting the `preference` value to `local`.
<template>
	<reactive-base :reactivesearchAPIConfig="reactivesearchAPIConfig" />
</template>
<script>
	export default {
		name: 'app',
		methods: {
			computed: {
				reactivesearchAPIConfig() {
					return {
						queryParams: {
                            preference: "local",
                        }
					};
				},
			},
		},
	};
</script>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4