Skip to content

Commit

Permalink
Update tracker to 4.0.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Oct 17, 2024
1 parent 152e96f commit 6b65e76
Show file tree
Hide file tree
Showing 8 changed files with 4,709 additions and 4,162 deletions.
598 changes: 34 additions & 564 deletions express/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@snowplow/node-tracker": "^3.5.0",
"@snowplow/node-tracker": "4.0.0-beta.2",
"dotenv": "^16.0.2",
"express": "^4.18.1"
},
Expand Down
8 changes: 6 additions & 2 deletions express/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ app.get("/", (req: Request, res: Response) => {
app.get("/order/complete/:transactionId", (req: Request, res: Response) => {
const { transactionId } = req.params;

const { eid: adConversionEid } = expressTracker.track(
const adConversionPayload = expressTracker.track(
buildAdConversion({
campaignId: "Transactional",
conversionId: transactionId,
})
);

const { eid: ecomTransactionEid } = expressTracker.track(
const adConversionEid = adConversionPayload ? adConversionPayload.eid : "undefined";

const ecomTransactionPayload = expressTracker.track(
buildEcommerceTransaction({
orderId: transactionId,
total: 10,
affiliation: "test store",
})
);

const ecomTransactionEid = ecomTransactionPayload ? ecomTransactionPayload.eid : "undefined";

res.send(
`Transaction ${transactionId} successful! Conversion Event Id: ${adConversionEid}. Transaction Event Id: ${ecomTransactionEid}`
);
Expand Down
37 changes: 19 additions & 18 deletions express/src/tracking/snowplow.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { tracker, gotEmitter, HttpProtocol, HttpMethod } from "@snowplow/node-tracker";
import { newTracker } from "@snowplow/node-tracker";

const emitter = gotEmitter(
"0.0.0.0",
HttpProtocol.HTTPS,
9090,
HttpMethod.POST,
1, // buffer size – 1 means that each event is sent right away, without buffering
5,
undefined,
function (error, response) {
// Callback called for each request
if (error) {
console.log(error, "Request error");
} else {
console.log("Event Sent");
}
export const expressTracker = newTracker(
{
namespace: "myTracker",
appId: "myApp",
encodeBase64: false,
},
{
customEmitter: () => ({
input: (payload) => {
return Promise.resolve();
},
flush: () => {
return Promise.resolve();
},
setCollectorUrl: (url) => {},
setAnonymousTracking: (anonymous) => {},
setBufferSize: (bufferSize) => {},
}),
}
);

export const expressTracker = tracker(emitter, "myTracker", "myApp", false);
10 changes: 5 additions & 5 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@snowplow/browser-plugin-form-tracking": "^3.14.0",
"@snowplow/browser-plugin-media": "^3.14.0",
"@snowplow/browser-plugin-vimeo-tracking": "3.14.0",
"@snowplow/browser-plugin-youtube-tracking": "^3.14.0",
"@snowplow/browser-tracker": "^3.14.0",
"@snowplow/browser-plugin-form-tracking": "4.0.0-beta.2",
"@snowplow/browser-plugin-media": "4.0.0-beta.2",
"@snowplow/browser-plugin-vimeo-tracking": "4.0.0-beta.2",
"@snowplow/browser-plugin-youtube-tracking": "4.0.0-beta.2",
"@snowplow/browser-tracker": "4.0.0-beta.2",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^13.5.0",
Expand Down
2 changes: 1 addition & 1 deletion react/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function handleDisableAnonymousTracking() {
function handleTrackStructuredEvent() {
trackStructEvent({
category: "category",
action: "action"
action: "action",
});
}

Expand Down
12 changes: 7 additions & 5 deletions react/src/routes/youtube.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { enableYouTubeTracking } from "@snowplow/browser-plugin-youtube-tracking";
import { startYouTubeTracking } from "@snowplow/browser-plugin-youtube-tracking";
import React, { useEffect } from "react";
import CreateTrackerWrapper from "../createTrackerWrapper";

function YoutubeTrack() {
const videoId = "youtube";

useEffect(() => {
enableYouTubeTracking({
id: videoId,
options: {
captureEvents: ["DefaultEvents", "error"],
startYouTubeTracking({
id: "youtube",
captureEvents: ["DefaultEvents", "error", "ping"],
video: videoId,
pings: {
pingInterval: 5,
},
});
}, []);
Expand Down
Loading

0 comments on commit 6b65e76

Please sign in to comment.