NAV
javascript swift kotlin

Introduction

Welcome to the Polymatiks Analytics SDK.

This is a library built on top of the Google Analytics. It provides a set of reusable functions to track user interactions and events in your project.

This SDK simplifies the process of sending data to Google Analytics by encapsulating common tracking logic into easy-to-use functions.

Getting Started

Installation

npm install @polymatiks/react-analytics-sdk
//Using CocoaPods
target 'YourAppTarget' do
  pod 'Analytics', :git => 'https://github.com/polymatiks/analytics-ios-sdk.git', :tag => '1.0.0'
end
//Include Polymatiks Maven Repository as a gradle source in your settings.gradle
repositories {
    //...
    maven { url 'https://repository.sdk.polymatiks.ai/repository/maven-public/' }
    //...
}
//Properly include the dependency in your project build.gradle file
dependencies {
    //...
    implementation 'ai.polymatiks:analytics:0.1.0'
    //...
}

The SDK is designed to be easy to integrate into different development environments. Below, you’ll find the steps to install and configure the SDK for the main frameworks: React, Native Android, and Native iOS.

--

--

Authentication

// Javascript library automatically takes care of the authentication
import FirebaseApp

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

        if FirebaseApp.app() == nil {
            let options = FirebaseOptions(
                googleAppID: ProcessInfo.processInfo.environment["POLYMATIKS_APP_ID"] ?? "",
                gcmSenderID: ProcessInfo.processInfo.environment["POLYMATIKS_SENDER_ID"] ?? ""
            )
            options.apiKey = ProcessInfo.processInfo.environment["POLYMATIKS_EVENT_API_KEY"] ?? ""
            options.projectID = ProcessInfo.processInfo.environment["POLYMATIKS_PROJECT_ID"] ?? ""
            options.bundleID = Bundle.main.bundleIdentifier ?? ""

            FirebaseApp.configure(options: options)
        }

        return true
    }
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    //...
    id 'com.google.gms.google-services' version '4.4.2' apply false
    //...
}
plugins {
    //...
    id 'com.google.gms.google-services'
    //...
}

Authentication in the SDK is simple and integrated, but the process varies slightly depending on the platform. Below, you’ll find the details for setting up authentication in each supported environment.

--

--

Product Object

const product = {
    id: '123',
    name: 'ACME Anvil',
    price: 17.99,
    fromPrice: 19.99,
    polymatiksPrice: 15.99
}
import Foundation

struct Product: Codable {
    let id: String
    let name: String
    let price: Double
    let fromPrice: Double
    let polymatiksPrice: Double
}

let product = Product(
    id: "123",
    name: "ACME Anvil",
    price: 17.99,
    fromPrice: 19.99,
    polymatiksPrice: 15.99
)
import ai.polymatiks.analytics.Product

val product = Product(
    id = "123",
    name = "ACME Anvil",
    price = 17.99,
    fromPrice = 19.99,
    polymatiksPrice = 15.99
)

Field Type Required Description
id string true An unique ID that identifies the product
name string false A human-readable name for the product
price float true Product price displayed to the customer
fromPrice float false Product original price in a case of discount
polymatiksPrice float false Product price/discount given by Polymatiks

Initialize the SDK

import { initPolymatiksAnalytics } from '@polymatiks/react-analytics-sdk';

initPolymatiksAnalytics(customerId, cartId);
import PolymatiksAnalytics

PolymatiksAnalytics.initPolymatiksAnalytics(customerId: "", cartId: "")
import ai.polymatiks.analytics.PolymatiksAnalytics
import ai.polymatiks.analytics.Product

//Initiate your object also giving the Activity context as the first parameter
//Any following events should be triggered using the initiated object
val polymatiksAnalytics = PolymatiksAnalytics(context = this, customerId = '', cartId = '');

Before using the SDK, you need to initialize it.

Keep in mind that this initialization can be triggered everytime when the scenario changes. For example, an user can navigate anonymously (signed out), adding products to a cart and sign in in the middle of the process. So you can start a session without an customerId and update this session once the user sign in.

Parameters

Parameter Required Default Type Description
customerId false null string An ID that identifies the signed in user
cartId false null string An ID that identifies the session's cart

Product View Events

The Product Views Events are a set of analytics events designed to track how users interact with products across different contexts in your application. These events help you understand where and how users are discovering, exploring, and engaging with your products. By capturing these interactions, you can gain valuable insights into user behavior, optimize product placement, and improve the overall user experience.

View Product Page

import { viewProductPageEvent } from '@polymatiks/react-analytics-sdk';

viewProductPageEvent(product);
import PolymatiksAnalytics

