Phygrid Developers
Browse Topics
React App Integration / Phygrid Developers

React App Integration

This page describes how you can integrate your React-based App to Grid Signals.

Functions

States and Events

useGridSignals

Use this hook if your app is built from the omg app create template or is using @ombori/ga-settings.

This will initialize the Grid Signals instance using the application settings. Under the hood, it uses @ombori/ga-settings to automatically get the required Grid Signals parameters for initialization.

You can only start invoking any other functions when Grid Signals is ready.

Usage

import React from "react"
import { useGridSignals, getInstance as gs } from "@ombori/grid-signals-react"
const App = () => {
  const isReady = useGridSignals()
  if (!isReady) {
    return <div>Initializing App</div>
  }
  return <MainPage />
}

Ideally, you don't need to override the parameters when using this function. However, we provide the ability to override the Grid Signals Init Parameters for flexibility.

const isReady = useGridSignals({
  environment: 'TEST_ENV',
  ...<other valid parameters you want to override>,
});

useGridSignalsWithExternalParams

Use this hook if your app is not using @ombori/ga-settings.

This will initialize the Grid Signals instance with the required Init Parameters.

Usage

import React from "react"
import { useGridSignalsWithExternalParams } from "@ombori/grid-signals-react"

const App = () => {
  const isReady = useGridSignalsWithExternalParams({
    deviceId: "XXXXXXXXXXXXXXXXXXXXXXXX",
    installationId: "XXXXXXXXXXXXXXXXXXXXXXXX",
    spaceId: "XXXXXXXXXXXXXXXXXXXXXXXX",
    tenantId: "XXXXXXXXXXXXXXXXXXXXXXXX",
    appVersion: "XXXXXXXXXXXXXXXXXXXXXXXX",
    appId: "XXXXXXXXXXXXXXXXXXXXXXXX",
    environment: "PROD",
    dataResidency: "EU",
    country: "SE",
    installationVersion: "XXXXXXXXXXXXXXXXXXXXXXXX",
    accessId: "XXXX",
    accessToken: "XXXX",
  })

  if (!isReady) {
    return <div>Initializing App</div>
  }

  return <MainPage />
}

getInstanceProps

This will return the instance object of the session. Ideally, you don't need to get the instance props. This is provided for flexibility.

Usage

import { getInstance as gs } from '@ombori/grid-signals-react';

...
  gs().getInstanceProps();
...

Returns

These are the instance properties that are returned from the getInstance() method.

KeyTypeDescription
tenantIdstringTenant id in the Grid Console
sessionIdstringGrid Session instance-id
environmentstringApplication environment
dataResidencystringThe region where to store the data
countrystringTenant base country (Abbrev.)
spaceIdstringThe id of the Space where the device or any entity is located
appIdstringThe id of the gridapp which is running on a device
appVersionstring

List of Product Type IDs applicable to this product as a reference from ProductTypes Database

installationIdstringThe id of the installation in Grid Console
installationVersionstringBuild id of the installation
deviceIdstring

Id of the device in the console. If deviceId is not passed, virtual deviceId is created

clientIdstring

Client id of the requestor. clientId is same as deviceId for registered devices in console

clientCreatedstringDate when the client id is created
clientUserAgentstringRequestor user agent
locationAccuracynumberGeographic coordinates accuracy
latitudenumberGeographic latitude of the device or requestor
longitudenumberGeographic longitude of the device or requestor
lastActivitystringDate string of the last invoked function

createSession

Starts a new session. You should call this method every time a new user starts interacting with the application.

Usage

import { getInstance as gs } from '@ombori/grid-signals-react';

...
  gs().createSession();
...

Grid Signals Init Parameters

KeyTypeDescriptionRequiredOptions
tenantIdstringTenant id in the Grid Consoleyes
environmentstringApplication environmentyes
dataResidencystringThe region where to store the datayes"EU", "UAE", "IN", "US", "AU"
countrystringTenant base country (Abbrev.)yes
spaceIdstringThe id of the Space where the device or any entity is locatedyes
appIdstringThe id of the gridapp which is running on a deviceyes
appVersionstring

List of Product Type IDs applicable to this product as a reference from ProductTypes Database

yes
installationIdstringThe id of the installation in Grid Consoleyes
installationVersionstringBuild id of the installationyes
deviceIdstring

Id of the device in the console. If deviceId is not passed, virtual deviceId is created

no
clientUserAgentstringRequestor user agentyes
locationAccuracynumberGeographic coordinates accuracyno
latitudenumberGeographic latitude of the device or requestorno-90 to 90
longitudenumberGeographic longitude of the device or requestorno-180 to 180
accessIdstring

Credentials used when subscribing to session or space state or events

no
accessTokenstring

Credentials used when subscribing to session or space state or events

no

Event Tracking

See Event Tracking page for more details.

© 2024 · Phygrid. An Ombori company