MCPcopy Create free account
hub / github.com/DavidWells/analytics / renderUsageExample

Function renderUsageExample

packages/analytics-cli/src/commands/docs.js:141–181  ·  view source on GitHub ↗
(example, name, pkg)

Source from the content-addressed store, hash-verified

139}
140
141function renderUsageExample(example, name, pkg) {
142 const code = `
143import Analytics from 'analytics'
144import ${name} from '${pkg}'
145
146const analytics = Analytics({
147 app: 'awesome-app',
148 plugins: [
149 ${example.replace(/^\s+|\s+$/g, '')},
150 // ...other plugins
151 ]
152})
153
154/* Track page views */
155analytics.page()
156
157/* Track custom events */
158analytics.track('buttonClicked')
159
160/* Identify visitors */
161analytics.identify('user-xzy-123', {
162 name: 'Bill Murray',
163 cool: true
164})
165`
166 const formattedCode = prettier.format(code, { semi: false, singleQuote: true, parser: 'babel' })
167
168 return `## Usage
169
170Install \`analytics\` and \`${pkg}\` packages
171
172\`\`\`bash
173npm install analytics ${pkg}
174\`\`\`
175
176Import and initialize in project
177
178\`\`\`js
179${formattedCode}
180\`\`\``
181}

Callers 1

USAGEFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected