Created
November 8, 2018 17:25
-
-
Save caasi/daf32bfa740c14ff5335cf64fe8e8875 to your computer and use it in GitHub Desktop.
Extract GTM event labels and actions from the element id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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