Wiki source code of ONEcount Javascript Widgets

Last modified by Admin User on 2025/10/31 14:02

Hide last authors
melanie@one-count_com 1.1 1 {{layout}}
2 {{layout-section ac:type="two_right_sidebar"}}
3 {{layout-cell}}
melanie@one-count_com 7.1 4 ----
5
melanie@one-count_com 1.1 6 (updated 10/12/16)
7
8
Admin User 13.1 9 **oc.min.js**: This is the main script that's used for data collection, interacting with ONEcount.
melanie@one-count_com 1.1 10
11 The main object in this script is called **GCN**. **GCN** contains the following objects:
12
13 (% style="margin-left: 30.0px;" %)
14 **variables**: this is a container for variables that may be used by others objects in GCN
15
16 (% style="margin-left: 30.0px;" %)
17 **cookie**: utility for interacting with cookies. Contains the following functions:
18
19 * (((
20 * (((
21 **read**(**name**) : returns the value of cookie **name** or null if it doesn't exist
22 )))
23 * (((
24 **set**(**name**, **value**, **options**): create a cookie called **name** with value **value**. **options** is an object which can have **expires**, **path**, **domain** and **secure** properties
25 )))
26 * (((
Admin User 12.1 27 **remove**(**name**, **options**): removes the cookie **name**. **options** is an object which can have the property **sublevel**
melanie@one-count_com 1.1 28 )))
29 )))
30
31 (% style="margin-left: 30.0px;" %)
32 **url**: utility for interacting with url. Contains the following functions:
33
34 * (((
35 * (((
36 **parse**(**url**): parses the url and returns an object containing these properties : **href**, **withoutHash**, **url**, **origin**, **protocol**, **protocolseparator**, **credhost**, **cred**, **user**, **pass**, **host**, **hostname**, **port**, **pathname**, **segment1**, **segment2**, **search**, **hash**
37 )))
38 * (((
39 **params**(**url**): return a key value pair object of the query string parameters
40 )))
41 )))
42
43 * (((
44 * (((
45 **build**(**url**, **params**): create a new **url** based of the provided **url** and **params**
46 )))
47 )))
48
49
Admin User 12.1 50
melanie@one-count_com 1.1 51 (% style="margin-left: 30.0px;" %)
52 **script**: utility for interacting with scripts. Contains the following functions:
53
54 * (((
55 * (((
56 **add**(**url**): creates a script tag using **document.write** whose **src** is **url**
57 )))
58 * (((
59 **addInHeader**(**url**): create a script tag in the **head** whose **src** is **url**
60 )))
61 * (((
62 **addAsync**(**url**): create a script tag in the **body** whose **src** is **url**
63 )))
64 * (((
Admin User 12.1 65 **createScript**(**url**): helper function that create a script element whose src is url
melanie@one-count_com 1.1 66 )))
67 )))
68
69 (% style="margin-left: 30.0px;" %)
70 **method**: utility for dynamically invoking methods. Contains the following functions:
71
72 * (((
73 * (((
Admin User 12.1 74 **call**(**f**, **options**): calls the function **f**
melanie@one-count_com 1.1 75 )))
76 )))
77
78 (% style="margin-left: 30.0px;" %)
79 **event**: utility for interacting with event. Contains the following functions:
80
81 * (((
82 * (((
83 **on**(type, listener, f) : add a listener that executes the function **f** when event of type **type** occurs on **listener**
84 )))
85 * (((
86 **off**(**type**, **listener**, **f**): removes the listener that executes the function **f** when event of type **type** occurs
87 )))
88 )))
89
90 (% style="margin-left: 30.0px;" %)
91 **random**: utility for generating random number and string. Contains the following functions:
92
93 * (((
94 * (((
95 **number**(): return a random integer
96 )))
97 * (((
98 **string**(**count**): return a random string of length **count**
99 )))
100 )))
101
102 (% style="margin-left: 30.0px;" %)
103 **tracker**: this is used for tracking web impressions. Contains many functions used internally but the 2 functions accessible publicly are:
104
105 * (((
106 * (((
107 **init**(**_gcnt**): called on page load to initialize the tracker which which will start collecting impressions. **_gcnt** is an array that contains options used by the tracker.~/~/add list of options ?
108 )))
109 * (((
110 **track**(**url**, **title**, **referer**): used to dynamically track a page with url **url**, title **title** and referer **referer**. This can be used with **infinite scroll**.
111 )))
112 )))
113
114 (% style="margin-left: 30.0px;" %)
115 **ONEcount**: object for interacting with ONEcount application. This object contains many functions and objects.
116
117 (% style="margin-left: 60.0px;" %)
Admin User 12.1 118 a.** Functions**:
melanie@one-count_com 1.1 119
120 * (((
121 * (((
122 **init**(): initialize the widget
123 )))
124 * (((
125 **parseScript**(): parse the main script that was loaded to retrieve the **clientId**
126 )))
127 * (((
128 **getClientId**(): return the **clientId**
129 )))
130 * (((
131 **getOrigin**(): returns the script's **origin**
132 )))
133 * (((
134 **getScript**(): return the current script that is being executed
135 )))
136 * (((
137 **setUrls**(): set the different urls endpoint (**automation**, **login/logout**, **tracking**, **viewability**, **form embed**, ...) used to interact with ONEcount
138 )))
139 * (((
140 **setLinks**(): set the login/logout url as link.
141 )))
142 * (((
143 **setTargeting**() : loads the automation script used for **targeting**
144 )))
145 * (((
146 **loadAdditionalScripts**(): load additional scripts based on the **clientId**
147 )))
148 * (((
149 **isLoggedIn**(): return true if the user is logged in
150 )))
151 * (((
152 **checkPerm**(**params**): makes a **jsonp** request to the perm server to check whether the user has access to the page or not. **params** is an object that can have **url**, **referrer**, **resource** properties. If **url** and **referrer** are not provided, they will be retrieved from the window element. This is actually calling **tracker.track(url, title, referer)**. If the callback is provided, it will be called once a response is received from the server. This is being used to return the number of articles read for windowed products
153 )))
154 * (((
155 **gate**(**resource**): makes a **jsonp** request to the perm server to take the user to the registration page for resource. If the user is already subscribed then nothing will happen.
156 )))
157 )))
158
159
Admin User 12.1 160
melanie@one-count_com 1.1 161 (% style="margin-left: 60.0px;" %)
Admin User 12.1 162 b. ** Objects**
melanie@one-count_com 1.1 163
164 * (((
165 * (((
166 **urls**: this object contains all the url used to interact with ONEcount. These url already have the **clientId** appended to them.
167 )))
168 * (((
169 **links:** this object contains links to the login/logout in ONEcount. Below are the functions:
170 )))
171 )))
172
173 * (((
174 * (((
175 * (((
176 **login**() : return the link needed for login
177 )))
178 * (((
179 **logout**(): return the link need for logout
180 )))
181 * (((
182 This also contains other helper functions such as **setReturn**(**returnUrl**), **getReturnParam**(**returnUrl**), **encodeUrl**(**url**), **decodeUrl**(**url**)
183 )))
184 )))
185 )))
186
187 * (((
188 * (((
189 **modal**: used to create a modal. This is being used for the form popup and the custom targeting pop up Contains the following functions:
190
Admin User 12.1 191 *
melanie@one-count_com 1.1 192
193 **create**(**options**): create a modal. options is an object that contains the properties **html**, **styles**, **close**
194
Admin User 12.1 195 *
melanie@one-count_com 1.1 196
197 **getCloseButton**(**options**): return the close button element. **options** is an object that contains the properties **close**
198
Admin User 12.1 199 *
melanie@one-count_com 1.1 200
201 **getContent**(**options**): return a div that contains the content of the modal. **options** is an object that contains the properties **html**
202
Admin User 12.1 203 *
melanie@one-count_com 1.1 204
Admin User 12.1 205 **loadStyles**(**options**): load css styles used for the modal. **options** is an object that contains the properties **style**
melanie@one-count_com 1.1 206 )))
207 * (((
208 **functions**: this is an object contains functions used by other widgets on the page. Contains the following functions:
209
Admin User 12.1 210 *
melanie@one-count_com 1.1 211
212 **dfp_sb_ad_capture**(**e**): used to prepare data for **DFP Small Business** viewability script. e is and event containing data about the data (**creativeId**, **lineItemId**)
213
Admin User 12.1 214 *
melanie@one-count_com 1.1 215
Admin User 12.1 216 **get_user_data()**: returns the user's **ocid** and **tempid** in the format **ocid.tempid**
melanie@one-count_com 1.1 217 )))
218 * (((
219 **form**: used to create a pop up form or for form embed. Contains one function and another object:
220
Admin User 12.1 221 *
melanie@one-count_com 1.1 222
223 **embed**(**options**): this function is used to embed a form on the page
224
Admin User 12.1 225 *
melanie@one-count_com 1.1 226
227 **popup:** this object is used to display the form as a popup. Contains the following functions:
228
Admin User 12.1 229 *
melanie@one-count_com 1.1 230
231 **resize**(**id**): re sizes the form with document id **id**
232
Admin User 12.1 233 *
melanie@one-count_com 1.1 234
235 **display**(options): displays the form as a pop up
236
Admin User 12.1 237 *
melanie@one-count_com 1.1 238
239 **message**(event): used to interact with the form in the iframe via **postMessage**
240 )))
241 )))
242
243
Admin User 12.1 244
Admin User 14.1 245 On top of this **oc.min.js** also contains a library used for browser fingerprinting as well as a library used for getting flash info on the browser. The content of this files used to spread in 3 different files and now they're in one place.
melanie@one-count_com 1.1 246
247 **v.js:** This script is used to capture viewability data for **DFP Premium** and **Openx Open Source (Revive)**.
248
249 **v_sb.js:** This script is used to capture viewability data for **DFP Small Business**
250
251 **fs.js:** This is the form scrapper script. Used to scrapped content from 3^^rd^^ party forms when they are being submitted.
252
Admin 10.1 253 === GCN.onecount.track(url, title, referrer, resourceId, callback): ===
melanie@one-count_com 1.1 254
Admin 10.1 255 By default, ONEcount widgets track impressions on each page load. For sites where one article is displayed per page, this works fine. But in cases where articles are displayed on the same page, i.e. infinite scroll, only the first one is tracked.
256
257 This function is designed to provide an impression track for each article on a page. The function expects three parameters:
258
259 * **url**: The url of the article that is supposed to be tracked. **This is required**.
260 * **title**: This should be the same as the **title tag** if the article was displayed alone on the page.
261 * **referrer**: The referrer of article. (For infinite scroll this can be the previous article in the scroll.)
262 * (((
263 **resourceId**: this is optional. If set to a valid resourceId, that resource that will be used in order to perform gating or increase view_count. You can pass 0 in order to use the default resource associated with the url if any
264 )))
265 * (((
266 **callback**: function to be called after a request has been sent to ONEcount. This can return the number of articles read by the user for products with limit in timeframe
267 )))
268
269 While the impressions are being tracked, ONEcount will also check whether the user's subscription is still valid or not (e.g. limit of X articles per month has been reached). If the subscription is not valid, then the user will be taken to the subscription page.
270
271 Let's assume I have a page where the first article is displayed when the page loads and three mores articles are displayed as the user scrolls down. The first article will be tracked by ONEcount, but for the three other articles, a call to GCN.onecount.track needs to be made to tell ONEcount that the articles have been displayed. The url should be the direct url of the article. The referrer should be the previous article's url.
272
273 === GCN.onecount.gate(resourceId, callback): ===
274
275 Gating is currently done based on a REGEX match of a url segment on page load. This function is designed to allow customers to gate content where gating can not be sufficiently managed using URL segments, or where content must be gated without a page load.
276
277 This function expects **two parameter** :
278
279 1. **resourceId** : this is the **resourceId** that will be used for gating and it's **required.**
280 1. **callback:** this is a function that can be passed. The response from the gating request will be made available in the callback. The callback should expect one parameter which is a JSON object. The JSON object has a property called hasAccess which is a boolean (true/false). **true** means the user has access and **false** means he does not.
281
282 Resource Ids are available in ONEcount on the resource listing page.
283
284 To create a resource that uses this function, choose “Function” from the resource type pull-down, then enter a text return value in the box below. This return value is ignored for now, but may be used to trigger gating in the future.
285
286 When the function is called and the user is not subscribed to the product that the resource belongs to, he will be taken to the registration page in order to do so. If he is already subscribed to the product then nothing will happen.
287
288
289
Admin User 12.1 290 **__NOTE:__**  If page load speed is ever a concern, it is recommended to use a third party service (such as tools.pingdom.com). By doing so, it will generate report of all items loading on your webpage along with their load times. Simply copy and paste your page's URL into the designated field and a test will be conducted immediately. If any** oc.net** item exceeds a load speed of 500ms, please enter a Helpdesk ticket for us to review. Testing page load speeds is a very informative way of identifying items that are directly impacting page performance. It is worth mentioning that there will be items that continuously load in short spurts (ex. **v.js** for viewability data) however those short spurts do not negatively impact load speed performance.
melanie@one-count_com 1.1 291
292
Admin User 12.1 293
melanie@one-count_com 1.1 294 {{/layout-cell}}
295 {{/layout-section}}
296 {{/layout}}