This plug-in is provided by Adobe Consulting as a courtesy to help you get more value out of Adobe Analytics. Adobe Customer Care does not provide support with this plug-in, including installation or troubleshooting. If you require help with this plug-in, contact your organization’s Account Manager. They can arrange a meeting with a consultant for assistance.
The addProductEvent
plug-in adds a numeric or currency event to the products
variable. Adobe recommends using this plug-in if you want to add a numeric or currency event to the products
variable without worrying about the product string format. This plug-in is not necessary if you don’t use numeric or currency events in the products
variable.
Adobe offers an extension that allows you to use most commonly-used plug-ins.
If you do not want to use the plug-in extension, you can use the custom code editor.
Copy and paste the following code anywhere in the AppMeasurement file after the Analytics tracking object is instantiated (using s_gi
). Preserving comments and version numbers of the code in your implementation helps Adobe with troubleshooting any potential issues.
/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: addProductEvent v1.0 (Requires apl v3.1 and inList v2.0+ plug-ins) */
s.addProductEvent=function(en,ev,ap){var s=this;if("string"===typeof en)if(ev=isNaN(ev)?"1":String(ev),ap=ap||!1,s.events= s.apl(s.events,en),s.products){var e=s.products.split(",");ap=ap?0:e.length-1;for(var a;ap<e.length;ap++)a=e[ap].split(";") ,a[4]&&a[4].includes("event")?a[4]=a[4]+"|"+en+"="+ev:a[5]?a[4]=en+"="+ev:a[4]||(a[3]||(a[3]=""),a[2]||(a[2]=""),a[1]||(a[1]=""),a[4]=en+"="+ev),e[ap]=a.join(";");s.products=e.join(",")}else s.products=";;;;"+en+"="+ev};
/* Adobe Consulting Plugin: apl (appendToList) v3.2 (Requires inList v2.0 or higher) */
s.apl=function(lv,vta,d1,d2,cc){if(!lv||"string"===typeof lv){if("undefined"===typeof this.inList||"string"!==typeof vta||""===vta)return lv;d1=d1||",";d2=d2||d1;1==d2&&(d2=d1,cc||(cc=1));2==d2&&1!=cc&&(d2=d1);vta=vta.split(",");for(var g=vta.length,e=0;e<g;e++)this.inList(lv,vta[e],d1,cc)||(lv=lv?lv+d2+vta[e]:vta[e])}return lv};
/* Adobe Consulting Plugin: inList v2.1 */
s.inList=function(lv,vtc,d,cc){if("string"!==typeof vtc)return!1;if("string"===typeof lv)lv=lv.split(d||",");else if("object"!== typeof lv)return!1;d=0;for(var e=lv.length;d<e;d++)if(1==cc&&vtc===lv[d]||vtc.toLowerCase()===lv[d].toLowerCase())return!0;return!1};
/******************************************** END CODE TO DEPLOY ********************************************/
The addProductEvent
method uses the following arguments:
en
(required, string): The event to add to the last entry in the products
variable. If the products
variable is empty, then a “blank” product entry is created with the event (and its value) attached.ev
(required, string): The value assigned to the numeric or currency event in the en
argument. Defaults to 1
when not set.ap
(optional, boolean): If the products variable currently contains more than one product entry, a value of true
(or 1
) adds the event to all product entries. Defaults to false
when not set.The addProductEvent
returns nothing. Instead, it adds the event and its value to the products
variable. The plug-in also automatically adds the event to the events
variable, since it is also required there.
The addProductEvent plug-in does not create or use any cookies
The following code sets the s.products
variable to ";product1;3;300,;product2;2;122,;product3;1;25;event35=25"
.
s.products=";product1;3;300,;product2;2;122,;product3;1;25"
s.events="purchase";
s.addProductEvent("event35", "25");
The above code also sets the s.events
variable to "purchase,event35"
The following code sets the s.products
variable to ";product1;3;300;event35=25,;product2;2;122;event35=25,;product3;1;25;event35=25"
s.products=";product1;3;300,;product2;2;122,;product3;1;25";
s.addProductEvent("event35", 25, 1);
When the third argument in the addProductEvent
call is true
(or 1
), each product entry has the event specified in the call added to its value.
The following code sets the s.products
variable to ";product1;3;300;event2=10;eVar33=large|eVar34=men|eVar35=blue,;product2;2;122,;product3;1;25;event33= 12|event34=10|event35=15"
s.products=";product1;3;300;event2=10;eVar33=large|eVar34=men|eVar35=blue,;product2;2;122,;product3;1;25";
s.events="purchase,event2";
s.addProductEvent("event33", "12");
s.addProductEvent("event34", "10");
s.addProductEvent("event35", "15");
The above code also sets the s.events
variable to "purchase,event2,event33,event34,event35"
The following code sets the s.products
variable to ";product1;3;300;event2=10|event33=12|event34=10|event35=15;eVar33=large|eVar34=men|eVar35=blue, ;product2;2;122;event33=12|event34=10|event35=15,;product3;1;25;event33=12|event34=10|event35=15"
s.products=";product1;3;300;event2=10;eVar33=large|eVar34=men|eVar35=blue,;product2;2;122,;product3;1;25"
s.events="purchase,event2"
s.addProductEvent("event33", "12", 1);
s.addProductEvent("event34", 10, 1);
s.addProductEvent("event35", "15", 1);
The above code also sets the s.events
variable to "purchase,event2,event33,event34,event35"
.
The second argument in the call can be either an integer or a string representing an integer/number
If s.products
isn’t already set, the following code sets it to ";;;;event35=25"
s.addProductEvent("event35", "25");
The above code also appends "event35"
to the end of s.events
or, if s.events
isn’t already set, the above code sets s.events
to "event35"