{"id":28829132,"url":"https://github.com/forcedotcom/sfdx-analytics","last_synced_at":"2025-08-16T01:29:00.247Z","repository":{"id":40422360,"uuid":"149190415","full_name":"forcedotcom/sfdx-analytics","owner":"forcedotcom","description":"Einstein Analytics sample application templates","archived":false,"fork":false,"pushed_at":"2024-01-26T20:48:04.000Z","size":1484,"stargazers_count":44,"open_issues_count":0,"forks_count":19,"subscribers_count":18,"default_branch":"main","last_synced_at":"2024-04-14T19:33:40.096Z","etag":null,"topics":["analytics-templates","salesforce","sfdx","tableau-crm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/forcedotcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-09-17T21:29:25.000Z","updated_at":"2024-04-02T09:33:30.000Z","dependencies_parsed_at":"2024-01-26T21:47:45.704Z","dependency_job_id":null,"html_url":"https://github.com/forcedotcom/sfdx-analytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/forcedotcom/sfdx-analytics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2Fsfdx-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2Fsfdx-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2Fsfdx-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2Fsfdx-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/forcedotcom","download_url":"https://codeload.github.com/forcedotcom/sfdx-analytics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forcedotcom%2Fsfdx-analytics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260690964,"owners_count":23047106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics-templates","salesforce","sfdx","tableau-crm"],"created_at":"2025-06-19T05:11:56.208Z","updated_at":"2025-07-04T13:36:49.988Z","avatar_url":"https://github.com/forcedotcom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CRM Analytics Template and Lightning Web Components Examples\n\n![recipes-logo](recipes-logo.png)\n\nA collection of CRM Analytics code examples for Lightning Web Components (LWC) and App Templates.\n\nFor LWC, each example demonstrates how to code third party Analytics visualizations into LWC. Current examples include a Gantt Chart, a graph, a hierarchy, a list, and an integration with the [Chart.js library](https://www.chartjs.org/). For additional infomation, see the [Lightning Web Components in CRM Analytics Dashboards (Beta)](https://developer.salesforce.com/docs/atlas.en-us.bi_dev_guide_lwc_in_db.meta/bi_dev_guide_lwc_in_db/bi_lwc_in_db_overview.htm) developer guide.\n\nFor App Templates, there is Quick Start project to get users using the power of SFDX to develop Analytics templates. For additional information on template creation and deep-dive details, see the [CRM Analytics Templates Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.bi_dev_guide_wave_templates.meta/bi_dev_guide_wave_templates/bi_templatesdev_intro_wave_templates.htm).\n\n\u003cdiv\u003e\n    \u003cimg src=\"https://res.cloudinary.com/hy4kyit2a/f_auto,fl_lossy,q_70,w_50/learn/projects/quick-start-lwc-recipes-app/bb501c3216ac163958f036fb90357955_badge.png\" align=\"left\" alt=\"Trailhead Badge\"/\u003e\n    Learn more about using generic LWC recipes by completing the \u003ca href=\"https://trailhead.salesforce.com/content/learn/projects/quick-start-lwc-recipes-app\"\u003eQuick Start: Explore the LWC Recipes Sample App\u003c/a\u003e Trailhead project.\n    \u003cbr/\u003e\n    \u003cbr/\u003e\n    \u003cbr/\u003e\n\u003c/div\u003e\n\n\u003e These samples are designed to run on Salesforce Platform.\n\n## Table of contents\n\n- [Installing the app using a Scratch Org](#installing-the-app-using-a-scratch-org): This is the recommended installation option. Use this option if you are a developer who wants to experience the app and the code.\n\n- [CRM Analytics LWC Metadata](#crm-analytics-lwc-metadata)\n\n- [CRM Analytics LWC Features](#crm-analytics-lwc-features)\n\n- [CRM Analytics App Templates](#crm-analytics-app-templates)\n\n## Installing the app using a Scratch Org\n\n1. Set up your environment. Follow the steps in the [Quick Start: Lightning Web Components](https://trailhead.salesforce.com/content/learn/projects/quick-start-lightning-web-components/) Trailhead project. The steps include:\n\n   - Enable Dev Hub in your Trailhead Playground\n   - Install Salesforce CLI\n   - Install the Analytics Plugin for the Salesforce CLI\n   - Install Visual Studio Code\n   - Install the Visual Studio Code Salesforce extensions, including the Lightning Web Components ansd Salesforce Analytics - App Templates extensions.\n\n1. If you haven't already done so, authorize your hub org and provide it with an alias (**myhuborg** in the command below):\n\n   ```\n   sfdx auth:web:login -d -a myhuborg\n   ```\n\n1. Clone the forcedotcom/sfdx-analytics repository:\n\n   ```\n   git clone https://github.com/forcedotcom/sfdx-analytics.git\n   cd sfdx-analytics\n   ```\n\n1. Install the Analytics SFDX plugin\n\n   ```\n   sfdx plugins:install @salesforce/analytics\n   ```\n\n1. Update the adminEmail in config/project-scratch-def.json to your email address.\n\n1. Create a scratch org, providing an org alias (sfdx-analytics in the command below):\n\n   ```\n   sfdx force:org:create -s -f config/project-scratch-def.json -a sfdx-analytics\n   ```\n\n1. Push the LWC and template sampleas to your scratch org:\n\n   ```\n   sfdx force:source:push\n   ```\n\n1. Open your scratch org.\n\n   ```\n   sfdx force:org:open -u myhuborg\n   ```\n\n## CRM Analytics LWC Metadata\n\nLightning Web Components used in CRM Analytics dashboards leverage the same file structure and [XML metadata format](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_configuration_tags) used by other LWCs on the Salesforce platform. Here are few additions to this metadata specific for CRM Analytics.\n\n**analytics\\_\\_Dashboard Target**\n\nAdding this target to the list of `\u003ctargets\u003e` for your component allows it to be used in CRM Analytics dashboards, provided that your component is public. You can also add a `\u003ctargetConfig\u003e` for the new target to further customize how your component appears in dashboards.\n\n**`\u003chasStep\u003e` Tag**\n\nIn an `analyticsDashboard` target config, you can choose to include a `\u003chasStep\u003etrue\u003c/hasStep\u003e` tag to indicate that your component requires an attached step to function as expected. With this tag, the dashboard builder UI prompts you to attach an existing step or create a new step when creating an instance of your component. Components with an attached step have access to step-specific properties like `results` and `selection`. For more information on these properties, see [CRM Analytics LWC Features](#crm-analytics-lwc-features).\n\n**Measure and Dimension Attribute Data Types**\n\nAttributes specified in a LWC's `analtyicsDashboard` target config are displayed in the CRM Analytics dashboard builder UI for configuration. In addition to the common data types, this target also supports `Measure` and `Dimension` data types for components with `\u003chasStep\u003etrue\u003c/hasStep\u003e`. Dashboard builders are able to choose a column of the given data type from the results of the attached step.\n\n## CRM Analytics LWC Features\n\n**Types**\n\nEach component configured for the `analytics__Dashboard` target has properties that are set by the dashboard runtime dynamically. Here are the properties by `type`:\n\n    type Row = {[string]: mixed, ...};\n    type Data = Array\u003cRow\u003e;\n    type Metadata = {|\n        groups: Array\u003cstring\u003e,\n        strings: Array\u003cstring\u003e,\n        numbers: Array\u003cstring\u003e\n    |};\n    type Selection = Data;\n    type SetSelection = (Selection) =\u003e void;\n    type SelectMode =\n        | 'none'\n        | 'single'\n        | 'multi'\n        | 'singlerequired'\n        | 'multirequired';\n\n    type State = {|\n        pageId: string,\n        state: DashboardStateJson\n    |};\n    type GetState = () =\u003e State,\n    type SetState = (State) =\u003e void;\n\nFor more information on `type` syntax, see [Type Annotations](https://flow.org/en/docs/types/).\n\n**Data**\n\nAvailable when a component has `\u003chasStep\u003etrue\u003c/hasStep\u003e`, `data` returns the query results of the step as an array of maps.\n\n    [\n        {columnOne: 'one', columnTwo: 123},\n        {columnOne: 'two', columnTwo: 456}\n    ]\n\n**Metadata**\n\nAvailable when a component has `\u003chasStep\u003etrue\u003c/hasStep\u003e`, `metadata` describes the shape of the step results.\n\n    {\n        strings: ['columnOne'],\n        numbers: ['columnTwo'],\n        groups: []\n    }\n\n**Selection**\n\nAvailable when a component has `\u003chasStep\u003etrue\u003c/hasStep\u003e`, `selection` is the current selection of the associated step as an Array of objects, with each object being one or more selected rows from the results.\n\n    return new Map((this.selection ?? []).map((row) =\u003e [this.hash(row), row]);\n\n**setSelelction**\n\nAvailable when a component has `\u003chasStep\u003etrue\u003c/hasStep\u003e`, `setSelection` is a callback passed in that allows the component to update the attached step's selection in CRM Analytics. In doing so, it potentially applies filters to the rest of the dashboard's contents depending on how the widgets are configured.\n\n    this.setSelection(this.isMultiSelect() ? [...selecedRowsByHash.values(), row] : [row]);\n\n**Select Mode**\n\nAvailable when a component has `\u003chasStep\u003etrue\u003c/hasStep\u003e`, `selectMode` describes which select mode the results from the step are in. Possible values are `single`, `multi`, `singlerequired`, `multirequired`, and `none`.\n\n    isMultiSelect() { return this.selectMode.includes('multi'); }\n\n**getState**\n\nAlways available to the component, use `getState` to retrieve the current state of the dashboard. The state format is documented [here](https://help.salesforce.com/articleView?id=sf.bi_embed_filters.htm\u0026type=5).\n\n**setState**\n\nAlways available to the component, use `setState` to patch the current state of the dashboard.\n\n    if (!this.getState().pageId == this.targetPage) {\n        this.priorPage = this.getState().pageId;\n        this.setState({...this.getState(), pageId : this.targetPage});\n    }\n\n**stateChangedCallback**\n\nAvailable as a custom lifecycle hook in v55 and later, use `stateChangedCallback` to detect any change to the dashboard state and allow the component to rerender.\n\n    @api stateChangedCallback(prevState, newState) {\n        // Do any comparisons on prevState and newState to determine if the component should rerender\n        this.currentState = newState;\n    }\n\n**Create a LWC for CRM Analytics Dashboards**\n\nQuickly create Lightning Web Components configured for use in CRM Analytics dashboards\n\n1. Visual Studio command\n\n   ```\n   SFDX: Create Analytics Dashboard LWC\n   ```\n\n1. CLI command\n   ```\n   sfdx force:lightning:component:create --type lwc -t [analyticsDashboard|analyticsDashboardWithStep] -n \u003cname\u003e\n   ```\n\n## CRM Analytics App Templates\n\nUse the Quick Start template to practice working with CRM Analytics app templates in your scratch org. Then, create\nyour own apps and templatize them using the Analytics CLI plugin and Visual Studio commands.\n\n1. Now you have a scratch org with an Analytics template installed. Explore the Analytics commands by running\n   `sfdx analytics --help`or open the Visual Studio command palette and search for available `SFDX` commands.\n\n1. View the options available to create an Analytics template from an app\n\n   ```\n   sfdx analytics:app:create --help\n   ```\n\n   or\n\n   ```\n   SFDX: Create Analytics Template\n   ```\n\n1. View the Analytics template:\n\n   ```\n   sfdx analytics:template:list\n   ```\n\n1. To create an Analytics application from the template you have two options:\n\n   1. From CLI:\n\n      ```\n      sfdx analytics:app:create -t \u003ctemplateid\u003e\n      ```\n\n      or\n\n      ```\n      SFDX: Create Analytics App from Template\n      ```\n\n   1. From Analytics Studio\n\n      1. Open the scratch org\n\n         ```\n         sfdx force:org:open -p analytics\n         ```\n\n         or\n\n         ```\n         SFDX: Open Analytics Studio\n         ```\n\n      1. Select 'Create' \u003e 'App' \u003e 'Start From Template' in Analytics Studio\n\n1. To view the Analytics applications from the CLI:\n   ```\n   sfdx analytics:app:list\n   ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforcedotcom%2Fsfdx-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fforcedotcom%2Fsfdx-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforcedotcom%2Fsfdx-analytics/lists"}