|
97 | 97 | configDefaultVendor = 'com.snowplowanalytics',
|
98 | 98 |
|
99 | 99 | // The schema against which custom context arrays should be validated
|
100 |
| - configContextSchema = "com.snowplowanalytics/contexts/1.0.0", |
| 100 | + configContextSchema = 'com.snowplowanalytics/contexts/json/1-0-0', |
| 101 | + |
| 102 | + // The schema against which unstructured event envelopes should be validated |
| 103 | + configUnstructEventSchema = 'com.snowplowanalytics/unstruct_event/json/1-0-0', |
101 | 104 |
|
102 | 105 | // Platform defaults to web for this tracker
|
103 | 106 | configPlatform = argmap.hasOwnProperty('platform') ? argmap.platform : 'web',
|
|
673 | 676 | /**
|
674 | 677 | * Log an unstructured event happening on this page
|
675 | 678 | *
|
676 |
| - * @param string name The name of the event |
677 |
| - * @param object properties The properties of the event |
678 |
| - * @param string eventVendor The author of the event |
| 679 | + * @param object eventJson Contains the properties and schema location for the event |
679 | 680 | * @param object context Custom context relating to the event
|
680 | 681 | */
|
681 |
| - function logUnstructEvent(eventVendor, name, properties, context) { |
682 |
| - var sb = payload.payloadBuilder(configEncodeBase64); |
683 |
| - sb.add('e', 'ue'); // 'ue' for Unstructured Event |
684 |
| - sb.add('ue_na', name); |
685 |
| - sb.addJson('ue_px', 'ue_pr', properties); |
686 |
| - sb.addJson('cx', 'co', completeContext(context)); |
687 |
| - sb.add('evn', eventVendor); |
688 |
| - var request = getRequest(sb); |
689 |
| - sendRequest(request, configTrackerPause); |
| 682 | + function logUnstructEvent(eventJson, context) { |
| 683 | + helpers.deleteEmptyProperties(eventJson.data); |
| 684 | + if (!lodash.isEmpty(eventJson.data)) { |
| 685 | + var envelope = { |
| 686 | + schema: configUnstructEventSchema, |
| 687 | + data: eventJson |
| 688 | + }, |
| 689 | + sb = payload.payloadBuilder(configEncodeBase64); |
| 690 | + sb.add('e', 'ue'); // 'ue' for Unstructured Event |
| 691 | + sb.addJson('ue_px', 'ue_pr', envelope); |
| 692 | + sb.addJson('cx', 'co', completeContext(context)); |
| 693 | + var request = getRequest(sb); |
| 694 | + sendRequest(request, configTrackerPause); |
| 695 | + } |
690 | 696 | }
|
691 | 697 |
|
692 | 698 | /**
|
|
768 | 774 | // TODO: this functionality is not yet fully implemented.
|
769 | 775 | // See https://github.com/snowplow/snowplow/issues/75
|
770 | 776 | function logLink(targetUrl, elementId, elementClasses, elementTarget, context) {
|
771 |
| - var linkClickJson = { |
772 |
| - targetUrl: targetUrl, |
773 |
| - elementId: elementId, |
774 |
| - elementClasses: elementClasses, |
775 |
| - elementTarget: elementTarget |
| 777 | + var eventJson = { |
| 778 | + schema: configDefaultVendor + '/link_click/json/1-0-0', |
| 779 | + data: { |
| 780 | + targetUrl: targetUrl, |
| 781 | + elementId: elementId, |
| 782 | + elementClasses: elementClasses, |
| 783 | + elementTarget: elementTarget |
| 784 | + }, |
776 | 785 | };
|
777 | 786 |
|
778 |
| - logUnstructEvent(configDefaultVendor, 'link_click', helpers.deleteEmptyProperties(linkClickJson), context); |
| 787 | + logUnstructEvent(eventJson, context); |
779 | 788 | }
|
780 | 789 |
|
781 | 790 | /**
|
|
1355 | 1364 | /**
|
1356 | 1365 | * Track an unstructured event happening on this page.
|
1357 | 1366 | *
|
1358 |
| - * @param string eventVendor The author of the event |
1359 |
| - * @param string name The name of the event |
1360 |
| - * @param object properties The properties of the event |
1361 |
| - * @param object Custom context relating to the event |
| 1367 | + * @param object eventJson Contains the properties and schema location for the event |
| 1368 | + * @param object context Custom context relating to the event |
1362 | 1369 | */
|
1363 |
| - trackUnstructEvent: function (eventVendor, name, properties, context) { |
1364 |
| - logUnstructEvent(eventVendor, name, properties, context); |
| 1370 | + trackUnstructEvent: function (eventJson, context) { |
| 1371 | + logUnstructEvent(eventJson, context); |
1365 | 1372 | },
|
1366 | 1373 |
|
1367 | 1374 | /**
|
|
1504 | 1511 | */
|
1505 | 1512 | trackAdImpression: function(impressionId, costModel, cost, targetUrl, bannerId, zoneId, advertiserId, campaignId, context) {
|
1506 | 1513 | trackCallback(function () {
|
1507 |
| - var adImpressionJson = { |
1508 |
| - impressionId: impressionId, |
1509 |
| - costModel: costModel, |
1510 |
| - cost: cost, |
1511 |
| - bannerId: bannerId, |
1512 |
| - targetUrl: targetUrl, |
1513 |
| - zoneId: zoneId, |
1514 |
| - advertiserId: advertiserId, |
1515 |
| - campaignId: campaignId |
| 1514 | + var eventJson = { |
| 1515 | + schema: configDefaultVendor + '/ad_impression/json/1-0-0', |
| 1516 | + data: { |
| 1517 | + impressionId: impressionId, |
| 1518 | + costModel: costModel, |
| 1519 | + cost: cost, |
| 1520 | + bannerId: bannerId, |
| 1521 | + targetUrl: targetUrl, |
| 1522 | + zoneId: zoneId, |
| 1523 | + advertiserId: advertiserId, |
| 1524 | + campaignId: campaignId |
| 1525 | + } |
1516 | 1526 | };
|
1517 | 1527 |
|
1518 |
| - logUnstructEvent(configDefaultVendor, 'ad_impression', helpers.deleteEmptyProperties(adImpressionJson), context); |
| 1528 | + logUnstructEvent(eventJson, context); |
1519 | 1529 | });
|
1520 | 1530 | },
|
1521 | 1531 |
|
|
1534 | 1544 | * @param object Custom context relating to the event
|
1535 | 1545 | */
|
1536 | 1546 | trackAdClick: function(targetUrl, clickId, costModel, cost, bannerId, zoneId, impressionId, advertiserId, campaignId, context) {
|
1537 |
| - var adClickJson = { |
1538 |
| - targetUrl: targetUrl, |
1539 |
| - clickId: clickId, |
1540 |
| - costModel: costModel, |
1541 |
| - cost: cost, |
1542 |
| - bannerId: bannerId, |
1543 |
| - zoneId: zoneId, |
1544 |
| - impressionId: impressionId, |
1545 |
| - advertiserId: advertiserId, |
1546 |
| - campaignId: campaignId |
| 1547 | + var eventJson = { |
| 1548 | + schema: configDefaultVendor + '/ad_click/json/1-0-0', |
| 1549 | + data: { |
| 1550 | + targetUrl: targetUrl, |
| 1551 | + clickId: clickId, |
| 1552 | + costModel: costModel, |
| 1553 | + cost: cost, |
| 1554 | + bannerId: bannerId, |
| 1555 | + zoneId: zoneId, |
| 1556 | + impressionId: impressionId, |
| 1557 | + advertiserId: advertiserId, |
| 1558 | + campaignId: campaignId |
| 1559 | + } |
1547 | 1560 | };
|
1548 | 1561 |
|
1549 |
| - logUnstructEvent(configDefaultVendor, 'ad_click', helpers.deleteEmptyProperties(adClickJson), context); |
| 1562 | + logUnstructEvent(eventJson, context); |
1550 | 1563 | },
|
1551 | 1564 |
|
1552 | 1565 | /**
|
|
1564 | 1577 | * @param object Custom context relating to the event
|
1565 | 1578 | */
|
1566 | 1579 | trackAdConversion: function(conversionId, costModel, cost, category, action, property, initialValue, advertiserId, campaignId, context) {
|
1567 |
| - var adConversionJson = { |
1568 |
| - conversionId: conversionId, |
1569 |
| - costModel: costModel, |
1570 |
| - cost: cost, |
1571 |
| - category: category, |
1572 |
| - action: action, |
1573 |
| - property: property, |
1574 |
| - initialValue: initialValue, |
1575 |
| - advertiserId: advertiserId, |
1576 |
| - campaignId: campaignId |
| 1580 | + var eventJson = { |
| 1581 | + schema: configDefaultVendor + '/ad_conversion/json/1-0-0', |
| 1582 | + data: { |
| 1583 | + conversionId: conversionId, |
| 1584 | + costModel: costModel, |
| 1585 | + cost: cost, |
| 1586 | + category: category, |
| 1587 | + action: action, |
| 1588 | + property: property, |
| 1589 | + initialValue: initialValue, |
| 1590 | + advertiserId: advertiserId, |
| 1591 | + campaignId: campaignId |
| 1592 | + } |
1577 | 1593 | };
|
1578 | 1594 |
|
1579 |
| - logUnstructEvent(configDefaultVendor, 'ad_conversion', helpers.deleteEmptyProperties(adConversionJson), context); |
| 1595 | + logUnstructEvent(eventJson, context); |
1580 | 1596 | }
|
1581 | 1597 | }
|
1582 | 1598 | }
|
|
0 commit comments