PageViewTracker Lightning Component
PageViewTracker Lightning Component
Coveo for Salesforce 3 (May 2018)
The PageViewTracker Lightning component allows you to insert a page view tracker component in your Experience Cloud site.
It takes care of wrapping and including the correct scripts and different resource references needed to do so.
Usage
Reference it in your Lightning component as you would for any other Aura component, using the namespace prefix of the Coveo package.
<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId,force:hasSObjectName"
access="global">
<CoveoV2:PageViewTracker />
</aura:component>
The PageViewTracker
Lightning component will use the clickableUri
instead of the recordId
when recordId
is unavailable.
Resources Included With This Component
This component includes the Coveo JavaScript Search Framework, the jQuery (latest 3.x.x version) library, and the Coveo for Salesforce specific assets.
Since Lightning Locker is automatically enabled on this component, the underscore result templates aren’t supported. You must use HTML templates instead.
Aura Method
sendPageView
When the manual
option is set to true
, use this function to manually send view events.
Required parameters:
-
contentIdKey
: A Coveo field name used to recommend results. -
contentIdValue
: The value of the selectedcontentIdKey
field.
<!-- myPageViewTrackerWrapper.cmp -->
<aura:component implements="forceCommunity:availableForAllPageTypes">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<CoveoV2:PageViewTracker aura:id="myPageViewTracker" manual="true" debug="true"/>
</aura:component>
// myPageViewTrackerWrapperController.js
{
doInit : function(component, event, helper) {
var myTracker = component.find('myPageViewTracker');
myTracker.sendPageView({
contentIdKey :'@clickableuri',
contentIdValue: 'https://mycommunity.salesforce-communities.com/mycommunity/s/?app=commeditor&view=editor&viewid=3bc9966a-db89-4aaf-9907-948a57084281&formFactor=LARGE&livePreviewBrandingSetID=f29190fc-cd8b-43c7-b2a6-bdfbba1fd3ef',
contentType: 'communityPageView',
customData: {age: 29}
});
}
}
You can safely call the sendPageView
method even when the PageViewTracker
component hasn’t yet initialized; the events are added to a queue and are sent once everything is ready.
Aura Event
This component offers the following Aura event:
GetSearchToken
Fired when the search token has been fetched (see Generating a custom search token for Lightning components).
Options
The component offers the following options:
contentIdKey
The Coveo field name used to recommend results. Ensure this field exists with the index you’re using.
Default value is @sfid
.
contentIdValue
The value for the contentIdKey
. This value should be a uniquely identifiable so Coveo Machine Learning can learn from the data.
Default value is the record id of the currently viewed page.
The component determines the value to enter for contentIdKey
this way:
- If the value is added in this option or through custom code, it’s assigned as its
contentIdValue
. - Otherwise, if in the URL of the page there’s a Salesforce Id, it’s assigned as its
contentIdValue
. - Otherwise, the URL of the page is assigned as its
contentIdValue
.
contentType
The Salesforce type of the currently viewed page.
By default, this value is dynamically calculated, meaning that, when viewing an Account item, the contentType
value would be Account
.
Entering a value for this option overrides this logic, and always sends the same static contentType
no matter which item type is being viewed.
customData
Custom data to be sent with the view event.
It should take the form of a JSON with the following syntax:
{"key":"value"}
debug
Whether the component should use the non-minified versions of the different resources.
Default value is false
.
manual
Whether to manually send events, instead of letting the component do it automatically.
When enabling this option, you have to manually send the usage analytics events to Coveo, using the sendPageView
function.
Default value is false
.
name
The name of the Advanced Lightning configuration to use for this component.
You usually want this value to be the same as your Coveo search component.
Default value is communityCoveo
.