| 139 | } |
| 140 | |
| 141 | function renderUsageExample(example, name, pkg) { |
| 142 | const code = ` |
| 143 | import Analytics from 'analytics' |
| 144 | import ${name} from '${pkg}' |
| 145 | |
| 146 | const analytics = Analytics({ |
| 147 | app: 'awesome-app', |
| 148 | plugins: [ |
| 149 | ${example.replace(/^\s+|\s+$/g, '')}, |
| 150 | // ...other plugins |
| 151 | ] |
| 152 | }) |
| 153 | |
| 154 | /* Track page views */ |
| 155 | analytics.page() |
| 156 | |
| 157 | /* Track custom events */ |
| 158 | analytics.track('buttonClicked') |
| 159 | |
| 160 | /* Identify visitors */ |
| 161 | analytics.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 | |
| 170 | Install \`analytics\` and \`${pkg}\` packages |
| 171 | |
| 172 | \`\`\`bash |
| 173 | npm install analytics ${pkg} |
| 174 | \`\`\` |
| 175 | |
| 176 | Import and initialize in project |
| 177 | |
| 178 | \`\`\`js |
| 179 | ${formattedCode} |
| 180 | \`\`\`` |
| 181 | } |