Skip to content

Commit

Permalink
feat: add rudderanalytics
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrpo committed Feb 29, 2024
1 parent 951bcdc commit c625d3d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"main": "./src/cli/index.js",
"bin": "./src/cli/index.js",
"scripts": {
"init": "TS_NODE_FILES=true ts-node ./src/cli init",
"dev": "TS_NODE_FILES=true NODE_ENV=development ts-node ./src/cli",
"prod": "TS_NODE_FILES=true NODE_ENV=production ts-node ./src/cli prod",
"build": "rm -rf dist && tsc && copyfiles --up 1 \"src/**/*.hbs\" dist/src/ && copyfiles \"README.*\" dist/ && copyfiles \"CHANGELOG.*\" dist/",
Expand Down
8 changes: 4 additions & 4 deletions src/generators/javascript/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ For more information on analytics-node, see: https://docs.rudderstack.com/stream
`)
{{/unless}}

{{!-- We use a closure so we can lazy-resolve window.analytics in browser environments. --}}
{{!-- We use a closure so we can lazy-resolve window.rudderanalytics in browser environments. --}}
let analytics: () => ({{#if isBrowser}}any{{else}}Rudder.AnalyticsNode{{/if}} | undefined) = () => {
{{#if isBrowser}}
return window.analytics
return window.rudderanalytics
{{else}}
throw missingAnalyticsNodeError
{{/if}}
Expand All @@ -108,7 +108,7 @@ export interface RudderTyperOptions {
/**
* Underlying analytics instance where analytics calls are forwarded on to.
{{#if isBrowser}}
* Defaults to window.analytics.
* Defaults to window.rudderanalytics.
{{/if}}
*/
analytics{{#if isBrowser}}?{{/if}}: {{#if isBrowser}}any{{else}}Rudder.AnalyticsNode{{/if}}
Expand All @@ -125,7 +125,7 @@ export interface RudderTyperOptions {

{{> setRudderTyperOptionsDocumentation}}
export function setRudderTyperOptions(options: RudderTyperOptions) {
analytics = options.analytics ? () => options.analytics{{#if isBrowser}} || window.analytics{{/if}} : analytics
analytics = options.analytics ? () => options.analytics{{#if isBrowser}} || window.rudderanalytics{{/if}} : analytics
{{#if isDevelopment}}
onViolation = options.onViolation || onViolation
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion src/generators/javascript/templates/rudder.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
declare global {
interface Window {
analytics: any
rudderanalytics: any
}
}

Expand Down

0 comments on commit c625d3d

Please sign in to comment.