Skip to main content

Google Tag Manager Integration - LoraStream Analytics Usage Guide

info

The LoraStreamAnalytics class is a utility for tracking events and analytics related to LORA application. This guide will walk you through how to set up and use this class effectively.

Initialization

To get started with LoraStreamAnalytics, you need to initialize an instance of the class. Here's an example of how to do this:

Step 1: Log in to LORA CMS

  • Enter your credentials (username and password) to log in to LORA CMS account.

Step 2: Access the Help Center Page

  • Look for the navigation menu or toolbar. Locate and click on the "Help Center" option.

Step 3: Copy the Google Tag Manager Script

  • Click on the Copy button under Google Tag Manager to copy Script

Step 4: Paste the Script in the HTML Code

  • Pass the script in the <head> tag in your HTML where you want to add the Google Tag Manager script
Example code:
<head>
// Your HTML code .... // Paste the script
<script src="https://lora-sdk.belive.sg/la/lora-analytics.js?orgid=YOUR_ORG_ID" type="text/javascript"></script>
</head>

Step 5: Initial an instance of the class

Example code:
<script>
const liveStreamAnalytics = new window.BeliveShortVideoSdk.LoraStreamAnalytics(YOUR_GTM_CONTAINER_ID); // YOUR_GTM_CONTAINER_ID: if null it will be
LORA GTM
</script>

Tracking Events

The LoraStreamAnalytics class provides several methods for tracking common events:

  1. trackingViewItem
  2. trackingAddToCart
  3. trackingDecreaseFromCart
  4. trackingRemoveFromCart
  5. trackingCheckout
  6. trackingPurchaseSuccess
  7. trackingPurchaseFailed

Tracking view item

trackingViewItem(products, price, currency, data)

info

Track when a user view an item

Parameters:
ContentDescriptionType
productsAn array of products added to the cart.array
priceThe total price of the items added.number
currencyThe currency in which the price is denominated.string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";

const eventData = {
cart_id: "Cart123",
};

liveStreamAnalytics.trackingViewItem(products, price, currency, eventData);

Tracking add to cart

trackingAddToCart(products, price, currency, data)

info

Track when a user adds items to their cart with this method.

Parameters:
ContentDescriptionType
productsAn array of products added to the cart.array
priceThe total price of the items added.number
currencyThe currency in which the price is denominated.string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";

const eventData = {
cart_id: "Cart123",
};

liveStreamAnalytics.trackingAddToCart(products, price, currency, eventData);

Tracking decrease item from cart

trackingDecreaseFromCart(products, price, currency, data)

info

Track when a user decreases items from their cart with this method.

Parameters:
ContentDescriptionType
productsAn array of products added to the cart.array
priceThe total price of the items added.number
currencyThe currency in which the price is denominated.string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";

const eventData = {
cart_id: "Cart123",
};

liveStreamAnalytics.trackingDecreaseFromCart(products, price, currency, eventData);

Tracking remove from cart

trackingRemoveFromCart(products, price, currency, data)

info

Track when a user remove item from their cart with this method.

Parameters:
ContentDescriptionType
productsAn array of products added to the cart.array
priceThe total price of the items added.number
currencyThe currency in which the price is denominated.string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";

const eventData = {
cart_id: "Cart123",
};

liveStreamAnalytics.trackingRemoveFromCart(products, price, currency, eventData);

Tracking check out

trackingCheckout(products, price, currency, coupon, data)

info

Track when a user initiates the checkout process.

Parameters:
ContentDescriptionType
productsAn array of products in the cart during checkout.array
priceThe total price of the items in the cart.number
currencyThe currency in which the price is denominated.string
couponThe coupon code applied during checkout.string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";
const coupon = "SAVE10";

const eventData = {
cart_id: "Cart123",
};

liveStreamAnalytics.trackingCheckout(products, price, currency, coupon, eventData);

Tracking purchase success

trackingPurchaseSuccess(products, price, currency, transactionId, coupon, shipping, tax, data)

info

Track a successful purchase event.

Parameters:
ContentDescriptionType
productsAn array of products included in the purchase.array
priceThe total purchase price.number
currencyThe currency in which the price is denominated.string
transactionIdThe unique identifier of a transaction.string
couponThe coupon code used for the purchase (if applicable).number | string
shippingThe shipping info (if applicable).number | string
taxTax info (if applicable).number | string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";
const coupon = "SAVE10";
const shipping = 10;
const tax = 12;
const transactionId = "TRSID1234";

const eventData = {
order_id: "Order123",
};

liveStreamAnalytics.trackingPurchaseSuccess(products, price, currency, transactionId, coupon, shipping, tax, eventData);

Tracking purchase failed

trackingPurchaseFailed(products, price, currency, transactionId, coupon, shipping, tax, data)

info

Track a failed purchase event.

Parameters:
ContentDescriptionType
productsAn array of products in the failed purchase.array
priceThe total price of the items in the cart during the failed purchase.number
currencyThe currency in which the price is denominated.string
transactionIdThe unique identifier of a transaction.string
couponThe coupon code attempted during the failed purchase.number | string
shippingThe shipping info (if applicable).number | string
taxTax info (if applicable).number | string
custom_dataAdditional event-specific data.object
Example code:
const products = [
{
item_id: "XYZ789",
item_name: "Product 1",
index: 0,
price: 50,
quantity: 2,
},
{
item_id: "DEF456",
item_name: "Product 2",
index: 1,
price: 100,
quantity: 1,
},
];

const price = 150;
const currency = "USD";
const coupon = "INVALIDCOUPON";
const shipping = 10;
const tax = 12;
const transactionId = "TRSID1234";

const eventData = {
cart_id: "Cart123",
};

liveStreamAnalytics.trackingPurchaseFailed(products, price, currency, transactionId, coupon, shipping, tax, eventData);