Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add Reusable PR Workflow #13

Merged
merged 9 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"before": true,
"beforeEach": true,
"after": true,
"Leanplum": true
"heap": true
},
"extends": ["plugin:prettier/recommended", "eslint:recommended"],
"plugins": ["prettier"],
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/pull-request.yml

This file was deleted.

23 changes: 13 additions & 10 deletions .github/workflows/reusable-workflows.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
name: Reusable Workflows

on:
pull_request:
pull_request:

jobs:
pr-branch-check-name:
name: Check PR for semantic branch name
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-check-name.yml@stable
pr-title-check:
name: Check PR for semantic title
uses: mParticle/mparticle-workflows/.github/workflows/pr-title-check.yml@stable
pr-branch-target-gitflow:
name: Check PR for semantic target branch
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-target-gitflow.yml@stable
web-kit-pull-request:
name: Run Web Kit PR Workflow
uses: mParticle/mparticle-workflows/.github/workflows/web-kit-pull-request.yml@stable
pr-branch-check-name:
name: Check PR for semantic branch name
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-check-name.yml@stable
pr-title-check:
name: Check PR for semantic title
uses: mParticle/mparticle-workflows/.github/workflows/pr-title-check.yml@stable
pr-branch-target-gitflow:
name: Check PR for semantic target branch
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-target-gitflow.yml@stable
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"scripts": {
"build": "ENVIRONMENT=production rollup --config rollup.config.js",
"build:test": "rollup --config rollup.test.config.js",
"lint": "eslint src/ test/src/",
"lint:fix": "eslint src/ test/src/ --fix",
"watch": "ENVIRONMENT=production rollup --config rollup.config.js -w",
"test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
"test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js",
Expand Down
133 changes: 74 additions & 59 deletions src/commerce-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,56 @@ var ProductActionTypes = {
Refund: 17,
RemoveFromCart: 11,
ViewDetail: 15,
}
};

var ProductActionNames = {
0: "Unknown",
1: "Add To Cart",
2: "Remove From Cart",
3: "Checkout",
4: "Checkout Option",
5: "Click",
6: "View Detail",
7: "Purchase",
8: "Refund",
9: "Add To Wishlist",
10: "Remove From Wishlist",
}
0: 'Unknown',
1: 'Add To Cart',
2: 'Remove From Cart',
3: 'Checkout',
4: 'Checkout Option',
5: 'Click',
6: 'View Detail',
7: 'Purchase',
8: 'Refund',
9: 'Add To Wishlist',
10: 'Remove From Wishlist',
};

var PromotionType = {
PromotionClick: 19,
PromotionView: 18,
}
};

var PromotionTypeNames = {
19: "Click",
18: "View",
}
19: 'Click',
18: 'View',
};
var HeapConstants = {
EventNameItem: "Item",
EventNameProductAction: "Product Action Event",
EventNameProductActionPart: "Product Action: ",
EventNamePromotionPart: "Promotion: ",
EventNameImpression: "Impression Event",
EventNameItem: 'Item',
EventNameProductAction: 'Product Action Event',
EventNameProductActionPart: 'Product Action: ',
EventNamePromotionPart: 'Promotion: ',
EventNameImpression: 'Impression Event',
MaxPropertyLength: 1023,
KeyProductName: "product_name",
KeyProductPrice: "product_price",
KeyProductQuantity: "product_quantity",
KeyProductTotalProductAmount: "total_product_amount",
KeyProductSku: "product_id",
KeyProductBrand: "product_brand",
KeyProductCategory: "product_category",
KeyProductSkus: "skus",
KeyPromotionCreative: "creative",
KeyPromotionId: "id",
KeyPromotionPosition: "position",
}
KeyProductName: 'product_name',
KeyProductPrice: 'product_price',
KeyProductQuantity: 'product_quantity',
KeyProductTotalProductAmount: 'total_product_amount',
KeyProductSku: 'product_id',
KeyProductBrand: 'product_brand',
KeyProductCategory: 'product_category',
KeyProductSkus: 'skus',
KeyPromotionCreative: 'creative',
KeyPromotionId: 'id',
KeyPromotionPosition: 'position',
};

