-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
221bcb5
commit 18abf2d
Showing
24 changed files
with
638 additions
and
452 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import dataLayer from './ext/data-layer/data-layer'; | ||
|
||
const MAP_DL_PA = [ | ||
['createdAt', 'content_publication_date'], | ||
['tags', 'tags_array'] | ||
]; | ||
|
||
function processContentProperties(model) { | ||
const content = dataLayer.get('content'); | ||
for (const propContent in content) { | ||
if (Object.prototype.hasOwnProperty.call(content, propContent)) { | ||
// searching for a DL property name and replacing it with its PA name | ||
const datalayerPropFoundResult = MAP_DL_PA.find((items) => items[0] === propContent); | ||
const propFinalName = datalayerPropFoundResult ? datalayerPropFoundResult[1] : _camelToSnake(`content_${propContent}`); | ||
model.addEventsProperty(propFinalName, content[propContent]); | ||
} | ||
} | ||
} | ||
|
||
function initContentProperties(pa) { | ||
pa.setContentProperty = function (name, value) { | ||
// searching for a PA property name and replacing it with its DL name | ||
const pianoAnalyticsPropFound = MAP_DL_PA.find((items) => items[1] === name); | ||
dataLayer.set('content', { | ||
[pianoAnalyticsPropFound ? pianoAnalyticsPropFound[0] : name]: value | ||
}); | ||
}; | ||
pa.setContentProperties = function (content) { | ||
for (const prop in content) { | ||
if (Object.prototype.hasOwnProperty.call(content, prop)) { | ||
pa.setContentProperty(prop, content[prop]); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
function _camelToSnake(string) { | ||
return string.replace(/[\w]([A-Z])/g, function (m) { | ||
return m[0] + '_' + m[1]; | ||
}).toLowerCase(); | ||
} | ||
|
||
export { | ||
processContentProperties, | ||
initContentProperties | ||
}; |
This file contains 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
Oops, something went wrong.