Skip to content

Commit

Permalink
3901: Use constants for webtrekk parameter IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
holt83 committed Dec 17, 2018
1 parent e2d33ab commit 9847587
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
29 changes: 23 additions & 6 deletions modules/ding_webtrekk/ding_webtrekk.js
Expand Up @@ -13,6 +13,14 @@

"use strict";

// Webtrekk tracking parameters.
var DING_WEBTREKK_PARAMETER_AUTOCOMPLETE = 54;
var DING_WEBTREKK_PARAMETER_RENEW_SELECTED = 55;
var DING_WEBTREKK_PARAMETER_RENEW_RATING_ID = 57;
var DING_WEBTREKK_PARAMETER_RENEW_RATING = 58;
var DING_WEBTREKK_PARAMETER_CAROUSEL_NEXT = 59;
var DING_WEBTREKK_PARAMETER_CAROUSEL_PREV = 60;

var appendQueryParameter = function(url, key, value) {
var seperator = (url.indexOf('?') !== -1) ? '&' : '?';
var urlParameter = key + '=' + encodeURIComponent(value);
Expand Down Expand Up @@ -41,8 +49,8 @@
wts.push(['send', 'click', {
linkId: 'Materiale rating',
customClickParameter: {
58: rating,
57: contentId
DING_WEBTREKK_PARAMETER_RENEW_RATING: rating,
DING_WEBTREKK_PARAMETER_RENEW_RATING_ID: contentId
}
}]);
});
Expand All @@ -54,9 +62,12 @@
.once('js-ding-webtrekk')
.on('autocompleteSelect', function(e, selected) {
if (($(selected).text())) {
console.log($(selected).text());
wts.push(['send', 'click', {
linkId: 'Autocomplete søgning clicks',
customClickParameter: { 54: $(selected).text() }
customClickParameter: {
DING_WEBTREKK_PARAMETER_AUTOCOMPLETE: $(selected).text()
}
}]);
}
});
Expand Down Expand Up @@ -84,7 +95,9 @@
});
wts.push(['send', 'click', {
linkId: 'Forny valgte materialer',
customClickParameter: { 55: selectedMaterials.join(';') }
customClickParameter: {
DING_WEBTREKK_PARAMETER_RENEW_SELECTED: selectedMaterials.join(';')
}
}]);
});

Expand Down Expand Up @@ -119,10 +132,14 @@

$('.slick-arrow', this).once('js-ding-webtrekk').click(function() {
var linkId = 'Karousel, click på forrige knappen';
var customClickParameter = { 60: carouselTitle };
var customClickParameter = {
DING_WEBTREKK_PARAMETER_CAROUSEL_PREV: carouselTitle
};
if ($(this).hasClass('slick-next')) {
linkId = 'Karousel, click på næste knappen';
customClickParameter = { 59: carouselTitle };
customClickParameter = {
DING_WEBTREKK_PARAMETER_CAROUSEL_NEXT: carouselTitle
};
}
wts.push(['send', 'click', {
linkId: linkId,
Expand Down
11 changes: 8 additions & 3 deletions modules/ding_webtrekk/ding_webtrekk.module
Expand Up @@ -4,6 +4,11 @@
* Include basic hooks for the module functionality.
*/

// Constants for Webtrekk tracking parameters.
define('DING_WEBTREKK_PARAMETER_RESERVE', 50);
define('DING_WEBTREKK_PARAMETER_SEE_ONLINE', 51);
define('DING_WEBTREKK_PARAMETER_RENEW_ALL', 56);

/**
* Implements hook_menu().
*/
Expand Down Expand Up @@ -204,15 +209,15 @@ function ding_webtrekk_ding_entity_view($entity, $view_mode) {
ding_webtrekk_attach_event(
$button['#options']['attributes'],
'Reserver',
[50 => $entity->getId()]
[DING_WEBTREKK_PARAMETER_RESERVE => $entity->getId()]
);
}
// See online button.
elseif (isset($button['#attributes']) && in_array('button-see-online', $button['#attributes']['class'])) {
ding_webtrekk_attach_event(
$button['#attributes'],
'Se online',
[51 => $entity->getId()]
[DING_WEBTREKK_PARAMETER_SEE_ONLINE => $entity->getId()]
);
}
}
Expand Down Expand Up @@ -261,7 +266,7 @@ function ding_webtrekk_form_ding_loan_loans_form_alter(&$form, &$form_state) {
ding_webtrekk_attach_event(
$form['actions_container']['actions_top']['renew_all']['#attributes'],
'Forny alle materialer',
[56 => implode(';', $material_ids)]
[DING_WEBTREKK_PARAMETER_RENEW_ALL => implode(';', $material_ids)]
);

// The renew selected button is more complicated, since we need data about
Expand Down

0 comments on commit 9847587

Please sign in to comment.