PolymatiksAnalytics.viewProductPageEvent(product: Product)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.viewProductPageEvent(Product)

This event is triggered when a user lands on a dedicated product page, where they can view detailed information about the product, such as descriptions, images, pricing, and reviews.

This event is specific to the product page, where the user is likely to spend more time and engage deeply with the product.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product

View Product Home

import { viewProductHomeEvent } from '@polymatiks/react-analytics-sdk';

viewProductHomeEvent(product, position);
import PolymatiksAnalytics

PolymatiksAnalytics.viewProductHomeEvent(product: Product, position: 0)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.viewProductHomeEvent(Product, position = 1)

This event is triggered when a user views a product tile (a small preview of the product) on the home page, typically in a featured or recommended products section.

This event is specific to the home page, where products are often displayed in a condensed format to attract attention.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product
position false 0 integer An incremental number that identifies position when listing

View Product Category

import { viewProductCategoryEvent } from '@polymatiks/react-analytics-sdk';

viewProductCategoryEvent(product, categoryId, page, position);
import PolymatiksAnalytics

PolymatiksAnalytics.viewProductCategoryEvent(product: Product, categoryId: "", page: 0, position: 0)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.viewProductCategoryEvent(Product, categoryId = '', page = 1, position = 1)

This event is triggered when a user views a product tile on a category page, where products are grouped by type, brand, or other criteria.

This event is specific to category pages, where users are often comparing multiple products within the same category.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product
categoryId true - string An ID that identifies the category
page false 0 integer An incremental number that identifies page when paginated
position false 0 integer An incremental number that identifies position when listing
import { viewProductSearchEvent } from '@polymatiks/react-analytics-sdk';

viewProductSearchEvent(product, term, page, position);
import PolymatiksAnalytics

PolymatiksAnalytics.viewProductSearchEvent(product: Product, term: "", page: 0, position: 0)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.viewProductSearchEvent(Product, term = '', page = 1, position = 1)

This event is triggered when a user views a product tile on the search results page, typically after performing a search query.

This event is specific to the search page, where users are actively looking for products that match their query.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product
term true - string The text that customer searched for
page false 0 integer An incremental number that identifies page when paginated
position false 0 integer An incremental number that identifies position when listing

View Product Other

import { viewProductEvent } from '@polymatiks/react-analytics-sdk';

viewProductEvent(eventName, product, eventData);
// Not Available
// Not Available

This event is triggered when a user views a product in a context that doesn’t fit the above categories, such as in a popup, modal, recommendation widget, or email.

This event is a catch-all for product views that don’t occur on a standard page or tile.

Parameters

Parameter Required Default Type Description
eventName true - string A name that that identifies and group similar events
product true - Product An object that defines the product
eventData false null object A data object to feed the event with additional information

Cart Interaction Events

The Cart Interaction Events are a set of analytics events designed to track how users interact with products in their shopping cart. These events help you understand user behavior during the critical stages of the purchasing journey, such as adding, removing, or modifying products in the cart. By capturing these interactions, you can gain insights into cart abandonment, product preferences, and user intent, enabling you to optimize the checkout process and improve conversion rates.

Cart Add

import { addProductCartEvent } from '@polymatiks/react-analytics-sdk';

addProductCartEvent(product, amount);
import PolymatiksAnalytics

PolymatiksAnalytics.addProductCartEvent(product: Product, amount: 1)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.addProductCartEvent(Product, amount = 1)

This event is triggered when a user adds a product to their shopping cart. It indicates a strong intent to purchase and is a critical step in the conversion funnel.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product
amount false 1 integer The amount of this products that was added

Cart Remove

import { removeProductCartEvent } from '@polymatiks/react-analytics-sdk';

removeProductCartEvent(product);
import PolymatiksAnalytics

PolymatiksAnalytics.removeProductCartEvent(product: Product)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.removeProductCartEvent(Product)

This event is triggered when a user removes a product from their shopping cart. It helps identify why users abandon certain products before completing their purchase.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product

Cart Change

import { changeProductCartEvent } from '@polymatiks/react-analytics-sdk';

changeProductCartEvent(product, amount);
import PolymatiksAnalytics

PolymatiksAnalytics.changeProductCartEvent(product: Product, amount: 1)
import ai.polymatiks.analytics.Product

polymatiksAnalytics.changeProductCartEvent(Product, amount = 1)

This event is triggered when a user changes the quantity of a product in their cart, either by increasing or decreasing the amount. It provides insights into user preferences and purchasing behavior.

Parameters

Parameter Required Default Type Description
product true - Product An object that defines the product
amount true - integer The amount remaining of this products in that cart