Best way to log every time page is viewed

  • 1
  • Question
  • Updated 4 months ago
  • Answered
I'd like to start measuring User adoption of pages. I'd like to see how often users are using the pages we've created.

The best way I can think to do this is create a model that pulls in the page as a record and then run a snippet on page load to create a record that is a child object of the Skuid__Page__c object. This would log the date/time and user every time the page is viewed. 

I was also wondering if there is a way to use Google Analytics with the Skuid pages that someone has implemented before to do something similar?

Any help is much appreciated. 

Thank you!
Photo of Sam Becker

Sam Becker

  • 1,158 Points 1k badge 2x thumb

Posted 4 months ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
You could probably just create a custom object with one custom text field named “Page”.
On page load, have it create a new record on that model and populate the custom text field with whatever you want to call the page such as “Contacts Detail Page”. Then have the action sequence isave the record.
The record will automatically have a created by assigned to the current user on page load and the create date will be the time the page was loaded.
Photo of Matt Davis

Matt Davis, Employee

  • 654 Points 500 badge 2x thumb
Hey Sam, here's something we've done for tracking page adoption within Skuid on Salesforce - 

  1. Create a custom Object (in my example it's Skuid_Tracking__c) w/ a custom picklist field (my example its Page Origin) to track the page origin they are coming from. You could use text if you want, but we went with a picklist since we change page names sometimes. You could use text if you want, but we went with a picklist since we change page names sometimes. 
  2. In each page you want to track, have a model using that Object with the following attributes.
    --- query on page load = false
    --- create row if model has none = true
    --- condition: OwnerId = Data Source user attribute || User ID
    --- condition: Page Origin = "Whateverpicklistvalue"
    --- action when new row created: save the model
What it does is on page load, create a new row in the model. That row will default to storing your user's info as the owner, the page origin as Whaetverpicklistvalue, and you'll have the created date as a time stamp. Immediately after the row is created, that action saves the model so the row is saved. 

It's nice because you can just copy & paste the model between pages and only have to worry about changing the model name & the Page Origin condition value. Here's an example of the model we used in one case - 
<model id="usage_tracking" query="false" createrowifnonefound="true" datasource="salesforce" processonclient="true" sobject="Skuid_Tracking__c">
    <fields>
        <field id="Name" autonumber="true" accessible="true" createable="false" editable="false" filterable="true" namefield="true" sortable="true" length="80" displaytype="STRING" label="Skuid POC Tracking Name"/>
        <field id="OwnerId" accessible="true" createable="true" editable="true" filterable="true" groupable="true" namepointing="true" sortable="true" displaytype="REFERENCE" label="Owner ID" rel="Owner" relationshipname="Owner" ref="Group,User" refprefix="00G,005" overridemetadata="false" ogdisplaytype="REFERENCE" datasource="SkuidLocal" defaultvaluetype="fieldvalue" defaultValue="{{$Model.adoption1.condition.0.value}}" mergefield="Id" enclosevalueinquotes="true"/>
        <field id="Owner.Type" accessible="true" createable="false" editable="false" filterable="true" groupable="true" sortable="true" length="40" displaytype="PICKLIST" label="Type"/>
        <field id="Page_Origin__c" accessible="true" createable="true" editable="true" filterable="true" groupable="true" required="true" sortable="true" length="255" displaytype="PICKLIST" label="Page Origin"/>
        <field id="CreatedById" accessible="true" createable="true" editable="false" filterable="true" groupable="true" namepointing="false" sortable="true" displaytype="REFERENCE" label="Created By ID" rel="CreatedBy" relationshipname="CreatedBy" ref="User" refprefix="005"/>
        <field id="CreatedBy.Name" accessible="true" createable="false" editable="false" filterable="true" groupable="true" namefield="true" sortable="true" length="121" displaytype="STRING" label="Full Name"/>
        <field id="CreatedDate" accessible="true" createable="true" editable="false" filterable="true" sortable="true" displaytype="DATETIME" label="Created Date"/>
    </fields>
    <conditions>
        <condition type="datasourceuserinfo" value="" field="OwnerId" fieldtargetobjects="Group,User" operator="=" userinfotype="userid" enclosevalueinquotes="true"/>
        <condition type="fieldvalue" value="Adoption Metrics" enclosevalueinquotes="true" field="Page_Origin__c"/>
    </conditions>
    <actions>
        <action>
            <actions>
                <action type="save">
                    <models>
                        <model>usage_tracking</model>
                    </models>
                </action>
            </actions>
            <events>
                <event>row.created</event>
            </events>
        </action>
    </actions>
</model>
Photo of Chandra V

Chandra V, Champion

  • 6,966 Points 5k badge 2x thumb
We use Google Analytics.  On each tracked Skuid page we have a snippet with the below code.  We changed our code from an Inline snippet (that runs on page load) to a regular snippet that we call using the Actions after the page renders.  We found the inline snippet slowed the page loads down.

Replace the placeholders with your SF org id (this makes the snippet only run in produciton, and you won't pick up your sandboxes) and your google tag id: UA-XXXXXX.


var params = arguments[0],
$ = skuid.$;

//SCRIPT ONLY RUNS IN PRODUCTION ORG, NOT SANDBOXES

if (skuid.utils.userInfo.organizationId === 'YOURSALESFORCEORGID') {
    var googletagmanager = document.createElement('script');
    googletagmanager.async = true;
    googletagmanager.src = 'https://www.googletagmanager.com/gtag/js?id=YOURTAGID';

    var googletagmanager2 = document.createElement('script');
    var scriptText = "window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments)}; gtag('js', new Date()); gtag('config', 'YOURTAGID');";
    googletagmanager2.text = scriptText;

    var s =(document.body||document.getElementsByTagName('script')[0]);
    s.appendChild(googletagmanager);
    s.appendChild(googletagmanager2);
}
Photo of Sam Becker

Sam Becker

  • 1,158 Points 1k badge 2x thumb
Awesome. Thanks to both of you for your in-depth replies!