Skip to content

Commit 68ecbce

Browse files
committed
Core: add trackConsentWithdrawn method (close snowplow#630)
1 parent a56cdb7 commit 68ecbce

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

core/lib/core.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,45 @@ export function trackerCore(base64: boolean, callback?: (PayloadData) => void) {
878878
pageResults: pageResults
879879
})
880880
}, context, tstamp);
881+
},
882+
883+
/**
884+
* Track a consent withdrawn event
885+
*
886+
* @param {boolean} all - Indicates user withdraws consent for all documents.
887+
* @param {number} [id] - ID number associated with document.
888+
* @param {number} [version] - Version number of document.
889+
* @param {string} [name] - Name of document.
890+
* @param {string} [description] - Description of document.
891+
* @param {Array<SelfDescribingJson>} [context] - Context relating to the event.
892+
* @param {Timestamp} [tstamp] - TrackerTimestamp of the event.
893+
* @return Payload
894+
*/
895+
trackConsentWithdrawn: function(
896+
all: boolean,
897+
id?: number,
898+
version?: number,
899+
name?: string,
900+
description?: string,
901+
context?: Array<SelfDescribingJson>,
902+
tstamp?: Timestamp): PayloadData {
903+
904+
let documentJson = {
905+
schema: 'iglu:com.snowplowanalytics.snowplow/consent_document/jsonschema/1-0-0',
906+
data: removeEmptyProperties({
907+
id: id,
908+
version: version,
909+
name: name,
910+
description: description
911+
})
912+
};
913+
914+
return trackSelfDescribingEvent({
915+
schema: 'iglu:com.snowplowanalytics.snowplow/consent_withdrawn/jsonschema/1-0-0',
916+
data: removeEmptyProperties({
917+
all: all
918+
})
919+
}, documentJson.data && context ? context.concat([documentJson]) : context, tstamp);
881920
}
882921
};
883922
}

core/tests/unit/core.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,42 @@ define([
491491
compare(tracker.trackSiteSearch(terms, filters, totalResults, pageResults), expected);
492492
},
493493

494+
"Track a consent withdrawn event": function () {
495+
var all = false;
496+
var id = 1234;
497+
var version = 2;
498+
var name = "consent_form";
499+
var description = "user withdraws consent for form";
500+
var tstamp = 1000000000000;
501+
var inputContext = [{
502+
schema: 'iglu:com.snowplowanalytics.snowplow/consent_document/jsonschema/1-0-0',
503+
data: {
504+
id: id,
505+
version: version,
506+
name: name,
507+
description: description
508+
}
509+
}];
510+
var inputJson = {
511+
schema: 'iglu:com.snowplowanalytics.snowplow/consent_withdrawn/jsonschema/1-0-0',
512+
data: {
513+
all: all
514+
}
515+
};
516+
var expected = {
517+
e: 'ue',
518+
ue_pr: JSON.stringify({
519+
schema: unstructEventSchema,
520+
data: inputJson
521+
}),
522+
co: JSON.stringify({
523+
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0',
524+
data: inputContext
525+
})
526+
};
527+
compare(tracker.trackConsentWithdrawn(all, id, version, name, description, [], tstamp), expected);
528+
},
529+
494530
"Track a page view with custom context": function () {
495531
var url = 'http://www.example.com';
496532
var page = 'title page';

0 commit comments

Comments
 (0)