Track only GA events using Node.js tracker

Hello,
I’m trying to track all the GA events, using the node.js tracker which I have implemented in the GCP cloud function.

  1. Initially for testing I use snowplow mini for this, where the URL http://MINI_URL//iglu-server/api/schemas does not have any schema set.
  2. By logging in the snowplow mini, I could find webapp called Swagger an IGLU server API where we can set, get and post any custom or self describing SCHEMA.

Here is my tracking code:

/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */
// const snowplow = require('@snowplow/node-tracker');
import snowplow from "@snowplow/node-tracker"
var gotEmitter = snowplow.gotEmitter;
var tracker = snowplow.tracker;
var buildPageView = snowplow.buildPageView;
var buildStructEvent = snowplow.buildStructEvent;
var buildSelfDescribingEvent = snowplow.buildSelfDescribingEvent;

const e = gotEmitter(
        'com.snowplow-mini-url', // Endpoint
        snowplow.HttpProtocol.HTTPS, // Protocol
        443, // Port
        snowplow.HttpMethod.POST, // Method
        1, // Buffer Size
        5, // Retries
        undefined,
        function (error, response) { // Callback called for each request
            if (error) {
                console.log(error, 'Request error');
                rej(error)
            } else {
                console.log('Event Sent'.response.statusCode);
                res(response)
            }
        },
    )

   const t = tracker([e], 'myTracker', 'myApp', false);
    t.setUserId('alexd');
    t.setPlatform('platform');
    t.setDomainUserId('domainUserId');
    t.setNetworkUserId('userID');
    t.setLang('en');
    t.setScreenResolution(375, 812);;
    t.setColorDepth(24);
    t.setTimezone('Asia/Kuala_Lumpur');

export const ss_test = (request,response) => {
    t.track(buildStructEvent({          
        category: "shop",
        action: "add-to-basket",
        label: "product",
        property: "pcs",
        value: 2
    }));

    t.track(buildSelfDescribingEvent({ 
        event: {
            schema: "iglu:com.snowplow..self-desc/schema/jsonschema/1-0-0",
            data: {
                save_id: "4321",
                level: 23,
                difficultyLevel: "HARD",
                dl_content: true
            }
        }
    }));

    t.track(buildPageView({    
        pageUrl: 'http://www.example.com',
        referrer: 'http://www.referer.com'
    }),
        [{
            "schema": "iglu:com.acme_company/example/jsonschema/2-1-1",
            "data": {
                "data": "foo",
                "date": "2022-01-01"
            }
        }]);
  response.send()
};

I got stuck in here, whether to track GA events I have to change the tracker code or just to set the schema in IGLU server API or is there is any other ways to do that ?

Hi @Shalini_Balakrishnan,

Not sure what you mean by GA events – could you elaborate on that?

In order to track self-describing events with custom schemas or any events with context entities with custom schemas, you will need to do 2 things:

  1. Upload the custom schema to your Iglu server in your Mini as you already mentioned.
  2. Make sure to refer to the schema when you are tracking events in your tracking code.

I can see in your tracking code that you are referring to non-existent schemas in two places:

t.track(buildSelfDescribingEvent({ 
        event: {
 // HERE you need to make sure to refer to a valid schema URI for the given data:
            schema: "iglu:com.snowplow..self-desc/schema/jsonschema/1-0-0",
            data: {
                save_id: "4321",
                level: 23,
                difficultyLevel: "HARD",
                dl_content: true
            }
        }
    }));

    t.track(buildPageView({    
        pageUrl: 'http://www.example.com',
        referrer: 'http://www.referer.com'
    }),
        [{
// HERE you need to make sure to refer to a valid schema URI for the given data:
            "schema": "iglu:com.acme_company/example/jsonschema/2-1-1",
            "data": {
                "data": "foo",
                "date": "2022-01-01"
            }
        }]);

Otherwise the events will fail validation and end up in the “bad events” queue.