function CommerceHandler(common) {
this.common = common || {};
}

CommerceHandler.prototype.logCommerceEvent = function(event) {
CommerceHandler.prototype.logCommerceEvent = function (event) {
/*
Sample ecommerce event schema:
{
Expand Down Expand Up @@ -128,11 +128,10 @@ CommerceHandler.prototype.logCommerceEvent = function(event) {
break;
default:
events = buildProductActionEvents(event);
};
}

for (var i = 0; i < events.length; i++) {
var event = events[i];
window.heap.track(event.Name, event.Properties);
window.heap.track(events[i].Name, events[i].Properties);
}
};

Expand All @@ -144,23 +143,28 @@ function buildImpressionEvents(event) {
var impression = event.ProductImpressions[i];
var productSkus = [];
if (impression.ProductList.length > 0) {
for(var j = 0; j < impression.ProductList.length; j++) {
for (var j = 0; j < impression.ProductList.length; j++) {
var product = impression.ProductList[j];
var eventObject = buildItemEvent(product);
events.push(eventObject.event);
if(eventObject.sku) {
if (eventObject.sku) {
productSkus.push(eventObject.sku);
}
}
}

events.push(buildActionEvent(event, HeapConstants.EventNameImpression, productSkus))
events.push(
buildActionEvent(
event,
HeapConstants.EventNameImpression,
productSkus
)
);
}
}


return events;
};
}

function buildPromotionEvents(event) {
var events = [];
Expand All @@ -171,13 +175,17 @@ function buildPromotionEvents(event) {
var eventObject = buildPromotionItemEvent(promotion);
events.push(eventObject.event);

if(eventObject.id) {
if (eventObject.id) {
promotionIds.push(eventObject.id);
}
}
}
var promotionActionEventName = HeapConstants.EventNamePromotionPart + PromotionTypeNames[event.EventCategory];
events.push(buildActionEvent(event, promotionActionEventName, promotionIds));
var promotionActionEventName =
HeapConstants.EventNamePromotionPart +
PromotionTypeNames[event.EventCategory];
events.push(
buildActionEvent(event, promotionActionEventName, promotionIds)
);
return events;
}

Expand All @@ -202,8 +210,10 @@ function buildProductActionEvents(event) {
if (!event.ProductAction) {
actionEventName = HeapConstants.EventNameProductAction;
} else {
var productActionKey = ProductActionNames[event.ProductAction.ProductActionType];
actionEventName = HeapConstants.EventNameProductActionPart + productActionKey;
var productActionKey =
ProductActionNames[event.ProductAction.ProductActionType];
actionEventName =
HeapConstants.EventNameProductActionPart + productActionKey;
}

events.push(buildActionEvent(event, actionEventName, productSkus));
Expand All @@ -212,9 +222,10 @@ function buildProductActionEvents(event) {
}

function buildActionEvent(event, eventName, productSkus) {
var properties = event && event.EventAttributes ? event.EventAttributes : {};
var properties =
event && event.EventAttributes ? event.EventAttributes : {};
properties[HeapConstants.KeyProductSkus] = productSkus;
return {Name: eventName, Properties: properties};
return { Name: eventName, Properties: properties };
}

function buildItemEvent(product) {
Expand All @@ -236,9 +247,12 @@ function buildItemEvent(product) {
properties[HeapConstants.KeyProductQuantity] = validatedQuantity;
}

var validatedTotalProductAmount = validateHeapPropertyValue(product.TotalProductAmount);
var validatedTotalProductAmount = validateHeapPropertyValue(
product.TotalProductAmount
);
if (validatedTotalProductAmount) {
properties[HeapConstants.KeyProductTotalProductAmount] = validatedTotalProductAmount;
properties[HeapConstants.KeyProductTotalProductAmount] =
validatedTotalProductAmount;
}

var validatedSku = validateHeapPropertyValue(product.Sku);
Expand All @@ -259,18 +273,19 @@ function buildItemEvent(product) {
event.Name = HeapConstants.EventNameItem;
event.Properties = properties;

return {event: event, sku: validatedSku};
return { event: event, sku: validatedSku };
}

function buildPromotionItemEvent(promotion) {
var event = {};
var properties = promotion && promotion.Attributes ? promotion.Attributes : {};
var properties =
promotion && promotion.Attributes ? promotion.Attributes : {};

var validatedPromotionValues = {
KeyPromotionCreative: validateHeapPropertyValue(promotion.Creative),
KeyPromotionId: validateHeapPropertyValue(promotion.Id),
KeyPromotionPosition: validateHeapPropertyValue(promotion.Position),
}
};

var validatedPromotionKeys = Object.keys(validatedPromotionValues);
for (var i = 0; i < validatedPromotionKeys.length; i++) {
Expand All @@ -286,17 +301,17 @@ function buildPromotionItemEvent(promotion) {
event.Properties = properties;
var promotionId = validatedPromotionValues.KeyPromotionId;

return {event: event, id: promotionId};
return { event: event, id: promotionId };
}

function validateHeapPropertyValue(value){
if (typeof value === "boolean" || typeof value === "number") {
function validateHeapPropertyValue(value) {
if (typeof value === 'boolean' || typeof value === 'number') {
return value;
}

if (value === undefined || value === null) {
return value;
} else if (value.length > HeapConstants.MaxPropertyLength){
} else if (value.length > HeapConstants.MaxPropertyLength) {
return value.substring(0, HeapConstants.MaxPropertyLength);
} else {
return value;
Expand Down
4 changes: 2 additions & 2 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ function Common() {}

Common.prototype.exampleMethod = function () {
return 'I am an example';
}
};

module.exports = Common;
module.exports = Common;
28 changes: 15 additions & 13 deletions src/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@ A non-ecommerce event has the following schema:
function EventHandler(common) {
this.common = common || {};
}
EventHandler.prototype.logEvent = function(event) {
var ignoredEvents = [
'click',
'change',
'submit'
];
EventHandler.prototype.logEvent = function (event) {
var ignoredEvents = ['click', 'change', 'submit'];

if (ignoredEvents.includes(event.EventName.toLowerCase())) {
return;
}

window.heap.track(event.EventName, event.EventAttributes);
};
EventHandler.prototype.logError = function(event) {

// This is used by the SDK Wrapper even if it is not used in an extended kit.
// eslint-disable-next-line no-unused-vars
EventHandler.prototype.logError = function (event) {
// The schema for a logError event is the same, but noteworthy differences are as follows:
// {
// EventAttributes: {m: 'name of error passed into MP', s: "Error", t: 'stack trace in string form if applicable'},
// EventName: "Error"
// }
};
EventHandler.prototype.logPageView = function(event) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe this will cause an error in the wrapper. https://github.com/mparticle-integrations/mparticle-javascript-web-kit-wrapper/blob/master/index.js#L160-L190

This doesn't check for the existence before calling.

So @SbDove - there are no page views in heap?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i'd put it back

/* The schema for a logPagView event is the same, but noteworthy differences are as follows:
{
EventAttributes: {hostname: "www.google.com", title: 'Test Page'}, // These are event attributes only if no additional event attributes are explicitly provided to mParticle.logPageView(...)
}
*/

// This is used by the SDK Wrapper even if it is not used in an extended kit.
// eslint-disable-next-line no-unused-vars
EventHandler.prototype.logPageView = function (event) {
// The schema for a logPagView event is the same, but noteworthy differences are as follows:
// {
// EventAttributes: {hostname: "www.google.com", title: 'Test Page'}, // These are event attributes only if no additional event attributes are explicitly provided to mParticle.logPageView(...)
// }
//
};

module.exports = EventHandler;
Loading