Skip to content

Instantly share code, notes, and snippets.

@caasi
Created November 8, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caasi/daf32bfa740c14ff5335cf64fe8e8875 to your computer and use it in GitHub Desktop.
Save caasi/daf32bfa740c14ff5335cf64fe8e8875 to your computer and use it in GitHub Desktop.
Extract GTM event labels and actions from the element id
function() {
var result = {{Click ID}}.match(/sense-([^_\s]*)__([^_\s]+)/);
if (!result) return {{Click Text}};
var label = result[1];
var action = result[2].split('-');
var last = action[action.length-1];
if (last.match(/btn|input|link|type/)) {
action = action.slice(0, action.length - 1);
}
action = action.join('-');
return action;
}
function() {
var result = {{Click ID}}.match(/sense-([^_\s]*)__([^_\s]+)/);
if (!result) return {{Click Element}};
var label = result[1];
var action = result[2].split('-');
var last = action[action.length-1];
if (last.match(/btn|input|link|type/)) {
label = label + '-' + last;
}
return label;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment