15.2.4.1 Typescript Example

import { 
	GalEnvironment, // environment enum
	GalEvents, // events enum
	GalReportingGroups, // reporting group enum
	GalaAnalytics, // Core SDK class
	GameplayBeginDTO, // Specific DTO type 
	MilestoneDTO // Specific DTO type
} from '@gala-analytics/core';


// Create an instance of GalaAnalytics for use
// In order to maintain session parity, use one instance of GalaAnalytics
// per user session
const analytics = new GalaAnalytics({
    // publisherId provided by Core Tech Data team (test id shown)
    publisherId: 'Ht3QOWhvthSZjamSOorRldkzgP7l4XbE',
    publisherGroup: GalReportingGroups.product,
    // Recommend storing url in environment
    reportingUri: '<https://alpha-data.gala.com/>',
    // Gala user id if known upon instantiation
    // can be set later
    user: 'galaUserId1234',
    // set this per deployment environment
    environment: GalEnvironment.test
});


// take care to normalize event data wherever possible
const GAME_NAME_IDENTIFIER = 'pokergo';


// example async wrapper boilerplate
const sendTestEvents = async () => {


		try {
		    // passing the DTO to the method via generics e.g. report<GameplayBeginDTO>(... is optional
		    // but doing so will give you type hints in the IDE making it easier to ensure the DTO is valid
		    await analytics.report<GameplayBeginDTO>({
		        type: GalEvents.GameplayBeginDTO,
		        game: GAME_NAME_IDENTIFIER
		    });
		
		    await analytics.report<MilestoneDTO>({
		        type: GalEvents.MilestoneDTO,
		        name: 'testSuccessful',
		        stepNumber: 1,
		        timeTaken: 10232
		    });
		} catch(err) {
		   // handle errors
		}


}


// boilerplate for example purposes
(async () => {
    await sendTestEvents();
})();
undefined