### Initialize RudderTyper Project
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command initiates a quickstart wizard to create a `ruddertyper.yml` file and generate your first client with specified configuration details. It's the starting point for setting up RudderTyper in your project.
```sh
npx rudder-typer init | initialize | quickstart
```
--------------------------------
### Install Node.js Dependencies
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/node-javascript/README.md
Installs the necessary dependencies for the Node.js application using npm. This command should be run after cloning the project to set up the development environment.
```bash
npm run setup
```
--------------------------------
### RudderTyper Tracking Plan Configuration Example (YAML)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Example of configuring a RudderStack Tracking Plan for RudderTyper. This includes the plan ID, workspace slug, save path, and API version.
```yaml
trackingPlans:
- id: rs_QhWHOgp7xg8wkYxilH3scd2uRID
workspaceSlug: rudderstack-demo
path: ./analytics
APIVersion: v2
```
--------------------------------
### RudderTyper Client Configuration Example (YAML)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Example of RudderTyper client configuration within a tracking plan. This demonstrates overriding root-level settings for SDK, language, script target, and module target.
```yaml
client:
sdk: analytics.js
language: typescript
scriptTarget: 'ES5'
moduleTarget: 'ESNext'
```
--------------------------------
### Start Node.js Application
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/node-javascript/README.md
Starts the Node.js application, which will then send track events to the configured data plane URL. Ensure the `.env` file is properly set up with the write key and data plane URL before running this command.
```bash
npm run start
```
--------------------------------
### Generate Client Library with RudderTyper CLI
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/ios-swift/README.md
Regenerates the client library based on your tracking plan using the production version of RudderTyper. This command-line interface tool requires Node.js and npm.
```bash
npx rudder-typer@latest init
```
--------------------------------
### Track Cart View Event in Swift
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/ios-swift/README.md
Implements event tracking for a 'cartViewed' event within a Swift application. This example shows how to pass parameters like discount and email to the event tracking function.
```swift
RSRudderTyperAnalytics.cartViewed(discount:23.45, email:@"test@mail2.com")
```
--------------------------------
### RudderTyper Configuration Override Example (YAML)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Demonstrates how tracking plan level configuration overrides root-level settings in RudderTyper. This example shows specific client and script settings defined within a tracking plan.
```yaml
trackingPlans:
- id: rs_QhWHOgp7xg8wkYxilH3scd2uRID
workspaceSlug: rudderstack-demo
path: ./analytics
APIVersion: v2
scripts:
token: source .env; echo $RUDDERTYPER_TOKEN
client:
sdk: analytics-android
language: swift
```
--------------------------------
### Regenerate Client Library Locally with Shell Script
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/ios-swift/README.md
Regenerates the client library using local analytics files and a predefined shell script. This method is useful for development and testing against local repositories.
```bash
./rt_local_script_swift.sh
```
--------------------------------
### Android Java Integration with RudderTyper
Source: https://context7.com/rudderlabs/rudder-typer/llms.txt
Provides an example of integrating the auto-generated RudderTyper client with an Android application using Java. It demonstrates sending a strongly-typed 'orderCompleted' event using the Builder pattern for event properties.
```java
// Import auto-generated RudderTyper client
import com.rudderstack.generated.*;
// Send strongly-typed track event using Builder pattern
RudderTyperAnalytics.with(this).orderCompleted(
OrderCompleted.Builder()
.orderID("ck-f306fe0e-cc21-445a-9caa-08245a9aa52c")
.total(39.99)
.build()
);
```
--------------------------------
### iOS Objective-C Integration with RudderTyper
Source: https://context7.com/rudderlabs/rudder-typer/llms.txt
Shows how to integrate the auto-generated RudderTyper client within an iOS application using Objective-C. This example focuses on sending a type-safe 'orderCompleted' event with its associated properties.
```objc
// Import auto-generated RudderTyper client
#import "RSRudderTyperAnalytics.h"
// Send strongly-typed track event
[RSRudderTyperAnalytics orderCompletedWithOrderID:@"ck-f306fe0e-cc21-445a-9caa-08245a9aa52c"
total:@39.99];
```
--------------------------------
### Regenerate Analytics Files Locally with Script
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/ios-objc/README.md
This script regenerates the client library using local analytics files. It's a predefined shell script that leverages the supported commands of rudder-typer. No specific dependencies are mentioned beyond the script's internal logic.
```bash
./rt_local_script.sh
```
--------------------------------
### Browser JavaScript (NPM) Integration with RudderTyper
Source: https://context7.com/rudderlabs/rudder-typer/llms.txt
Shows how to integrate RudderTyper with the RudderStack JavaScript SDK when installed via NPM. It covers initializing the SDK and connecting RudderTyper for sending type-safe events like 'orderCompleted'. Requires the '@rudderstack/analytics-js' package.
```javascript
// Import RudderStack JS SDK and RudderTyper client
import { RudderAnalytics } from '@rudderstack/analytics-js';
import { RudderTyperAnalytics } from './analytics/index';
// Initialize RudderStack JS SDK
const rudderAnalytics = new RudderAnalytics();
rudderAnalytics.load('YOUR_WRITE_KEY', 'https://your-data-plane.rudderstack.com', {});
// Connect RudderTyper to analytics instance
RudderTyperAnalytics.setRudderTyperOptions({
analytics: rudderAnalytics,
});
// Track strongly-typed events
RudderTyperAnalytics.orderCompleted({
orderID: 'ck-f306fe0e-cc21-445a-9caa-08245a9aa52c',
total: 39.99,
});
```
--------------------------------
### Regenerate Browserify Bundle with TypeScript
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/README.md
This command regenerates the browserify bundle for the RudderTyper client library, processing TypeScript files and creating a standalone bundle. It requires `browserify` and `tsify` to be installed.
```bash
npx browserify src/analytics/index.ts -p [ tsify ] --standalone rudderTyper > public/rudderTyperBundle.js
```
--------------------------------
### Clear npm Cache and RudderTyper Local Data
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
These commands are used for troubleshooting setup errors. `npm cache clean --force` clears the npm cache, and `rm -r ~/.ruddertyper` removes the local RudderTyper configuration directory.
```sh
npm cache clean --force
rm -r ~/.ruddertyper
```
--------------------------------
### Track Order Completed Event with RudderTyper (Kotlin)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/tests/e2e/android-kotlin/readme.md
This Kotlin code snippet demonstrates how to track an `OrderCompleted` event using the RudderTyper generated analytics client. It requires the RudderStack Android SDK and the generated RudderTyper classes. The function takes a `Context` as input and builds an `OrderCompleted` event with various properties before tracking it.
```kotlin
private fun makeRudderTyperEvent(context: Context) {
RudderTyperAnalytics.with(context)
.orderCompleted(
OrderCompleted.Builder()
.age(23)
.amount("123.45")
.anonymousId("custom anonymous id")
.arrayWithNumber(listOf(1, 2, 3))
.build()
)
}
```
--------------------------------
### Display RudderTyper CLI Version
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command prints the current version of the RudderTyper Command Line Interface (CLI) that is installed. It's helpful for checking compatibility and ensuring you're using the latest features.
```sh
npx rudder-typer version
```
--------------------------------
### Track Cart Viewed Event in Objective-C
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/ios-objc/README.md
This Objective-C code snippet demonstrates how to track a 'cartViewed' event using the RudderTyper generated analytics class. It requires the RudderStack SDK to be initialized and configured. The method accepts parameters like discount and email.
```objective-c
[RSRudderTyperAnalytics cartViewedWithDiscount:@23.45 email:@"test@mail2.com" employees:nil];
```
--------------------------------
### Track Events with RudderTyper
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
Demonstrates how to track events using the RudderTyper library. It shows different ways to pass event data, including simple events and events with context and callbacks. Ensure RudderTyper is initialized before use.
```javascript
function track() {
rudderTyper.track('sample event name', {
'Sample property 1': 'Sample value 1',
});
rudderTyper.track('sample event name', {
'Sample property 1': 'Sample value 1',
}, {
integrations: {
All: true,
'Google Analytics': true,
},
context: {
active: true,
app: {
name: 'RudderStack',
version: '1.0.0',
build: '100',
},
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
timestamp: new Date(),
extraKey1: 'value1',
},
}, () => {
console.log('callback called from sampleEvent1 event');
});
}
```
--------------------------------
### Node.js TypeScript Integration with RudderTyper
Source: https://context7.com/rudderlabs/rudder-typer/llms.txt
Demonstrates integrating the generated RudderTyper client with the RudderStack Node.js SDK. It shows initialization, event tracking (track, page, screen, identify, group), and flushing events. Requires the '@rudderstack/rudder-sdk-node' package.
```typescript
import { RudderTyperAnalytics } from './analytics/index';
import RudderAnalytics from '@rudderstack/rudder-sdk-node';
// Initialize the RudderStack Node.js SDK
const client = new RudderAnalytics('YOUR_WRITE_KEY', {
dataPlaneUrl: 'https://your-data-plane.rudderstack.com',
});
// Connect RudderTyper to the analytics instance
RudderTyperAnalytics.setRudderTyperOptions({
analytics: client,
});
// Send strongly-typed track event with properties
RudderTyperAnalytics.sampleEvent1({
anonymousId: 'sample_anonymous_id',
properties: {
'Sample property 1': 'Sample value 1',
},
});
// Track event with full context and callback
RudderTyperAnalytics.sampleEvent1(
{
userId: 'user_123',
anonymousId: 'anon_456',
properties: {
'Sample property 1': 'Sample value 1',
},
context: {
app: { name: 'MyApp', version: '1.0.0', build: '100' },
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
},
integrations: { All: true, Amplitude: false },
timestamp: new Date(),
},
() => {
console.log('Event sent successfully');
}
);
// Page view tracking
RudderTyperAnalytics.page({
userId: 'user_123',
name: 'Home Page',
properties: { 'Sample property 1': 'Sample value 1' },
});
// Screen view tracking (mobile)
RudderTyperAnalytics.screen({
userId: 'user_123',
name: 'Dashboard Screen',
properties: { 'Sample property 1': 'Sample value 1' },
});
// Identify user with traits
RudderTyperAnalytics.identify({
userId: 'user_123',
traits: { 'Sample property 1': 'Sample value 1' },
});
// Group user with organization
RudderTyperAnalytics.group({
userId: 'user_123',
groupId: 'org_789',
traits: { 'Sample property 1': 'Sample value 1' },
});
// Flush events before process exit
await client.flush();
```
--------------------------------
### Build RudderTyper Production Client
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command generates a production-ready client from the `plan.json` file. It's used for creating a client intended for deployment in a production environment.
```sh
npx rudder-typer prod | p | production
```
--------------------------------
### Build RudderTyper Development Client
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command generates a development client from the `plan.json` file. It's used for creating a client intended for testing and development purposes within your project.
```sh
npx rudder-typer build | b | d | dev | development
```
--------------------------------
### Integrate RudderTyper with JavaScript SDK (NPM)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This snippet demonstrates integrating the RudderTyper client using NPM in a JavaScript project. It involves importing the RudderStack JS SDK and the auto-generated RudderTyper client, initializing the SDK, and then using the RudderTyper client to send events like 'orderCompleted'. Remember to replace placeholders for WRITE_KEY and DATA_PLANE_URL.
```javascript
// Import RudderStack JS SDK and initialize it
import { RudderAnalytics } from '@rudderstack/analytics-js';
// Import your auto-generated RudderTyper client:
import { RudderTyperAnalytics } from './analytics/index';
const rudderAnalytics = new RudderAnalytics();
rudderAnalytics.load(WRITE_KEY, DATA_PLANE_URL, {});
// Pass in your @rudderstack/analytics-js instance to RudderTyper client
RudderTyperAnalytics.setRudderTyperOptions({
analytics: rudderAnalytics,
});
// Issue your first RudderTyper track call!
RudderTyperAnalytics.orderCompleted({
orderID: 'ck-f306fe0e-cc21-445a-9caa-08245a9aa52c',
total: 39.99,
});
```
--------------------------------
### Initialize RudderStack SDK
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
This code initializes the RudderStack JavaScript SDK. It checks if the SDK is already included, defines methods for interacting with the SDK, and loads the necessary scripts. It also handles different build types (legacy and modern) and polyfills for older browsers.
```javascript
window.RudderSnippetVersion = '3.0.24';
var identifier = 'rudderanalytics';
if (!window[identifier]) {
window[identifier] = [];
}
var rudderanalytics = window[identifier];
if (Array.isArray(rudderanalytics)) {
if (rudderanalytics.snippetExecuted === true && window.console && console.error) {
console.error('RudderStack JavaScript SDK snippet included more than once.');
} else {
rudderanalytics.snippetExecuted = true;
window.rudderAnalyticsBuildType = 'legacy';
var sdkBaseUrl = 'https://cdn.rudderlabs.com/v3';
var sdkName = 'rsa.min.js';
var scriptLoadingMode = 'async';
var methods = [
'setDefaultInstanceKey',
'load',
'ready',
'page',
'track',
'identify',
'alias',
'group',
'reset',
'setAnonymousId',
'startSession',
'endSession',
'consent',
];
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
rudderanalytics[method] = (function (methodName) {
return function () {
if (Array.isArray(window[identifier])) {
rudderanalytics.push(
[methodName].concat(Array.prototype.slice.call(arguments)),
);
} else {
var _methodName;
(_methodName = window[identifier][methodName]) === null ||
_methodName === void 0 ||
_methodName.apply(window[identifier], arguments);
}
};
})(method);
}
try {
new Function('return import("")');
window.rudderAnalyticsBuildType = 'modern';
} catch (e) {}
var head = document.head || document.getElementsByTagName('head')[0];
var body = document.body || document.getElementsByTagName('body')[0];
window.rudderAnalyticsAddScript = function (url, extraAttributeKey, extraAttributeVal) {
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.setAttribute('data-loader', 'RS_JS_SDK');
if (extraAttributeKey && extraAttributeVal) {
scriptTag.setAttribute(extraAttributeKey, extraAttributeVal);
}
if (scriptLoadingMode === 'async') {
scriptTag.async = true;
} else if (scriptLoadingMode === 'defer') {
scriptTag.defer = true;
}
if (head) {
head.insertBefore(scriptTag, head.firstChild);
} else {
body.insertBefore(scriptTag, body.firstChild);
}
};
window.rudderAnalyticsMount = function () {
(function () {
if (typeof globalThis === 'undefined') {
var getGlobal = function getGlobal() {
if (typeof self !== 'undefined') {
return self;
}
if (typeof window !== 'undefined') {
return window;
}
return null;
};
var global = getGlobal();
if (global) {
Object.defineProperty(global, 'globalThis', {
value: global,
configurable: true,
});
}
}
})();
window.rudderAnalyticsAddScript(
''.concat(sdkBaseUrl, '/')
.concat(window.rudderAnalyticsBuildType, '/')
.concat(sdkName),
'data-rsa-write-key',
'__WRITE_KEY__',
);
};
if (typeof Promise === 'undefined' || typeof globalThis === 'undefined') {
window.rudderAnalyticsAddScript(
'https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount',
);
} else {
window.rudderAnalyticsMount();}
var loadOptions = {
logLevel: 'DEBUG',
configUrl: 'https://api.rudderstack.com',
destSDKBaseURL: sdkBaseUrl + '/' + window.rudderAnalyticsBuildType + '/js-integrations',
pluginsSDKBaseURL: sdkBaseUrl + '/' + window.rudderAnalyticsBuildType + '/plugins',
};
rudderanalytics.load('__WRITE_KEY__', '__DATAPLANE_URL__', loadOptions);
}
}
```
--------------------------------
### Regenerate RudderTyper Client Library (Production)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/node-javascript/README.md
Regenerates the RudderTyper client library based on the tracking plan using the production version from NPM. This command initializes the client library generation process.
```bash
npx rudder-typer init
```
--------------------------------
### Browser JavaScript (CDN) Integration with RudderTyper
Source: https://context7.com/rudderlabs/rudder-typer/llms.txt
Illustrates integrating RudderTyper with the RudderStack JavaScript SDK loaded via a CDN. This method involves including the SDK snippet, a bundled RudderTyper client (e.g., from `browserify`), and then connecting them to send events like 'orderCompleted'.
```html
```
--------------------------------
### Generate RudderTyper Client Libraries
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/README.md
Generates new `index.ts` and `rudder.ts` files based on the `ruddertyper.yml` configuration file. This command is essential for updating your client library with the latest tracking plan definitions.
```bash
npx rudder-typer
```
--------------------------------
### Group Users with RudderTyper
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
Illustrates how to group users using RudderTyper. This function allows for associating users with specific groups and providing group-level traits and context. Ensure RudderTyper is initialized and configured correctly.
```javascript
function group() {
rudderTyper.group('sample group id', {
'Sample property 1': 'Sample value 1',
});
rudderTyper.group({
'Sample property 1': 'Sample value 1',
});
rudderTyper.group('sample group id', {
'Sample property 1': 'Sample value 1',
}, {
integrations: {
All: true,
'Google Analytics': true,
},
context: {
active: true,
app: {
name: 'RudderStack',
version: '1.0.0',
build: '100',
},
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
timestamp: new Date(),
extraKey1: 'value1',
},
}, () => {
console.log('callback called from sampleEvent1 event');
});
}
```
--------------------------------
### Update RudderTyper Client
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command synchronizes your local `plan.json` file with the latest changes from your RudderStack tracking plan. It then generates an updated development client based on the synchronized data.
```sh
npx rudder-typer update | u | *
# (default)
```
--------------------------------
### Provide Workspace Email via Script
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Supplies the email address linked to your RudderStack workspace by executing a script. The script's output should be a valid email address registered with your workspace. It reads the email from the EMAIL environment variable after sourcing a .env file.
```bash
source .env; echo $EMAIL
```
--------------------------------
### View RudderTyper Token Configuration
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command displays the locally configured RudderStack API token. This is useful for verifying authentication settings for your RudderTyper client.
```sh
npx rudder-typer token | tokens | t
```
--------------------------------
### Provide RudderStack API Token via Script
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Supplies a RudderStack API token by executing a script. The script's output must be a valid RudderStack API token. It reads the token from the RUDDERTYPER_TOKEN environment variable after sourcing a .env file.
```bash
source .env; echo $RUDDERTYPER_TOKEN
```
--------------------------------
### Identify Users with RudderTyper
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
Shows how to identify users with RudderTyper, including options for setting user traits and providing context. This is crucial for user-specific analytics. The library needs to be properly configured prior to calling this function.
```javascript
function identify() {
rudderTyper.identify('sample user id', {
email: 'sample@example.com',
name: 'John Doe',
});
rudderTyper.identify('sample user id', {
email: 'sample@example.com',
name: 'John Doe',
}, {
integrations: {
All: true,
'Google Analytics': true,
},
context: {
active: true,
app: {
name: 'RudderStack',
version: '1.0.0',
build: '100',
},
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
timestamp: new Date(),
extraKey1: 'value1',
},
}, () => {
console.log('callback called from sampleEvent1 event');
});
}
```
--------------------------------
### Display RudderTyper Help Message
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This command shows the help message, which details all the available commands and their usage within the RudderTyper CLI. It serves as a quick reference for using the tool effectively.
```sh
npx rudder-typer help
```
--------------------------------
### Regenerate RudderTyper Client Library (Development)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/node-javascript/README.md
Regenerates the RudderTyper client library based on the tracking plan using the RudderType module from the local repository. This requires the repository to be set up for development and builds the module locally before regenerating the client library.
```bash
npm run rudder-typer:dev init
```
--------------------------------
### Track Events with RudderStack
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
This function demonstrates how to track custom events using the RudderStack SDK. It includes sample event data, integration options, and context information. A callback function is also provided to execute after the event is tracked.
```javascript
function track() {
rudderTyper.sampleEvent1(
{
'Sample property 1': 'Sample value 1',
},
{
integrations: {
All: true,
'Google Analytics': true,
},
context: {
active: true,
app: {
name: 'RudderStack',
version: '1.0.0',
build: '100',
},
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
timestamp: new Date(),
extraKey1: 'value1',
},
},
() => {
console.log('callback called from sampleEvent1 event');
},
);
}
```
--------------------------------
### Run RudderTyper Development Script
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/README.md
Executes RudderTyper commands using the locally developed module. This is useful for testing changes to the RudderTyper library during development.
```bash
npm run rudder-typer:dev
```
--------------------------------
### Run Production RudderTyper Command
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/README.md
Executes a specified command using the production version of RudderTyper. This allows you to perform various operations on your RudderTyper client library.
```bash
npx rudder-typer
```
--------------------------------
### Integrate RudderTyper with Node.js SDK
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
This snippet shows how to integrate the RudderTyper client with the RudderStack Node.js SDK. It involves importing the Rudder Node SDK and the RudderTyper-generated client, initializing the Node.js client with your write key and data plane URL, and then passing the client to RudderTyper to send events.
```javascript
// Import Rudder Node SDK and initialize it
const RudderAnalytics = require('@rudderstack/rudder-sdk-node');
const client = new RudderAnalytics(WRITE_KEY, {
dataPlaneUrl: DATA_PLANE_URL,
// More initialization options
});
const RudderTyperAnalytics = require('./analytics/index');
// Pass in your @rudderstack/rudder-sdk-node instance to RudderTyper.
RudderTyperAnalytics.setRudderTyperOptions({
analytics: client,
});
// Issue your first RudderTyper track call!
RudderTyperAnalytics.orderCompleted({
orderID: 'ck-f306fe0e-cc21-445a-9caa-08245a9aa52c',
total: 39.99,
});
```
--------------------------------
### Identify Users with RudderStack
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
This function demonstrates how to identify users using the RudderStack SDK. It allows identifying users with a user ID and optional traits. It also includes integration options and context information.
```javascript
function identify() {
rudderTyper.identify('sample user id', {
'Sample property 1': 'Sample value 1',
});
rudderTyper.identify({
'Sample property 1': 'Sample value 1',
});
rudderTyper.identify(
'sample user id', {
'Sample property 1': 'Sample value 1',
},
{
integrations: {
All: true,
'Google Analytics': true,
},
context: {
active: true,
app: {
name: 'RudderStack',
version: '1.0.0',
build: '100',
},
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
timestamp: new Date(),
extraKey1: 'value1',
},
},
);
}
```
--------------------------------
### Integrate RudderTyper Client with Android App (Java)
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Shows how to integrate a RudderTyper-generated client into an Android application using Java. It includes importing the generated client and making a track call for an 'orderCompleted' event.
```java
// Import your auto-generated RudderTyper client:
import com.rudderstack.generated.*
// Issue your first RudderTyper track call!
RudderTyperAnalytics.with(this).orderCompleted(
OrderCompleted.Builder()
.orderID("ck-f306fe0e-cc21-445a-9caa-08245a9aa52c")
.total(39.99)
.build()
);
```
--------------------------------
### Format RudderTyper Generated Files
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/README.md
Formats any of RudderTyper's auto-generated files using Prettier. This script ensures consistent code style for generated analytics plan JSON files.
```bash
./node_modules/.bin/prettier --write analytics/plan.json
```
--------------------------------
### Initialize RudderStack SDK in React App
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-npm-typescript/public/index.html
This JavaScript code snippet initializes the RudderStack JavaScript SDK within a React application. It ensures the SDK is loaded only once and defines methods for tracking user events. It handles cases where the SDK might be called before it's fully initialized.
```javascript
"use strict";
window.RudderSnippetVersion = "3.0.24";
var identifier = "rudderanalytics";
if (!window[identifier]) {
window[identifier] = [];
}
var rudderanalytics = window[identifier];
if (Array.isArray(rudderanalytics)) {
if (rudderanalytics.snippetExecuted === true && window.console && console.error) {
console.error("RudderStack JavaScript SDK snippet included more than once.");
} else {
rudderanalytics.snippetExecuted = true;
var methods = [
"setDefaultInstanceKey",
"load",
"ready",
"page",
"track",
"identify",
"alias",
"group",
"reset",
"setAnonymousId",
"startSession",
"endSession",
"consent"
];
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
rudderanalytics[method] = function(methodName) {
return function() {
if (Array.isArray(window[identifier])) {
rudderanalytics.push([methodName].concat(Array.prototype.slice.call(arguments)));
} else {
var _methodName;
(_methodName = window[identifier][methodName]) === null || _methodName === void 0 || _methodName.apply(window[identifier], arguments);
}
};
}(method);
}
}
}
// Below line is only for demonstration purpose, SPA code is better place for auto page call
window.rudderanalytics.page('sample page call');
```
--------------------------------
### Track Page Views with RudderStack
Source: https://github.com/rudderlabs/rudder-typer/blob/develop/examples/js-cdn-typescript/public/index.html
This function showcases different ways to track page views using the RudderStack SDK. It supports tracking with and without a category, and with or without additional properties and context. It also includes a callback function.
```javascript
function page() {
rudderTyper.page('sample category name', 'sample page name', {
'Sample property 1': 'Sample value 1',
});
rudderTyper.page('sample page name', {
'Sample property 1': 'Sample value 1',
});
rudderTyper.page({
'Sample property 1': 'Sample value 1',
});
rudderTyper.page(
'sample category name', 'sample page name', {
'Sample property 1': 'Sample value 1',
},
{
integrations: {
All: true,
'Google Analytics': true,
},
context: {
active: true,
app: {
name: 'RudderStack',
version: '1.0.0',
build: '100',
},
device: {
id: 'device_id',
manufacturer: 'Samsung',
model: 'Galaxy S20',
name: 'Samsung Galaxy S20',
type: 'Android',
},
timestamp: new Date(),
extraKey1: 'value1',
},
},
() => {
console.log('callback called from sampleEvent1 event');
},
);
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.