-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaned up Integration code for listVar integration #14
Open
cooperreid-optimizely
wants to merge
1
commit into
master
Choose a base branch
from
cooper-adobe_listvar_refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 54 additions & 3 deletions
57
Integrations/Analytics/Adobe Analytics/List Variable Integration/config.json
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 |
---|---|---|
@@ -1,9 +1,60 @@ | ||
{ | ||
"plugin_type": "analytics_integration", | ||
"name": "List Var Custom Adobe Analytics", | ||
"form_schema": [], | ||
"name": "Custom Adobe Analytics [List Var]", | ||
"form_schema": [ | ||
{ | ||
"default_value": "list1", | ||
"field_type": "dropdown", | ||
"name": "list", | ||
"label": "List Var", | ||
"options": { | ||
"choices": [ | ||
{ | ||
"value": "list1", | ||
"label": "list1" | ||
}, | ||
{ | ||
"value": "list2", | ||
"label": "list2" | ||
}, | ||
{ | ||
"value": "list3", | ||
"label": "list3" | ||
}, | ||
{ | ||
"value": "list4", | ||
"label": "list4" | ||
}, | ||
{ | ||
"value": "list5", | ||
"label": "list5" | ||
}, | ||
{ | ||
"value": "list6", | ||
"label": "list6" | ||
}, | ||
{ | ||
"value": "list7", | ||
"label": "list7" | ||
}, | ||
{ | ||
"value": "list8", | ||
"label": "list8" | ||
}, | ||
{ | ||
"value": "list9", | ||
"label": "list9" | ||
}, | ||
{ | ||
"value": "list10", | ||
"label": "list10" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"description": "Track this campaign in Adobe Analytics using a list variable.", | ||
"options": { | ||
"track_layer_decision": "// This extension integrates Optimizely w/ Adobe via a pre-defined list variable. Set the list variable on line 3 below.\nvar decisionString = window.optimizely.get('state').getDecisionString({campaignId: campaignId, shouldCleanString: true});\nvar redirectInfo = window.optimizely.get('state').getRedirectInfo();\nvar list = \"list1\";\n\n// Public Methods\nvar adobeIntegrator = {\n\t// Array of objects for active campaigns/experiments\n\tcampaignArray: [],\n\t// Accepts \"s\" variable as a param and assigns campaigns/experiments to list.\n\tassignCampaigns: function(sVariable) {\n sVariable[list] = sVariable[list] || [];\n if (!!redirectInfo) sVariable.referrer = redirectInfo.referrer;\n\t\tfor (var i = this.campaignArray.length-1; i >= 0; i--) {\n sVariable[list].push(this.campaignArray[i]);\n\t\t\tthis.campaignArray.splice(i, 1);\n\t\t}\n\t},\n\t// Accepts \"s\" variable as a param and assigns eVars to object, then dispatches custom link tracking.\n\ttrackDelayedCampaigns: function(sVariable) {\n sVariable[list] = sVariable[list] || [];\n sVariable.linkTrackVars += \",list1\";\n\t\tfor (var i = this.campaignArray.length-1; i >= 0; i--) {\n\t\t\tsVariable[list].push(this.campaignArray[i]);\n\t\t\tthis.campaignArray.splice(i, 1);\n\t\t}\n sVariable.tl(true, \"o\", \"OptimizelyLayerDecision\");\n\t}\n};\n\n// Scopes `campaignArray` to Optimizely object.\nif (!window.optimizely.get(\"custom/adobeIntegrator\")) {\n\twindow.optimizely.push({\n\t\ttype: \"registerModule\",\n\t\tmoduleName: \"adobeIntegrator\",\n\t\tmodule: adobeIntegrator\n\t});\n}\n\n// Failing Audiences returns `null`, failing Traffic Allocation returns `undefined` for decisionString.\nif (!!decisionString) window.optimizely.get(\"custom/adobeIntegrator\").campaignArray.push(decisionString);" | ||
"track_layer_decision": "var decisionString = window.optimizely.get('state').getDecisionString({\n campaignId: campaignId,\n shouldCleanString: true\n});\nvar redirectInfo = window.optimizely.get('state').getRedirectInfo();\n\nvar csvToArray = function(csv) {\n return csv.length ? (csv || '').split(/,\\s*/) : [];\n}\n\n// Public Methods\nvar adobeIntegrator = {\n campaignDecisions: [],\n appendToProperty: function(sVariable, listVar, decision) {\n if (typeof sVariable[listVar] === 'undefined') sVariable[listVar] = ''; //default to string format\n \n if (sVariable[listVar].constructor === Array) { // this listVarVar was previously defined as a string\n sVariable[listVar] = sVariable[listVar].concat(decision);\n } \n else { // this listVarVar was previously defined as a string\n sVariable[listVar] = csvToArray(sVariable[listVar]);\n sVariable[listVar].push(decision);\n sVariable[listVar] = sVariable[listVar].join(',');\n }\n },\n populateTrackerClearDecisions: function(sVariable) {\n var _this = this;\n this.campaignDecisions.forEach(function(i) {\n _this.appendToProperty(sVariable, i.listVar, i.decision);\n });\n this.campaignDecisions = [];\n },\n // Accepts \"s\" variable as a param and assigns eVars to object. \n assignCampaigns: function(sVariable) {\n if (!!redirectInfo) sVariable.referrer = redirectInfo.referrer;\n this.populateTrackerClearDecisions(sVariable);\n },\n // Accepts \"s\" variable as a param and assigns eVars to object, then dispatches custom link tracking.\n trackDelayedCampaigns: function(sVariable) {\n var _this = this;\n this.campaignDecisions.forEach(function(i) {\n _this.appendToProperty(sVariable, 'linkTrackVars', i.listVar);\n }); \n this.populateTrackerClearDecisions(sVariable);\n sVariable.tl(true, \"o\", \"OptimizelyLayerDecision\");\n }\n};\n\n// Scopes `campaignArray` to Optimizely object.\nif (!window.optimizely.get(\"custom/adobeIntegrator\")) {\n window.optimizely.push({\n type: \"registerModule\",\n moduleName: \"adobeIntegrator\",\n module: adobeIntegrator\n });\n}\n\n// Failing Audiences returns `null`, failing Traffic Allocation returns `undefined` for decisionString.\nif (!!decisionString) window.optimizely.get(\"custom/adobeIntegrator\").campaignDecisions.push({\n 'listVar': extension.list,\n 'decision': decisionString\n});" | ||
} | ||
} |
77 changes: 49 additions & 28 deletions
77
Integrations/Analytics/Adobe Analytics/List Variable Integration/integration.js
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 |
---|---|---|
@@ -1,41 +1,62 @@ | ||
// This extension integrates Optimizely w/ Adobe via a pre-defined list variable. Set the list variable on line 3 below. | ||
var decisionString = window.optimizely.get('state').getDecisionString({campaignId: campaignId, shouldCleanString: true}); | ||
var decisionString = window.optimizely.get('state').getDecisionString({ | ||
campaignId: campaignId, | ||
shouldCleanString: true | ||
}); | ||
var redirectInfo = window.optimizely.get('state').getRedirectInfo(); | ||
var list = "list1"; | ||
|
||
var csvToArray = function(csv) { | ||
return csv.length ? (csv || '').split(/,\s*/) : []; | ||
} | ||
|
||
// Public Methods | ||
var adobeIntegrator = { | ||
// Array of objects for active campaigns/experiments | ||
campaignArray: [], | ||
// Accepts "s" variable as a param and assigns campaigns/experiments to list. | ||
assignCampaigns: function(sVariable) { | ||
sVariable[list] = sVariable[list] || []; | ||
campaignDecisions: [], | ||
appendToProperty: function(sVariable, listVar, decision) { | ||
if (typeof sVariable[listVar] === 'undefined') sVariable[listVar] = ''; //default to string format | ||
|
||
if (sVariable[listVar].constructor === Array) { // this listVarVar was previously defined as a string | ||
sVariable[listVar] = sVariable[listVar].concat(decision); | ||
} | ||
else { // this listVarVar was previously defined as a string | ||
sVariable[listVar] = csvToArray(sVariable[listVar]); | ||
sVariable[listVar].push(decision); | ||
sVariable[listVar] = sVariable[listVar].join(','); | ||
} | ||
}, | ||
populateTrackerClearDecisions: function(sVariable) { | ||
var _this = this; | ||
this.campaignDecisions.forEach(function(i) { | ||
_this.appendToProperty(sVariable, i.listVar, i.decision); | ||
}); | ||
this.campaignDecisions = []; | ||
}, | ||
// Accepts "s" variable as a param and assigns eVars to object. | ||
assignCampaigns: function(sVariable) { | ||
if (!!redirectInfo) sVariable.referrer = redirectInfo.referrer; | ||
for (var i = this.campaignArray.length-1; i >= 0; i--) { | ||
sVariable[list].push(this.campaignArray[i]); | ||
this.campaignArray.splice(i, 1); | ||
} | ||
}, | ||
// Accepts "s" variable as a param and assigns eVars to object, then dispatches custom link tracking. | ||
trackDelayedCampaigns: function(sVariable) { | ||
sVariable[list] = sVariable[list] || []; | ||
sVariable.linkTrackVars += ",list1"; | ||
for (var i = this.campaignArray.length-1; i >= 0; i--) { | ||
sVariable[list].push(this.campaignArray[i]); | ||
this.campaignArray.splice(i, 1); | ||
} | ||
this.populateTrackerClearDecisions(sVariable); | ||
}, | ||
// Accepts "s" variable as a param and assigns eVars to object, then dispatches custom link tracking. | ||
trackDelayedCampaigns: function(sVariable) { | ||
var _this = this; | ||
this.campaignDecisions.forEach(function(i) { | ||
_this.appendToProperty(sVariable, 'linkTrackVars', i.listVar); | ||
}); | ||
this.populateTrackerClearDecisions(sVariable); | ||
sVariable.tl(true, "o", "OptimizelyLayerDecision"); | ||
} | ||
} | ||
}; | ||
|
||
// Scopes `campaignArray` to Optimizely object. | ||
if (!window.optimizely.get("custom/adobeIntegrator")) { | ||
window.optimizely.push({ | ||
type: "registerModule", | ||
moduleName: "adobeIntegrator", | ||
module: adobeIntegrator | ||
}); | ||
window.optimizely.push({ | ||
type: "registerModule", | ||
moduleName: "adobeIntegrator", | ||
module: adobeIntegrator | ||
}); | ||
} | ||
|
||
// Failing Audiences returns `null`, failing Traffic Allocation returns `undefined` for decisionString. | ||
if (!!decisionString) window.optimizely.get("custom/adobeIntegrator").campaignArray.push(decisionString); | ||
if (!!decisionString) window.optimizely.get("custom/adobeIntegrator").campaignDecisions.push({ | ||
'listVar': extension.list, | ||
'decision': decisionString | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cooperreid-optimizely what's the rational from moving away from a hard-coded list variable key? The reason I put this in was because customers didn't want to modify the list variable used every time so the integration would genuinely be "one click". Just wanted to confirm there's a reason before I merge in.