Analytics Interaction Gtag
forceCommunity:analyticsInteractionGtag
Tracks events that are triggered by custom components in Aura-based Experience Builder sites and sends the data to Google Analytics.
For Use In
Experience Builder Sites
This example creates a custom button and includes the forceCommunity:analyticsInteractionGtag event in the button’s client-side controller. Clicking the button sends event data to Google Analytics.
1handleClick : function(cmp, event, helper) {
2 var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteractionGtag");
3 analyticsInteraction.setParams({
4 event : 'click',
5 event_category : 'Button',
6 event_label : 'Winter Campaign Button',
7 value: 200
8 });
9 analyticsInteraction.fire();
10 }This example sends a user timing event to Google Analytics indicating that it took 3549 milliseconds for the current web page to load all external JavaScript dependencies. (Credit to Google Analytics documentation.)
1handleClick : function(cmp, event, helper) {
2 if (window.performance) {
3 // Gets the number of milliseconds since page load
4 // (and rounds the result since the value must be an integer).
5 var timeSincePageLoad = Math.round(performance.now());
6
7 var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteractionGtag");
8 analyticsInteraction.setParams({
9 event : 'timing_complete',
10 name : 'load',
11 value : 3549,
12 event_category: 'JS Dependencies',
13 event_label: 'Google CDN'
14 });
15 analyticsInteraction.fire();
16 }
17 }This example sends an exception event to Google Analytics if the divisor y is zero. (Credit to Google Analytics documentation.)
1handleClick : function(cmp, event, helper) {
2 var x = component.get("v.x");
3 var y = component.get("v.y");
4
5 try {
6 var r = divide(x, y);
7 } catch(err) {
8 var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteractionGtag");
9 analyticsInteraction.setParams({
10 event : 'exception',
11 description : err,
12 fatal : false
13 });
14 analyticsInteraction.fire();
15 }
16 }This event is supported in Aura-based Experience Builder sites only. To enable event tracking, add your Google Analytics tracking ID in Settings | Advanced in Experience Builder and publish the site.
Attributes
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
description | A description of the error. | string | ||
event | The string that will appear as the event action in Google Analytics Event reports. | string | ![]() | |
event_category | An event category is a name that you supply as a way to group objects that you want to analyze. Also, a string for categorizing all user timing variables into logical groups. | string | ||
event_label | Provides additional information for events that you want to analyze. Also, a string that can be used to add flexibility in visualizing user timings in the reports. | string | ||
fatal | True if the error was fatal. | boolean | ||
name | A string to identify the variable being recorded. Required for ‘timing_complete’ event. | string | ||
value | An integer used to assign a numerical value to a page object. Also, he number of milliseconds in elapsed time to report to Google Analytics. Required for ‘timing_complete’ event. | integer |
